修复代管订单押金赔付待打款金额
This commit is contained in:
@@ -289,7 +289,7 @@ func refreshCheckoutSettlementDTO(dto *CheckoutDTO, order model.RentalOrder, che
|
||||
if checkout.Status != checkoutStatusSubmitted && checkout.Status != checkoutStatusCountered {
|
||||
return
|
||||
}
|
||||
settlement := calculateCheckoutSettlement(order, checkout.ConsumableAmountCent, checkout.CoinConsumedM, checkout.DepositDeductAmountCent)
|
||||
settlement := calculateCheckoutSettlement(order, checkout.ConsumableAmountCent, checkout.CoinConsumedM, effectiveCheckoutDepositDeductCent(checkout))
|
||||
rent := settlement.ActualRentAmountCent
|
||||
ownerRent := settlement.OwnerRentIncomeCent
|
||||
platform := settlement.PlatformFeeCent
|
||||
|
||||
@@ -278,7 +278,16 @@ func buildCheckout(order model.RentalOrder, initiatedBy uint64, status string, c
|
||||
}
|
||||
|
||||
func buildCheckoutSettlement(order model.RentalOrder, checkout *model.OrderCheckout) checkoutSettlement {
|
||||
return calculateCheckoutSettlement(order, checkout.ConsumableAmountCent, checkout.CoinConsumedM, checkout.DepositDeductAmountCent)
|
||||
return calculateCheckoutSettlement(order, checkout.ConsumableAmountCent, checkout.CoinConsumedM, effectiveCheckoutDepositDeductCent(*checkout))
|
||||
}
|
||||
|
||||
// effectiveCheckoutDepositDeductCent keeps legacy checkouts that only populated
|
||||
// other_amount_cent from losing their deposit compensation at finalization.
|
||||
func effectiveCheckoutDepositDeductCent(checkout model.OrderCheckout) int64 {
|
||||
if checkout.DepositDeductAmountCent > 0 {
|
||||
return checkout.DepositDeductAmountCent
|
||||
}
|
||||
return maxCent(checkout.OtherAmountCent, 0)
|
||||
}
|
||||
|
||||
func calculateCheckoutSettlement(order model.RentalOrder, consumableAmountCent int64, coinConsumedM float64, depositDeductAmountCent int64) checkoutSettlement {
|
||||
|
||||
@@ -381,6 +381,20 @@ func TestBuildCheckoutSettlementWithDepositDeduct(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildCheckoutSettlementFallsBackToLegacyOtherAmount(t *testing.T) {
|
||||
order := model.RentalOrder{
|
||||
RentAmountCent: 24000,
|
||||
OwnerRentAmountCent: 21600,
|
||||
DepositAmountCent: 5000,
|
||||
}
|
||||
checkout := &model.OrderCheckout{OtherAmountCent: 2000}
|
||||
|
||||
settlement := buildCheckoutSettlement(order, checkout)
|
||||
if settlement.DepositCompensationCent != 2000 || settlement.OwnerIncomeCent != 23600 {
|
||||
t.Fatalf("legacy other amount settlement = compensation %d, owner income %d, want 2000/23600", settlement.DepositCompensationCent, settlement.OwnerIncomeCent)
|
||||
}
|
||||
}
|
||||
|
||||
// TestBuildCheckoutSettlementWithConsumable 测试额外消耗
|
||||
func TestBuildCheckoutSettlementWithConsumable(t *testing.T) {
|
||||
order := model.RentalOrder{
|
||||
|
||||
Reference in New Issue
Block a user