From e51dbea7c760967bb0e759ffff19d85e6840b16d Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Tue, 31 Mar 2026 07:22:12 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20getDiscount=20=E6=96=B0=E4=BA=BA?= =?UTF-8?q?=E5=8F=96=E6=8A=98=E6=89=A3=E6=9C=80=E5=A4=A7=E6=A1=A3=EF=BC=8C?= =?UTF-8?q?=E9=9D=9E=E6=96=B0=E4=BA=BA=E5=8F=96=E6=8A=98=E6=89=A3=E6=9C=80?= =?UTF-8?q?=E5=B0=8F=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新人:所有匹配 quantity 的条目中取 discount 值最小的(折扣力度最大) - 非新人:所有匹配 quantity 的条目中取 discount 值最大的(折扣力度最小,接近原价) - 不再按 new_user_only 过滤,由 isNewUserOnlyForQuantity 在上层控制准入 Co-Authored-By: claude-flow --- internal/logic/public/order/getDiscount.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/internal/logic/public/order/getDiscount.go b/internal/logic/public/order/getDiscount.go index 565c14b..87dc722 100644 --- a/internal/logic/public/order/getDiscount.go +++ b/internal/logic/public/order/getDiscount.go @@ -4,25 +4,21 @@ import "github.com/perfect-panel/server/internal/types" // getDiscount returns the discount factor for the given quantity. // -// - New user: pick the tier with the lowest discount value (best deal) among all matching tiers. -// - Non-new user: pick the tier with the highest discount value (most expensive / least discount) -// among tiers where new_user_only=false only. +// - New user: pick the tier with the lowest discount value (biggest saving). +// - Non-new user: pick the tier with the highest discount value (least saving / closest to full price). func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64, isNewUser bool) float64 { best := float64(-1) for _, d := range discounts { if d.Quantity != inputMonths || d.Discount <= 0 || d.Discount >= 100 { continue } - if !isNewUser && d.NewUserOnly { - continue - } if isNewUser { // lowest discount value = biggest saving if best < 0 || d.Discount < best { best = d.Discount } } else { - // highest discount value = least discount (closest to original price) + // highest discount value = least saving (closest to original price) if best < 0 || d.Discount > best { best = d.Discount }