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))