fix: 过期套餐检测扩展覆盖 Depleted 状态(status IN (1,2))
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -59,7 +59,7 @@ func NewPackageActivationHandler(
|
||||
func (h *PackageActivationHandler) HandlePackageActivationCheck(ctx context.Context) error {
|
||||
startTime := time.Now()
|
||||
|
||||
// 任务 19.2: 查询已过期的主套餐(status=1 AND expires_at <= NOW)
|
||||
// 任务 19.2: 查询已过期的主套餐(status IN (1,2) AND expires_at <= NOW)
|
||||
expiredPackages, err := h.findExpiredMainPackages(ctx)
|
||||
if err != nil {
|
||||
h.logger.Error("查询过期主套餐失败", zap.Error(err))
|
||||
@@ -97,12 +97,11 @@ func (h *PackageActivationHandler) findExpiredMainPackages(ctx context.Context)
|
||||
var packages []*model.PackageUsage
|
||||
now := time.Now()
|
||||
|
||||
// 查询 status=1 (生效中) AND expires_at <= NOW AND master_usage_id IS NULL (主套餐)
|
||||
err := h.db.WithContext(ctx).
|
||||
Where("status = ?", constants.PackageUsageStatusActive).
|
||||
Where("status IN ?", []int{constants.PackageUsageStatusActive, constants.PackageUsageStatusDepleted}).
|
||||
Where("expires_at <= ?", now).
|
||||
Where("master_usage_id IS NULL"). // 主套餐没有 master_usage_id
|
||||
Limit(1000). // 每次最多处理 1000 个,避免长事务
|
||||
Where("master_usage_id IS NULL").
|
||||
Limit(1000).
|
||||
Find(&packages).Error
|
||||
|
||||
return packages, err
|
||||
|
||||
Reference in New Issue
Block a user