fix: 按实际纯币结算金额计算保险费用
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import type { Order } from '@/features/orders/api/orders'
|
||||
import type { CounterFormState } from '@/features/orders/composables/useOrderActions'
|
||||
import { useCheckoutSimulator } from '@/features/orders/composables/useCheckoutSimulator'
|
||||
|
||||
function orderFixture(): Order {
|
||||
return {
|
||||
id: 1,
|
||||
order_no: 'ORDER-1',
|
||||
listing_id: 1,
|
||||
listing_no: 'LISTING-1',
|
||||
account_id: 1,
|
||||
owner_id: 1,
|
||||
renter_id: 2,
|
||||
title: '测试账号',
|
||||
server_region: '国服',
|
||||
login_platform: '扫码',
|
||||
estimated_duration_hours: 24,
|
||||
display_amount_cent: 25000,
|
||||
rent_amount_cent: 25000,
|
||||
owner_rent_amount_cent: 25000,
|
||||
deposit_amount_cent: 15000,
|
||||
deposit_original_amount_cent: 15000,
|
||||
deposit_waived_amount_cent: 0,
|
||||
insurance_fee_bps: 800,
|
||||
account_snapshot: {
|
||||
haf_coin_amount: 100_000_000,
|
||||
asset_summary: {
|
||||
price_breakdown: {
|
||||
buyer_ratio: 40,
|
||||
seller_ratio: 40,
|
||||
buyer_coin_base_price: 250,
|
||||
seller_coin_base_price: 250,
|
||||
consumable_price: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
status: 'renting',
|
||||
handoff_status: 'received',
|
||||
settlement_status: 'unsettled',
|
||||
created_at: '2026-11-05T00:00:00+08:00',
|
||||
updated_at: '2026-11-05T00:00:00+08:00',
|
||||
}
|
||||
}
|
||||
|
||||
describe('useCheckoutSimulator insurance fee', () => {
|
||||
it('按实际纯币结算金额计费,额外物品不进入保险基数', () => {
|
||||
const form = ref<CounterFormState>({
|
||||
consumableAmountYuan: 50,
|
||||
coin_consumed_m: 50,
|
||||
depositDeductAmountYuan: 0,
|
||||
reason: '',
|
||||
evidenceText: '',
|
||||
})
|
||||
const simulator = useCheckoutSimulator({
|
||||
order: ref(orderFixture()),
|
||||
isOwner: ref(true),
|
||||
isRenter: ref(false),
|
||||
form,
|
||||
})
|
||||
|
||||
expect(simulator.value?.role).toBe('owner')
|
||||
if (!simulator.value || simulator.value.role !== 'owner') {
|
||||
throw new Error('owner simulation missing')
|
||||
}
|
||||
expect(simulator.value.insuranceFeeYuan).toBe(10)
|
||||
expect(simulator.value.rentIncomeYuan).toBe(165)
|
||||
expect(simulator.value.lossCompensationYuan).toBe(50)
|
||||
})
|
||||
})
|
||||
@@ -102,7 +102,7 @@ export function useCheckoutSimulator(options: {
|
||||
|
||||
const grossOwnerRentIncomeYuan = roundMoney(ownerCoinYuan + ownerConsumableYuan)
|
||||
const insuranceFeeYuan = roundMoney(
|
||||
(grossOwnerRentIncomeYuan * Number(o.insurance_fee_bps || 0)) / 10000
|
||||
(ownerCoinYuan * Number(o.insurance_fee_bps || 0)) / 10000
|
||||
)
|
||||
const ownerRentIncomeYuan = Math.max(
|
||||
roundMoney(grossOwnerRentIncomeYuan - insuranceFeeYuan),
|
||||
|
||||
Reference in New Issue
Block a user