chore: 新增 .gitignore 排除开发文档,同步代码与构建产物

Made-with: Cursor
This commit is contained in:
卡若
2026-03-16 09:21:39 +08:00
parent fa9903d235
commit 85ce2422d1
40 changed files with 2315 additions and 947 deletions

View File

@@ -36,7 +36,7 @@ func BookAllChapters(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": true, "data": []interface{}{}})
return
}
freeIDs := getFreeChapterIDs(db)
freeIDs := getEffectiveFreeChapterIDs(db)
for i := range list {
if freeIDs[list[i].ID] {
t := true
@@ -112,6 +112,24 @@ func getFreeChapterIDs(db *gorm.DB) map[string]bool {
return ids
}
func getEffectiveFreeChapterIDs(db *gorm.DB) map[string]bool {
ids := getFreeChapterIDs(db)
var rows []struct {
ID string `gorm:"column:id"`
}
if err := db.Model(&model.Chapter{}).
Select("id").
Where("is_free = ? OR price = 0", true).
Find(&rows).Error; err == nil {
for _, row := range rows {
if row.ID != "" {
ids[row.ID] = true
}
}
}
return ids
}
// checkUserChapterAccess 判断 userId 是否有权读取 chapterIDVIP / 全书购买 / 单章购买)
// isPremium=true 表示增值版fullbook 买断不含增值版
func checkUserChapterAccess(db *gorm.DB, userID, chapterID string, isPremium bool) bool {
@@ -587,8 +605,7 @@ func BookStats(c *gin.Context) {
db := database.DB()
var total int64
db.Model(&model.Chapter{}).Count(&total)
var freeCount int64
db.Model(&model.Chapter{}).Where("is_free = ?", true).Count(&freeCount)
freeCount := len(getEffectiveFreeChapterIDs(db))
var totalWords struct{ S int64 }
db.Model(&model.Chapter{}).Select("COALESCE(SUM(word_count),0) as s").Scan(&totalWords)
var userCount int64