修复戒烟首页与统计中抽烟/忍住口径混淆

This commit is contained in:
root
2026-03-04 00:59:12 +08:00
parent 4509ebea60
commit bdd34785ef
6 changed files with 13 additions and 8 deletions
+4
View File
@@ -78,6 +78,10 @@ func (h *SmokeHandler) Create(c *gin.Context) {
}
num = *req.Num
}
if num == 0 {
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "num=0 请使用 /api/v1/smoke/logs/resisted"))
return
}
if level < 0 || num < 0 {
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "level/num 不能为负数"))
@@ -494,7 +494,7 @@ func (s *SmokeAINextSmokeService) loadRecent3Days(ctx context.Context, uid int,
}
snap := ensure(day)
isResisted := l.Num == 0
isResisted := l.Level == 0 && l.Num == 0
if isResisted {
snap.ResistedCount++
} else if l.Num > 0 {
+2 -2
View File
@@ -163,7 +163,7 @@ func (s *SmokeLogService) List(ctx context.Context, uid int, req ListSmokeLogsRe
case "smoke":
tx = tx.Where("num > 0")
case "resisted":
tx = tx.Where("num = 0")
tx = tx.Where("level = 0 AND num = 0")
}
var total int64
@@ -287,7 +287,7 @@ func (s *SmokeLogService) HomeSummary(ctx context.Context, uid int, asOf time.Ti
if err := s.db.WithContext(ctx).
Model(&smokemodel.SmokeLog{}).
Where("uid = ? AND (deletetime IS NULL OR deletetime = 0)", uid).
Where("num = 0 AND smoke_time = ?", todayKey).
Where("level = 0 AND num = 0 AND smoke_time = ?", todayKey).
Count(&resistedCount).Error; err != nil {
return SmokeHomeSummary{}, fmt.Errorf("count resisted logs: %w", err)
}
+1 -1
View File
@@ -170,7 +170,7 @@ func (s *SmokeNextService) countResistedLastDays(ctx context.Context, uid int, d
if err := s.db.WithContext(ctx).
Model(&smokemodel.SmokeLog{}).
Where("uid = ? AND (deletetime IS NULL OR deletetime = 0)", uid).
Where("num = 0").
Where("level = 0 AND num = 0").
Where("smoke_time BETWEEN ? AND ?", start.Format("2006-01-02"), end.Format("2006-01-02")).
Count(&count).Error; err != nil {
return 0, fmt.Errorf("count resisted logs: %w", err)
@@ -244,7 +244,7 @@ func (s *SmokeLogService) countResisted(ctx context.Context, uid int, start, end
if err := s.db.WithContext(ctx).
Model(&smokemodel.SmokeLog{}).
Where("uid = ? AND (deletetime IS NULL OR deletetime = 0)", uid).
Where("num = 0").
Where("level = 0 AND num = 0").
Where("smoke_time BETWEEN ? AND ?", start.Format("2006-01-02"), end.Format("2006-01-02")).
Count(&count).Error; err != nil {
return 0, fmt.Errorf("count resisted: %w", err)