package handler import ( "log" "net/http" "time" "github.com/gin-gonic/gin" "wx_service/internal/achievement" "wx_service/internal/middleware" "wx_service/internal/model" ) func (h *SmokeHandler) ListAchievementThemes(c *gin.Context) { themes, err := h.achievementService.ListActiveThemes(c.Request.Context()) if err != nil { c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "获取成就主题失败")) return } c.JSON(http.StatusOK, model.Success(gin.H{"themes": themes})) } func (h *SmokeHandler) GetAchievement(c *gin.Context) { user := middleware.MustCurrentUser(c) ctx := c.Request.Context() uid := int(user.ID) now := time.Now() profile, err := h.smokeProfileService.Get(ctx, uid) if err != nil { c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "获取用户信息失败")) return } if profile == nil || profile.AchievementThemeID == nil { c.JSON(http.StatusOK, model.Success(gin.H{"achievement": nil})) return } var days int if profile.Mode == "quit" { homeData, err := h.quitCheckinService.Home(ctx, uid, now) if err != nil { log.Printf("achievement: quitcheckin home err uid=%d: %v", uid, err) days = 0 } else { days = homeData.Summary.CurrentStreakDays } } else { streakDays, err := h.smokeLogService.GetStreakDays(ctx, uid, now) if err != nil { log.Printf("achievement: smoke streak err uid=%d: %v", uid, err) days = 0 } days = streakDays } ach, err := h.achievementService.GetUserAchievement(ctx, *profile.AchievementThemeID, days) if err != nil { if err == achievement.ErrThemeNotFound { c.JSON(http.StatusOK, model.Success(gin.H{"achievement": nil})) return } c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "获取成就信息失败")) return } c.JSON(http.StatusOK, model.Success(gin.H{"achievement": ach})) }