修复(#87): 修复促销数量档下单金额计算
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -40,8 +40,8 @@ func calculatePurchasePrice(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if promoResult != nil && promoResult.Eligible && promoResult.PromoPrice < unitPrice {
|
if promoResult != nil && promoResult.Eligible && promoResult.PromoPrice < originalPrice {
|
||||||
result.PayableBase = promoResult.PromoPrice * quantity
|
result.PayableBase = promoResult.PromoPrice
|
||||||
result.PromoRuleId = promoResult.RuleID
|
result.PromoRuleId = promoResult.RuleID
|
||||||
result.PromoDiscount = originalPrice - result.PayableBase
|
result.PromoDiscount = originalPrice - result.PayableBase
|
||||||
result.PromoPrice = promoResult.PromoPrice
|
result.PromoPrice = promoResult.PromoPrice
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func (m fakePromoModel) Transaction(context.Context, func(*gorm.DB) error) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) {
|
func TestCalculatePurchasePricePromoUsesQuantityTierTotalPrice(t *testing.T) {
|
||||||
svcCtx := &svc.ServiceContext{
|
svcCtx := &svc.ServiceContext{
|
||||||
DB: &gorm.DB{},
|
DB: &gorm.DB{},
|
||||||
PromoModel: fakePromoModel{rules: []*promo.RuleWithPrice{
|
PromoModel: fakePromoModel{rules: []*promo.RuleWithPrice{
|
||||||
@@ -77,7 +77,7 @@ func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) {
|
|||||||
Type: promo.RuleTypeCampaign,
|
Type: promo.RuleTypeCampaign,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
},
|
},
|
||||||
PromoPrice: 600,
|
PromoPrice: 279,
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
@@ -87,9 +87,9 @@ func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) {
|
|||||||
svcCtx,
|
svcCtx,
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
1000,
|
100,
|
||||||
3,
|
7,
|
||||||
[]types.SubscribeDiscount{{Quantity: 3, Discount: 50}},
|
[]types.SubscribeDiscount{{Quantity: 7, Discount: 50}},
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
@@ -97,11 +97,11 @@ func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) {
|
|||||||
t.Fatalf("calculatePurchasePrice returned error: %v", err)
|
t.Fatalf("calculatePurchasePrice returned error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.OriginalPrice != 3000 {
|
if result.OriginalPrice != 700 {
|
||||||
t.Fatalf("OriginalPrice = %d, want 3000", result.OriginalPrice)
|
t.Fatalf("OriginalPrice = %d, want 700", result.OriginalPrice)
|
||||||
}
|
}
|
||||||
if result.PayableBase != 1800 {
|
if result.PayableBase != 279 {
|
||||||
t.Fatalf("PayableBase = %d, want 1800", result.PayableBase)
|
t.Fatalf("PayableBase = %d, want 279", result.PayableBase)
|
||||||
}
|
}
|
||||||
if result.DiscountAmount != 0 {
|
if result.DiscountAmount != 0 {
|
||||||
t.Fatalf("DiscountAmount = %d, want 0", result.DiscountAmount)
|
t.Fatalf("DiscountAmount = %d, want 0", result.DiscountAmount)
|
||||||
@@ -109,8 +109,11 @@ func TestCalculatePurchasePricePromoSkipsPercentDiscount(t *testing.T) {
|
|||||||
if result.PromoRuleId != 9 {
|
if result.PromoRuleId != 9 {
|
||||||
t.Fatalf("PromoRuleId = %d, want 9", result.PromoRuleId)
|
t.Fatalf("PromoRuleId = %d, want 9", result.PromoRuleId)
|
||||||
}
|
}
|
||||||
if result.PromoDiscount != 1200 {
|
if result.PromoDiscount != 421 {
|
||||||
t.Fatalf("PromoDiscount = %d, want 1200", result.PromoDiscount)
|
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,
|
Type: promo.RuleTypeCampaign,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
},
|
},
|
||||||
PromoPrice: 1000,
|
PromoPrice: 3000,
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user