From cf4792cdc874c392bf12ca3800ef9bf878cc4a4b Mon Sep 17 00:00:00 2001 From: Chang lue Tsen Date: Sat, 13 Sep 2025 14:02:49 -0400 Subject: [PATCH] fix(quota): update time handling in quota logic and correct subscriber ID query --- internal/logic/admin/marketing/createQuotaTaskLogic.go | 5 +++-- .../logic/admin/marketing/queryQuotaTaskPreCountLogic.go | 4 ++-- queue/logic/task/quotaLogic.go | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/logic/admin/marketing/createQuotaTaskLogic.go b/internal/logic/admin/marketing/createQuotaTaskLogic.go index 8eb29d5..b08abbd 100644 --- a/internal/logic/admin/marketing/createQuotaTaskLogic.go +++ b/internal/logic/admin/marketing/createQuotaTaskLogic.go @@ -42,12 +42,12 @@ func (l *CreateQuotaTaskLogic) CreateQuotaTask(req *types.CreateQuotaTaskRequest query = query.Where("`status` IN ?", []int64{0, 1, 2}) // 0: Pending 1: Active 2: Finished } if req.StartTime != 0 { - start := time.UnixMilli(req.StartTime) + start := time.Unix(req.StartTime, 0) query = query.Where("`start_time` >= ?", start) } if req.EndTime != 0 { end := time.UnixMilli(req.EndTime) - query = query.Where("`start_time` <= ?", end) + query = query.Where("`expire_time` <= ?", end) } if err := query.Find(&subs).Error; err != nil { @@ -67,6 +67,7 @@ func (l *CreateQuotaTaskLogic) CreateQuotaTask(req *types.CreateQuotaTaskRequest IsActive: req.IsActive, StartTime: req.StartTime, EndTime: req.EndTime, + Objects: subIds, } scopeBytes, _ := scopeInfo.Marshal() contentInfo := task.QuotaContent{ diff --git a/internal/logic/admin/marketing/queryQuotaTaskPreCountLogic.go b/internal/logic/admin/marketing/queryQuotaTaskPreCountLogic.go index d004619..2b77ada 100644 --- a/internal/logic/admin/marketing/queryQuotaTaskPreCountLogic.go +++ b/internal/logic/admin/marketing/queryQuotaTaskPreCountLogic.go @@ -37,12 +37,12 @@ func (l *QueryQuotaTaskPreCountLogic) QueryQuotaTaskPreCount(req *types.QueryQuo tx = tx.Where("`status` IN ?", []int64{0, 1, 2}) // 0: Pending 1: Active 2: Finished } if req.StartTime != 0 { - start := time.UnixMilli(req.StartTime) + start := time.Unix(req.StartTime, 0) tx = tx.Where("`start_time` >= ?", start) } if req.EndTime != 0 { end := time.UnixMilli(req.EndTime) - tx = tx.Where("`start_time` <= ?", end) + tx = tx.Where("`expire_time` <= ?", end) } if err = tx.Count(&count).Error; err != nil { l.Errorf("[QueryQuotaTaskPreCount] count error: %v", err.Error()) diff --git a/queue/logic/task/quotaLogic.go b/queue/logic/task/quotaLogic.go index becdbeb..4fd9632 100644 --- a/queue/logic/task/quotaLogic.go +++ b/queue/logic/task/quotaLogic.go @@ -68,7 +68,7 @@ func (l *QuotaTaskLogic) ProcessTask(ctx context.Context, t *asynq.Task) error { return err } - subscribes, err := l.getSubscribes(ctx, scope.Subscribers) + subscribes, err := l.getSubscribes(ctx, scope.Objects) if err != nil { return err } @@ -156,7 +156,7 @@ func (l *QuotaTaskLogic) parseTaskData(ctx context.Context, taskInfo *task.Task) func (l *QuotaTaskLogic) getSubscribes(ctx context.Context, subscriberIDs []int64) ([]*user.Subscribe, error) { var subscribes []*user.Subscribe - if err := l.svcCtx.DB.WithContext(ctx).Model(&user.Subscribe{}).Where("subscribe_id IN ?", subscriberIDs).Find(&subscribes).Error; err != nil { + if err := l.svcCtx.DB.WithContext(ctx).Model(&user.Subscribe{}).Where("id IN ?", subscriberIDs).Find(&subscribes).Error; err != nil { logger.WithContext(ctx).Error("[QuotaTaskLogic.getSubscribes] find subscribes error", logger.Field("error", err.Error()), logger.Field("subscribers", subscriberIDs),