feat: 支持章节通过 mid 进行访问,优化阅读跳转逻辑。新增章节数据结构,包含章节的 mid 信息,提升用户体验。更新 API 以支持通过 mid 查询章节内容,确保兼容性与灵活性。
This commit is contained in:
@@ -268,12 +268,21 @@ func UserPurchaseStatus(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"success": false, "error": "用户不存在"})
|
||||
return
|
||||
}
|
||||
var orderRows []struct{ ProductID string }
|
||||
db.Raw("SELECT DISTINCT product_id FROM orders WHERE user_id = ? AND status = ? AND product_type = ?", userId, "paid", "section").Scan(&orderRows)
|
||||
var orderRows []struct {
|
||||
ProductID string
|
||||
MID int
|
||||
}
|
||||
db.Raw(`SELECT DISTINCT o.product_id, c.mid FROM orders o
|
||||
LEFT JOIN chapters c ON c.id = o.product_id
|
||||
WHERE o.user_id = ? AND o.status = ? AND o.product_type = ?`, userId, "paid", "section").Scan(&orderRows)
|
||||
purchasedSections := make([]string, 0, len(orderRows))
|
||||
sectionMidMap := make(map[string]int)
|
||||
for _, r := range orderRows {
|
||||
if r.ProductID != "" {
|
||||
purchasedSections = append(purchasedSections, r.ProductID)
|
||||
if r.MID > 0 {
|
||||
sectionMidMap[r.ProductID] = r.MID
|
||||
}
|
||||
}
|
||||
}
|
||||
// 匹配次数配额:纯计算(订单 + match_records)
|
||||
@@ -290,6 +299,7 @@ func UserPurchaseStatus(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"success": true, "data": gin.H{
|
||||
"hasFullBook": user.HasFullBook != nil && *user.HasFullBook,
|
||||
"purchasedSections": purchasedSections,
|
||||
"sectionMidMap": sectionMidMap,
|
||||
"purchasedCount": len(purchasedSections),
|
||||
"matchCount": matchQuota.PurchasedTotal,
|
||||
"matchQuota": gin.H{
|
||||
|
||||
Reference in New Issue
Block a user