From dccfe45019ad299e0082ffa6b972ae0eda54b702 Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Wed, 27 May 2026 02:31:14 -0700 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D(#87):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BF=83=E9=94=80=E6=95=B0=E9=87=8F=E6=A1=A3=E4=B8=8B=E5=8D=95?= =?UTF-8?q?=E9=87=91=E9=A2=9D=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: multica-agent --- internal/logic/public/order/promoPricing.go | 4 +-- .../logic/public/order/promoPricing_test.go | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/internal/logic/public/order/promoPricing.go b/internal/logic/public/order/promoPricing.go index 77b6e93..a1d9133 100644 --- a/internal/logic/public/order/promoPricing.go +++ b/internal/logic/public/order/promoPricing.go @@ -40,8 +40,8 @@ func calculatePurchasePrice( if err != nil { return nil, err } - if promoResult != nil && promoResult.Eligible && promoResult.PromoPrice < unitPrice { - result.PayableBase = promoResult.PromoPrice * quantity + if promoResult != nil && promoResult.Eligible && promoResult.PromoPrice < originalPrice { + result.PayableBase = promoResult.PromoPrice result.PromoRuleId = promoResult.RuleID result.PromoDiscount = originalPrice - result.PayableBase result.PromoPrice = promoResult.PromoPrice diff --git a/internal/logic/public/order/promoPricing_test.go b/internal/logic/public/order/promoPricing_test.go index fc89213..12456d2 100644 --- a/internal/logic/public/order/promoPricing_test.go +++ b/internal/logic/public/order/promoPricing_test.go @@ -66,7 +66,7 @@ func (m fakePromoModel) Transaction(context.Context, func(*gorm.DB) error) error return nil } -func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) { +func TestCalculatePurchasePricePromoUsesQuantityTierTotalPrice(t *testing.T) { svcCtx := &svc.ServiceContext{ DB: &gorm.DB{}, PromoModel: fakePromoModel{rules: []*promo.RuleWithPrice{ @@ -77,7 +77,7 @@ func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) { Type: promo.RuleTypeCampaign, Enabled: true, }, - PromoPrice: 600, + PromoPrice: 279, }, }}, } @@ -87,9 +87,9 @@ func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) { svcCtx, 1, 2, - 1000, - 3, - []types.SubscribeDiscount{{Quantity: 3, Discount: 50}}, + 100, + 7, + []types.SubscribeDiscount{{Quantity: 7, Discount: 50}}, true, true, ) @@ -97,11 +97,11 @@ func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) { t.Fatalf("calculatePurchasePrice returned error: %v", err) } - if result.OriginalPrice != 3000 { - t.Fatalf("OriginalPrice = %d, want 3000", result.OriginalPrice) + if result.OriginalPrice != 700 { + t.Fatalf("OriginalPrice = %d, want 700", result.OriginalPrice) } - if result.PayableBase != 1800 { - t.Fatalf("PayableBase = %d, want 1800", result.PayableBase) + if result.PayableBase != 279 { + t.Fatalf("PayableBase = %d, want 279", result.PayableBase) } if result.DiscountAmount != 0 { t.Fatalf("DiscountAmount = %d, want 0", result.DiscountAmount) @@ -109,8 +109,11 @@ func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) { if result.PromoRuleId != 9 { t.Fatalf("PromoRuleId = %d, want 9", result.PromoRuleId) } - if result.PromoDiscount != 1200 { - t.Fatalf("PromoDiscount = %d, want 1200", result.PromoDiscount) + if result.PromoDiscount != 421 { + t.Fatalf("PromoDiscount = %d, want 421", result.PromoDiscount) + } + if result.PromoPrice != 279 { + t.Fatalf("PromoPrice = %d, want 279", result.PromoPrice) } } @@ -125,7 +128,7 @@ func TestCalculatePurchasePriceIgnoresInvalidPromoPrice(t *testing.T) { Type: promo.RuleTypeCampaign, Enabled: true, }, - PromoPrice: 1000, + PromoPrice: 3000, }, }}, }