新增匹配次数管理功能,优化用户匹配体验。通过服务端计算用户的匹配配额,更新用户状态以反映剩余匹配次数。同时,调整匹配页面逻辑,确保在匹配次数用尽时提示用户购买更多次数。更新相关API以支持匹配记录的存储与查询,提升系统稳定性。

This commit is contained in:
乘风
2026-02-11 16:53:17 +08:00
parent ecee1bb2bb
commit a1dcf599ee
18 changed files with 422 additions and 229 deletions

View File

@@ -219,6 +219,8 @@ func miniprogramPayPost(c *gin.Context) {
if description == "" {
if req.ProductType == "fullbook" {
description = "《一场Soul的创业实验》全书"
} else if req.ProductType == "match" {
description = "购买匹配次数"
} else {
description = fmt.Sprintf("章节购买-%s", req.ProductID)
}
@@ -311,7 +313,7 @@ func miniprogramPayPost(c *gin.Context) {
})
}
// GET - 查询订单状态
// GET - 查询订单状态(并主动同步:若微信已支付但本地未标记,则更新本地订单,便于配额即时生效)
func miniprogramPayGet(c *gin.Context) {
orderSn := c.Query("orderSn")
if orderSn == "" {
@@ -336,6 +338,18 @@ func miniprogramPayGet(c *gin.Context) {
switch tradeState {
case "SUCCESS":
status = "paid"
// 若微信已支付,主动同步到本地 orders不等 PayNotify便于购买次数即时生效
db := database.DB()
var order model.Order
if err := db.Where("order_sn = ?", orderSn).First(&order).Error; err == nil && order.Status != nil && *order.Status != "paid" {
now := time.Now()
db.Model(&order).Updates(map[string]interface{}{
"status": "paid",
"transaction_id": transactionID,
"pay_time": now,
})
fmt.Printf("[PayGet] 主动同步订单已支付: %s\n", orderSn)
}
case "CLOSED", "REVOKED", "PAYERROR":
status = "failed"
case "REFUND":
@@ -429,6 +443,8 @@ func MiniprogramPayNotify(c *gin.Context) {
if attach.ProductType == "fullbook" {
db.Model(&model.User{}).Where("id = ?", buyerUserID).Update("has_full_book", true)
fmt.Printf("[PayNotify] 用户已购全书: %s\n", buyerUserID)
} else if attach.ProductType == "match" {
fmt.Printf("[PayNotify] 用户购买匹配次数: %s订单 %s\n", buyerUserID, orderSn)
} else if attach.ProductType == "section" && attach.ProductID != "" {
var count int64
db.Model(&model.Order{}).Where(