退款时压缩卖方加价,人工/自动批次仅完结单可入账,号主收入进主站钱包;仲裁后重算释放并支持作废未入账 DS。开通时四种模式按默认生效,对外口径合并为 35/40/25,不再单独展示通道费。 Co-authored-by: Cursor <cursoragent@cursor.com>
116 lines
3.6 KiB
TypeScript
116 lines
3.6 KiB
TypeScript
import type { DistributionRule } from '@/features/admin/api/adminDistribution'
|
|
|
|
export const DISTRIBUTION_MODES = [
|
|
{
|
|
value: 'two_party_distributor_receive',
|
|
label: '两方 · 分站收号',
|
|
hint: '主站下单,货在分站',
|
|
},
|
|
{
|
|
value: 'two_party_platform_receive',
|
|
label: '两方 · 分站卖出',
|
|
hint: '分站卖主站货',
|
|
},
|
|
{
|
|
value: 'three_party',
|
|
label: '三方分账',
|
|
hint: '分站卖另一分站的货',
|
|
},
|
|
{
|
|
value: 'site_self_sell',
|
|
label: '本站自卖',
|
|
hint: '分站卖本站货,卖出站拿 75%',
|
|
},
|
|
] as const
|
|
|
|
const MODE_LABELS: Record<string, string> = Object.fromEntries(
|
|
DISTRIBUTION_MODES.map(item => [item.value, item.label])
|
|
)
|
|
|
|
const PARTY_ROLE_LABELS: Record<string, string> = {
|
|
distributor_receive: '分站收号',
|
|
platform_sell: '主站卖出',
|
|
platform_receive: '主站收号',
|
|
distributor_sell: '分站卖出',
|
|
distributor_a: '收号站',
|
|
distributor_b: '卖出站',
|
|
}
|
|
|
|
export function distributionModeLabel(mode?: string) {
|
|
if (!mode) return '-'
|
|
return MODE_LABELS[mode] || mode
|
|
}
|
|
|
|
export function distributionPartyRoleLabel(role?: string) {
|
|
if (!role) return '-'
|
|
return PARTY_ROLE_LABELS[role] || role
|
|
}
|
|
|
|
export function formatRatioPercent(value?: number) {
|
|
const n = Number(value || 0)
|
|
return `${n.toFixed(n % 1 === 0 ? 0 : 1)}%`
|
|
}
|
|
|
|
export function ruleSplitParts(rule: DistributionRule) {
|
|
switch (rule.mode) {
|
|
case 'two_party_distributor_receive':
|
|
return [
|
|
{ label: '分站收号', value: formatRatioPercent(rule.distributor_receive_ratio) },
|
|
{ label: '主站卖出', value: formatRatioPercent(rule.platform_sell_ratio) },
|
|
]
|
|
case 'two_party_platform_receive':
|
|
return [
|
|
{ label: '主站收号', value: formatRatioPercent(rule.platform_receive_ratio) },
|
|
{ label: '分站卖出', value: formatRatioPercent(rule.distributor_sell_ratio) },
|
|
]
|
|
case 'three_party':
|
|
return [
|
|
{ label: '收号站', value: formatRatioPercent(rule.distributor_a_ratio) },
|
|
{ label: '卖出站', value: formatRatioPercent(rule.distributor_b_ratio) },
|
|
]
|
|
case 'site_self_sell':
|
|
return [{ label: '本站卖出', value: formatRatioPercent(rule.distributor_sell_ratio) }]
|
|
default:
|
|
return []
|
|
}
|
|
}
|
|
|
|
export function formatServiceFee(
|
|
rule: Pick<DistributionRule, 'service_fee_value' | 'service_fee_unit'>
|
|
) {
|
|
if (rule.service_fee_unit === 'fixed_amount') {
|
|
return `${Number(rule.service_fee_value || 0).toFixed(2)} 元/单`
|
|
}
|
|
return formatRatioPercent(rule.service_fee_value)
|
|
}
|
|
|
|
export function settlementBatchKind(batchNo?: string) {
|
|
if (batchNo?.startsWith('DA')) {
|
|
return { label: '自动释放', type: 'success' as const }
|
|
}
|
|
if (batchNo?.startsWith('DS')) {
|
|
return { label: '人工批次', type: 'warning' as const }
|
|
}
|
|
return { label: '结算批次', type: 'info' as const }
|
|
}
|
|
|
|
export function distributorReleaseLabel(row: {
|
|
distributor_settlement_status?: string
|
|
release_at?: string
|
|
}) {
|
|
if (row.distributor_settlement_status === 'settled') {
|
|
return { label: '已释放入账', type: 'success' as const }
|
|
}
|
|
if (row.distributor_settlement_status === 'pending' && row.release_at) {
|
|
const date = new Date(row.release_at)
|
|
const text = Number.isNaN(date.getTime())
|
|
? '待释放'
|
|
: `待释放 ${date.toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' })}`
|
|
return { label: text, type: 'warning' as const }
|
|
}
|
|
if (row.distributor_settlement_status === 'pending') {
|
|
return { label: '待释放', type: 'info' as const }
|
|
}
|
|
return { label: '未进入释放', type: 'info' as const }
|
|
}
|