feat(quitcheckin): persist hp and log hp changes

This commit is contained in:
nepiedg
2026-04-16 11:33:41 +08:00
parent 6e0a06cfcf
commit a32ec911a1
7 changed files with 582 additions and 42 deletions
+17
View File
@@ -3,6 +3,7 @@ package handler
import (
"errors"
"io"
"log"
"net/http"
"strconv"
"strings"
@@ -134,6 +135,22 @@ func (h *SmokeHandler) Create(c *gin.Context) {
return
}
// quit 模式下:把“抽烟记录”视作一次 slip/复吸,同步到 quitcheckin(扣 HP + 标记当日 relapsed)。
// 这一步失败不影响主流程(记录仍应成功写入 smoke_log)。
if record != nil && record.Num > 0 {
if profile, e := h.smokeProfileService.Get(c.Request.Context(), int(user.ID)); e == nil && profile != nil {
if strings.TrimSpace(strings.ToLower(profile.Mode)) == "quit" {
slipAt := time.Now().In(time.Local)
if record.SmokeAt != nil {
slipAt = record.SmokeAt.In(time.Local)
}
if e := h.quitCheckinService.RecordSmokeSlip(c.Request.Context(), int(user.ID), slipAt, record.Num, record.Remark); e != nil {
log.Printf("[smoke_create] sync quitcheckin slip degraded uid=%d err=%v", user.ID, e)
}
}
}
}
c.JSON(http.StatusOK, model.Success(record))
}