diff --git a/app/main/api/internal/logic/admin_promotion/getpromotionstatstotallogic.go b/app/main/api/internal/logic/admin_promotion/getpromotionstatstotallogic.go index 979715d..269f475 100644 --- a/app/main/api/internal/logic/admin_promotion/getpromotionstatstotallogic.go +++ b/app/main/api/internal/logic/admin_promotion/getpromotionstatstotallogic.go @@ -100,7 +100,8 @@ func (l *GetPromotionStatsTotalLogic) GetPromotionStatsTotal(req *types.GetPromo } // 获取今日统计数据 - today := time.Now().Truncate(24 * time.Hour) + now := time.Now() + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) var todayClickCount, todayPayCount int64 var todayPayAmount float64 diff --git a/app/main/api/internal/service/adminPromotionLinkStatsService.go b/app/main/api/internal/service/adminPromotionLinkStatsService.go index 9949d36..8285f7d 100644 --- a/app/main/api/internal/service/adminPromotionLinkStatsService.go +++ b/app/main/api/internal/service/adminPromotionLinkStatsService.go @@ -35,7 +35,7 @@ func NewAdminPromotionLinkStatsService(svcCtx *ServiceContext) *AdminPromotionLi func (s *AdminPromotionLinkStatsService) ensureTotalStats(ctx context.Context, session sqlx.Session, linkId int64) (*model.AdminPromotionLinkStatsTotal, error) { totalStats, err := s.svcCtx.AdminPromotionLinkStatsTotalModel.FindOneByLinkId(ctx, linkId) if err != nil { - if err == model.ErrNotFound { + if errors.Is(err, model.ErrNotFound) { // 如果记录不存在,创建新记录 totalStats = &model.AdminPromotionLinkStatsTotal{ LinkId: linkId, @@ -63,7 +63,7 @@ func (s *AdminPromotionLinkStatsService) ensureTotalStats(ctx context.Context, s func (s *AdminPromotionLinkStatsService) ensureHistoryStats(ctx context.Context, session sqlx.Session, linkId int64, today time.Time) (*model.AdminPromotionLinkStatsHistory, error) { historyStats, err := s.svcCtx.AdminPromotionLinkStatsHistoryModel.FindOneByLinkIdStatsDate(ctx, linkId, today) if err != nil { - if err == model.ErrNotFound { + if errors.Is(err, model.ErrNotFound) { // 如果记录不存在,创建新记录 historyStats = &model.AdminPromotionLinkStatsHistory{ LinkId: linkId, @@ -106,7 +106,8 @@ func (s *AdminPromotionLinkStatsService) UpdateLinkStats(ctx context.Context, li } // 确保历史统计记录存在 - today := time.Now().Truncate(24 * time.Hour) + now := time.Now() + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) historyStats, err := s.ensureHistoryStats(ctx, session, linkId, today) if err != nil { return err @@ -143,7 +144,8 @@ func (s *AdminPromotionLinkStatsService) UpdatePaymentStats(ctx context.Context, } // 确保历史统计记录存在 - today := time.Now().Truncate(24 * time.Hour) + now := time.Now() + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) historyStats, err := s.ensureHistoryStats(ctx, session, linkId, today) if err != nil { return err @@ -188,7 +190,8 @@ func (s *AdminPromotionLinkStatsService) CreateLinkStats(ctx context.Context, li } // 创建今日历史统计记录 - today := time.Now().Truncate(24 * time.Hour) + now := time.Now() + today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) historyStats := &model.AdminPromotionLinkStatsHistory{ LinkId: linkId, StatsDate: today,