fix: 修复同 quantity 存在新用户和普通折扣档时老用户无法下单的问题
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 7m34s

isNewUserOnlyForQuantity 原逻辑取第一条匹配记录即返回,
当同一 quantity 同时配置了 new_user_only=true 和 false 两档时,
结果依赖数组顺序,导致老用户/超24h用户触发 SubscribeNewUserOnly 错误。

修复:扫描所有同 quantity 档位,仅当存在 true 且无 false 兜底时才返回 true;
有 false 兜底则返回 false,老用户可正常购买并命中普通折扣档。

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
shanshanzhong 2026-03-30 22:30:12 -07:00
parent e0b2be2058
commit 202c1c18d7
2 changed files with 29 additions and 9 deletions

View File

@ -16,13 +16,23 @@ func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64, isNewUs
}
// isNewUserOnlyForQuantity checks whether the matched discount tier has new_user_only enabled.
// Returns true only when all matching tiers for the given quantity require new-user status
// (i.e. no fallback tier with new_user_only=false exists). When both a new-user-only tier
// and a general tier exist for the same quantity, non-new-users can still purchase via the
// general tier, so this returns false.
func isNewUserOnlyForQuantity(discounts []types.SubscribeDiscount, inputQuantity int64) bool {
for _, discount := range discounts {
if inputQuantity == discount.Quantity {
return discount.NewUserOnly
hasNewUserOnly := false
hasFallback := false
for _, d := range discounts {
if d.Quantity != inputQuantity {
continue
}
if d.NewUserOnly {
hasNewUserOnly = true
} else {
hasFallback = true
}
}
return false
return hasNewUserOnly && !hasFallback
}

View File

@ -1319,12 +1319,22 @@ func (l *ActivateOrderLogic) RedemptionActivate(ctx context.Context, orderInfo *
}
// isNewUserOnlyForQuantity checks whether the matched discount tier has new_user_only enabled.
// Returns true only when all matching tiers for the given quantity require new-user status
// (i.e. no fallback tier with new_user_only=false exists). When both a new-user-only tier
// and a general tier exist for the same quantity, non-new-users can still purchase via the
// general tier, so this returns false.
func isNewUserOnlyForQuantity(discounts []internaltypes.SubscribeDiscount, inputQuantity int64) bool {
hasNewUserOnly := false
hasFallback := false
for _, d := range discounts {
if inputQuantity == d.Quantity {
return d.NewUserOnly
if d.Quantity != inputQuantity {
continue
}
if d.NewUserOnly {
hasNewUserOnly = true
} else {
hasFallback = true
}
}
return false
return hasNewUserOnly && !hasFallback
}