From 202c1c18d7dbff41673d4da3246f360a7dfea59e Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Mon, 30 Mar 2026 22:30:12 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=90=8C=20quantity?= =?UTF-8?q?=20=E5=AD=98=E5=9C=A8=E6=96=B0=E7=94=A8=E6=88=B7=E5=92=8C?= =?UTF-8?q?=E6=99=AE=E9=80=9A=E6=8A=98=E6=89=A3=E6=A1=A3=E6=97=B6=E8=80=81?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=97=A0=E6=B3=95=E4=B8=8B=E5=8D=95=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit isNewUserOnlyForQuantity 原逻辑取第一条匹配记录即返回, 当同一 quantity 同时配置了 new_user_only=true 和 false 两档时, 结果依赖数组顺序,导致老用户/超24h用户触发 SubscribeNewUserOnly 错误。 修复:扫描所有同 quantity 档位,仅当存在 true 且无 false 兜底时才返回 true; 有 false 兜底则返回 false,老用户可正常购买并命中普通折扣档。 Co-Authored-By: claude-flow --- internal/logic/public/order/getDiscount.go | 20 +++++++++++++++----- queue/logic/order/activateOrderLogic.go | 18 ++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/internal/logic/public/order/getDiscount.go b/internal/logic/public/order/getDiscount.go index ee7dd4e..db107f3 100644 --- a/internal/logic/public/order/getDiscount.go +++ b/internal/logic/public/order/getDiscount.go @@ -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 } diff --git a/queue/logic/order/activateOrderLogic.go b/queue/logic/order/activateOrderLogic.go index 45a41cc..582f595 100644 --- a/queue/logic/order/activateOrderLogic.go +++ b/queue/logic/order/activateOrderLogic.go @@ -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 }