fix(checkout): 修复角色价格快照下到手试算不更新
This commit is contained in:
@@ -70,3 +70,73 @@ describe('useCheckoutSimulator insurance fee', () => {
|
||||
expect(simulator.value.lossCompensationYuan).toBe(50)
|
||||
})
|
||||
})
|
||||
|
||||
describe('useCheckoutSimulator role-sanitized snapshot', () => {
|
||||
it('号主修改实际消耗后实时更新试算金额', () => {
|
||||
const order = orderFixture()
|
||||
order.account_snapshot = {
|
||||
haf_coin_amount: 100_000_000,
|
||||
asset_summary: {
|
||||
publish_ratio: 40,
|
||||
display_ratio: 40,
|
||||
display_coin_base_price: 200,
|
||||
consumable_price: 50,
|
||||
},
|
||||
}
|
||||
const form = ref<CounterFormState>({
|
||||
consumableAmountYuan: 50,
|
||||
coin_consumed_m: 0,
|
||||
depositDeductAmountYuan: 0,
|
||||
reason: '',
|
||||
evidenceText: '',
|
||||
})
|
||||
const simulator = useCheckoutSimulator({
|
||||
order: ref(order),
|
||||
isOwner: ref(true),
|
||||
isRenter: ref(false),
|
||||
form,
|
||||
})
|
||||
|
||||
expect(simulator.value?.totalIncomeYuan).toBe(50)
|
||||
|
||||
form.value.coin_consumed_m = 50
|
||||
|
||||
if (!simulator.value || simulator.value.role !== 'owner') {
|
||||
throw new Error('owner simulation missing')
|
||||
}
|
||||
expect(simulator.value.totalIncomeYuan).toBe(165)
|
||||
expect(simulator.value.insuranceFeeYuan).toBe(10)
|
||||
})
|
||||
|
||||
it('租客侧同样按摊平后的比例和币价计算', () => {
|
||||
const order = orderFixture()
|
||||
order.account_snapshot = {
|
||||
haf_coin_amount: 100_000_000,
|
||||
asset_summary: {
|
||||
publish_ratio: 40,
|
||||
display_ratio: 40,
|
||||
display_coin_base_price: 250,
|
||||
consumable_price: 0,
|
||||
},
|
||||
}
|
||||
const form = ref<CounterFormState>({
|
||||
consumableAmountYuan: 0,
|
||||
coin_consumed_m: 50,
|
||||
depositDeductAmountYuan: 0,
|
||||
reason: '',
|
||||
evidenceText: '',
|
||||
})
|
||||
const simulator = useCheckoutSimulator({
|
||||
order: ref(order),
|
||||
isOwner: ref(false),
|
||||
isRenter: ref(true),
|
||||
form,
|
||||
})
|
||||
|
||||
if (!simulator.value || simulator.value.role !== 'renter') {
|
||||
throw new Error('renter simulation missing')
|
||||
}
|
||||
expect(simulator.value.actualCostYuan).toBe(125)
|
||||
expect(simulator.value.totalRefundYuan).toBe(275)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -55,11 +55,24 @@ export function useCheckoutSimulator(options: {
|
||||
| undefined) || {}
|
||||
|
||||
const totalCoinM = roundQuantity(readNumber(snapshot?.haf_coin_amount) / 1000000)
|
||||
const buyerRatio = readNumber(priceBreakdown['buyer_ratio'])
|
||||
const sellerRatio = readNumber(priceBreakdown['seller_ratio'])
|
||||
const buyerCoinBaseYuan = readNumber(priceBreakdown['buyer_coin_base_price'])
|
||||
const sellerCoinBaseYuan = readNumber(priceBreakdown['seller_coin_base_price'])
|
||||
const prepaidConsumableYuan = readNumber(priceBreakdown['consumable_price'])
|
||||
|
||||
// 订单详情接口会按角色删除 price_breakdown,并把当前角色可见的价格字段摊平。
|
||||
// 同时兼容原始快照,便于管理端/历史数据复用同一套试算。
|
||||
const roleRatio = readNumber(assetSummary?.publish_ratio ?? assetSummary?.display_ratio)
|
||||
const roleCoinBaseYuan = readNumber(assetSummary?.display_coin_base_price)
|
||||
const summaryConsumableYuan = readNumber(assetSummary?.consumable_price)
|
||||
const buyerRatio =
|
||||
readNumber(priceBreakdown['buyer_ratio']) || (options.isRenter.value ? roleRatio : 0)
|
||||
const sellerRatio =
|
||||
readNumber(priceBreakdown['seller_ratio']) || (options.isOwner.value ? roleRatio : 0)
|
||||
const buyerCoinBaseYuan =
|
||||
readNumber(priceBreakdown['buyer_coin_base_price']) ||
|
||||
(options.isRenter.value ? roleCoinBaseYuan : 0)
|
||||
const sellerCoinBaseYuan =
|
||||
readNumber(priceBreakdown['seller_coin_base_price']) ||
|
||||
(options.isOwner.value ? roleCoinBaseYuan : 0)
|
||||
const prepaidConsumableYuan =
|
||||
readNumber(priceBreakdown['consumable_price']) || summaryConsumableYuan
|
||||
|
||||
const coinUseRatio = totalCoinM > 0 ? roundQuantity(consumedM / totalCoinM) : 1
|
||||
const isCoinOvershoot = totalCoinM > 0 && consumedM > totalCoinM
|
||||
|
||||
Reference in New Issue
Block a user