按实际纯币金额计算租客优惠与积分
This commit is contained in:
@@ -5,11 +5,116 @@ import (
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/modules/rentergrowth"
|
||||
"hfb_sys/backend/internal/timeutil"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
func pureCoinDiscountOrder() model.RentalOrder {
|
||||
return model.RentalOrder{
|
||||
RentAmountCent: 38037,
|
||||
OwnerRentAmountCent: 35300,
|
||||
DepositAmountCent: 15000,
|
||||
RentOriginalAmountCent: 38300,
|
||||
RentDiscountAmountCent: 263,
|
||||
PureCoinOriginalAmountCent: 26300,
|
||||
ExtraItemOriginalAmountCent: 12000,
|
||||
RenterDiscountBps: 9900,
|
||||
AccountSnapshot: datatypes.JSON([]byte(`{
|
||||
"haf_coin_amount": 100000000,
|
||||
"asset_summary": {
|
||||
"price_breakdown": {
|
||||
"buyer_coin_base_price": 263,
|
||||
"seller_coin_base_price": 233,
|
||||
"consumable_price": 120
|
||||
}
|
||||
}
|
||||
}`)),
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalculateCheckoutSettlementUsesOnlyActualPureCoinForDiscount(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
consumableAmountCent int64
|
||||
coinConsumedM float64
|
||||
wantPureCoinCent int64
|
||||
wantDiscountCent int64
|
||||
wantActualRentCent int64
|
||||
wantOvershootCent int64
|
||||
}{
|
||||
{
|
||||
name: "全量纯币和额外物品",
|
||||
consumableAmountCent: 12000,
|
||||
coinConsumedM: 100,
|
||||
wantPureCoinCent: 26300,
|
||||
wantDiscountCent: 263,
|
||||
wantActualRentCent: 38037,
|
||||
wantOvershootCent: 0,
|
||||
},
|
||||
{
|
||||
name: "部分纯币和全量额外物品",
|
||||
consumableAmountCent: 12000,
|
||||
coinConsumedM: 50,
|
||||
wantPureCoinCent: 13150,
|
||||
wantDiscountCent: 132,
|
||||
wantActualRentCent: 25018,
|
||||
wantOvershootCent: 0,
|
||||
},
|
||||
{
|
||||
name: "只使用额外物品",
|
||||
consumableAmountCent: 12000,
|
||||
coinConsumedM: 0,
|
||||
wantPureCoinCent: 0,
|
||||
wantDiscountCent: 0,
|
||||
wantActualRentCent: 12000,
|
||||
wantOvershootCent: 0,
|
||||
},
|
||||
{
|
||||
name: "纯币打超仍参与优惠",
|
||||
consumableAmountCent: 12000,
|
||||
coinConsumedM: 110,
|
||||
wantPureCoinCent: 28930,
|
||||
wantDiscountCent: 290,
|
||||
wantActualRentCent: 40640,
|
||||
wantOvershootCent: 2603,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
settlement := calculateCheckoutSettlement(pureCoinDiscountOrder(), test.consumableAmountCent, test.coinConsumedM, 0)
|
||||
if settlement.PureCoinAmountCent != test.wantPureCoinCent || settlement.PureCoinDiscountCent != test.wantDiscountCent {
|
||||
t.Fatalf("纯币原价/优惠 = %d/%d, want %d/%d", settlement.PureCoinAmountCent, settlement.PureCoinDiscountCent, test.wantPureCoinCent, test.wantDiscountCent)
|
||||
}
|
||||
if settlement.ActualRentAmountCent != test.wantActualRentCent || settlement.OvershootAmountCent != test.wantOvershootCent {
|
||||
t.Fatalf("实际租金/打超 = %d/%d, want %d/%d", settlement.ActualRentAmountCent, settlement.OvershootAmountCent, test.wantActualRentCent, test.wantOvershootCent)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildOrderPricingDoesNotDiscountAllExtraItemOrder(t *testing.T) {
|
||||
pricing := buildOrderPricing(
|
||||
model.RentalListing{PriceCent: 12000},
|
||||
model.GameAccount{AssetSummary: datatypes.JSON([]byte(`{
|
||||
"price_breakdown": {
|
||||
"buyer_coin_base_price": 0,
|
||||
"seller_coin_base_price": 0,
|
||||
"consumable_price": 120,
|
||||
"seller_total_price": 120
|
||||
}
|
||||
}`))},
|
||||
)
|
||||
if pricing.PureCoinAmountCent != 0 || pricing.ExtraItemAmountCent != 12000 || pricing.PureCoinPlatformFeeCent != 0 {
|
||||
t.Fatalf("全额外物品订单纯币/额外物品/纯币差价 = %d/%d/%d, want 0/12000/0", pricing.PureCoinAmountCent, pricing.ExtraItemAmountCent, pricing.PureCoinPlatformFeeCent)
|
||||
}
|
||||
if discount := rentergrowth.CalculateDiscountCent(pricing.PureCoinAmountCent, pricing.PureCoinPlatformFeeCent, 9900); discount != 0 {
|
||||
t.Fatalf("全额外物品订单优惠 = %d, want 0", discount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalculateCheckoutSettlementRefundsUnusedRent(t *testing.T) {
|
||||
order := model.RentalOrder{
|
||||
RentAmountCent: 38300,
|
||||
|
||||
Reference in New Issue
Block a user