From 5733ebe40d833ff7d30eae38452080c3fb620c16 Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Tue, 31 Mar 2026 06:35:14 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20renewal=20logic=20=E5=B0=9D=E9=B2=9C?= =?UTF-8?q?=E4=BB=B7=E6=9C=AA=E7=94=9F=E6=95=88=20=E2=80=94=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E8=B5=B0=20newUser=20=E8=B5=84=E6=A0=BC=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit renewalLogic 在计算折扣时硬编码 isNewUser=false, 导致新用户在 24h 窗口内通过 renewal 接口购买时无法享受尝鲜价。 改为调用 resolveNewUserDiscountEligibility,与 purchaseLogic 保持一致。 Co-Authored-By: claude-flow --- internal/logic/public/order/renewalLogic.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/logic/public/order/renewalLogic.go b/internal/logic/public/order/renewalLogic.go index 9aa19c4..1642fee 100644 --- a/internal/logic/public/order/renewalLogic.go +++ b/internal/logic/public/order/renewalLogic.go @@ -81,11 +81,17 @@ func (l *RenewalLogic) Renewal(req *types.RenewalOrderRequest) (resp *types.Rene if !*sub.Sell { return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "subscribe not sell") } + newUserDiscount, err := resolveNewUserDiscountEligibility(l.ctx, l.svcCtx.DB, u.Id, sub.Id, req.Quantity, sub.Discount) + if err != nil { + l.Errorw("[Renewal] Database query error resolving new user eligibility", + logger.Field("error", err.Error()), + logger.Field("user_id", u.Id), + ) + return nil, err + } var discount float64 = 1 - if sub.Discount != "" { - var dis []types.SubscribeDiscount - _ = json.Unmarshal([]byte(sub.Discount), &dis) - discount = getDiscount(dis, req.Quantity, false) + if len(newUserDiscount.Discounts) > 0 { + discount = getDiscount(newUserDiscount.Discounts, req.Quantity, newUserDiscount.EligibleForDiscount) } price := sub.UnitPrice * req.Quantity amount := int64(math.Round(float64(price) * discount))