修复一些问题,主要是生效套餐
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m16s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m16s
This commit is contained in:
@@ -72,28 +72,26 @@ func (h *PackageActivationHandler) HandlePackageActivationCheck(ctx context.Cont
|
||||
return err
|
||||
}
|
||||
|
||||
if len(expiredPackages) == 0 {
|
||||
return nil
|
||||
}
|
||||
if len(expiredPackages) > 0 {
|
||||
h.logger.Info("发现过期主套餐",
|
||||
zap.Int("count", len(expiredPackages)),
|
||||
zap.Duration("check_duration", time.Since(startTime)))
|
||||
|
||||
h.logger.Info("发现过期主套餐",
|
||||
zap.Int("count", len(expiredPackages)),
|
||||
zap.Duration("check_duration", time.Since(startTime)))
|
||||
|
||||
// 处理每个过期的主套餐
|
||||
for _, pkg := range expiredPackages {
|
||||
if err := h.processExpiredPackage(ctx, pkg); err != nil {
|
||||
h.logger.Error("处理过期套餐失败",
|
||||
zap.Uint("package_usage_id", pkg.ID),
|
||||
zap.Error(err))
|
||||
// 继续处理下一个,不中断
|
||||
continue
|
||||
// 处理每个过期的主套餐
|
||||
for _, pkg := range expiredPackages {
|
||||
if err := h.processExpiredPackage(ctx, pkg); err != nil {
|
||||
h.logger.Error("处理过期套餐失败",
|
||||
zap.Uint("package_usage_id", pkg.ID),
|
||||
zap.Error(err))
|
||||
// 继续处理下一个,不中断
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
h.logger.Info("套餐激活检查完成",
|
||||
zap.Int("processed", len(expiredPackages)),
|
||||
zap.Duration("total_duration", time.Since(startTime)))
|
||||
h.logger.Info("套餐激活检查完成",
|
||||
zap.Int("processed", len(expiredPackages)),
|
||||
zap.Duration("total_duration", time.Since(startTime)))
|
||||
}
|
||||
|
||||
// 任务 6: 孤儿套餐扫描
|
||||
orphanCount, err := h.findAndActivateOrphanPackages(ctx)
|
||||
@@ -109,15 +107,15 @@ func (h *PackageActivationHandler) HandlePackageActivationCheck(ctx context.Cont
|
||||
}
|
||||
|
||||
// findAndActivateOrphanPackages 任务 6.1-6.2: 查找孤儿载体并触发激活
|
||||
// 孤儿定义:存在 status=0 的主套餐(pending_realname_activation=false),但不存在 status=1 的主套餐
|
||||
// 孤儿定义:存在 status=0 的主套餐,但不存在 status=1 的主套餐。
|
||||
func (h *PackageActivationHandler) findAndActivateOrphanPackages(ctx context.Context) (int, error) {
|
||||
// 查询孤儿待生效主套餐(无生效主套餐但有待生效主套餐)
|
||||
var orphanUsages []*model.PackageUsage
|
||||
err := h.db.WithContext(ctx).
|
||||
Where("status = ?", constants.PackageUsageStatusPending).
|
||||
Where("master_usage_id IS NULL").
|
||||
Where("pending_realname_activation = ?", false).
|
||||
Where("deleted_at IS NULL").
|
||||
Order("priority ASC, created_at ASC").
|
||||
Limit(100).
|
||||
Find(&orphanUsages).Error
|
||||
if err != nil {
|
||||
@@ -178,9 +176,9 @@ func (h *PackageActivationHandler) findAndActivateOrphanPackages(ctx context.Con
|
||||
continue
|
||||
}
|
||||
|
||||
// 保留 priority 最低的套餐
|
||||
// 保留购买顺序最靠前的套餐,队首未满足实名条件时不跳过。
|
||||
if existing, ok := carrierMap[key]; ok {
|
||||
if usage.Priority < existing.Priority {
|
||||
if usage.Priority < existing.Priority || (usage.Priority == existing.Priority && usage.CreatedAt.Before(existing.CreatedAt)) {
|
||||
carrierMap[key] = usage
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user