feat(consignment): 保证金支持按规格选项价格乘寄售数量计算

This commit is contained in:
2026-11-08 12:52:24 +08:00
parent ac2411ab6e
commit 01c2517f29
9 changed files with 436 additions and 17 deletions
@@ -0,0 +1,31 @@
import type { ConsignmentProfileConfig, ConsignmentSpecValues } from '../types/consignment'
/**
* 发布寄卖时的履约保证金(分)。
*
* - fixed:固定金额
* - per_quantity:每件金额 × 寄售数量
* - per_spec:所选规格选项的每件保证金 × 寄售数量(选项没配价格按 0 计)
* - 保证金开关关闭时退回平台统一押金
*/
export function resolveConsignmentDepositFen(input: {
deposit: ConsignmentProfileConfig['deposit'] | null | undefined
quantity: number
specValues?: ConsignmentSpecValues | null
fallbackFen: number
}): number {
const deposit = input.deposit
if (!deposit?.enabled) return Math.max(0, Math.round(Number(input.fallbackFen || 0)))
const quantity = Math.max(1, Math.round(Number(input.quantity || 1)))
if (deposit.mode === 'per_quantity') {
return Math.max(0, Math.round(Number(deposit.unitAmountFen || 0))) * quantity
}
if (deposit.mode === 'per_spec') {
const specKey = String(deposit.specKey || '').trim()
const selected = specKey ? String(input.specValues?.[specKey] ?? '').trim() : ''
const unitFen = Math.max(0, Math.round(Number(deposit.specPrices?.[selected] ?? 0)))
return unitFen * quantity
}
return Math.max(0, Math.round(Number(deposit.fixedAmountFen || 0)))
}