feat(consignment): 匹配弹窗增加付款金额与售价差价

一键查询待匹配订单与手动匹配寄卖新增「工单用户付款金额」列,
售价后括号显示「用户付款金额 - 售价」差价:正数绿、负数红、
0 黄;拼单不显示差价,付款未知显示 -。
This commit is contained in:
2026-11-16 14:38:45 +08:00
parent ec11022c1b
commit 866f0d37fd
12 changed files with 279 additions and 12 deletions
@@ -7,9 +7,11 @@ import { useMemo, useState } from 'react'
import PercentTable from '@/components/common/PercentTable'
import { fetchPendingPistolMatches } from '@/services/admin/consignment'
import type { PendingPistolMatchPair } from '@/types/consignment'
import { formatFenMoney } from '@/utils/consignment-payment-price-diff'
import { formatDateTime } from '@/utils/date-time'
import { resolveConsignmentPriorityTagColor } from '@/utils/consignment-match-priority'
import ConsignmentPriceWithDiff from './ConsignmentPriceWithDiff'
import ConsignmentWorkOrderMatchModal from './ConsignmentWorkOrderMatchModal'
const { Text } = Typography
@@ -219,6 +221,26 @@ export default function ConsignmentPendingMatchModal({
</Text>
),
},
{
title: '工单用户付款金额',
key: 'userPayment',
width: 140,
render: (_, record) => (
<Text style={{ fontSize: 13 }}>{formatFenMoney(record.userPaymentFen)}</Text>
),
},
{
title: '售价',
key: 'salePrice',
width: 180,
render: (_, record) => (
<ConsignmentPriceWithDiff
userPaymentFen={record.userPaymentFen}
salePriceFen={record.salePriceFen}
sharingEnabled={record.sharingEnabled}
/>
),
},
{
title: '匹配说明',
key: 'reason',
@@ -285,7 +307,7 @@ export default function ConsignmentPendingMatchModal({
: '匹配 · 待匹配订单 × 在库现货'
}
open={open}
width="min(1320px, 94vw)"
width="min(1480px, 96vw)"
footer={null}
destroyOnHidden
onCancel={onClose}
@@ -363,7 +385,7 @@ export default function ConsignmentPendingMatchModal({
loading={query.isFetching}
dataSource={pairs}
columns={columns}
scroll={{ y: 460 }}
scroll={{ x: 1680, y: 460 }}
pagination={{
pageSize: 20,
showSizeChanger: false,
@@ -0,0 +1,27 @@
import { Typography } from 'antd'
import { formatFenMoney, resolvePaymentPriceDiff } from '@/utils/consignment-payment-price-diff'
/**
* 寄售售价 + 差价:`¥110.00(+¥20.00)`。
*
* 差价 = 工单用户付款金额 - 售价;正数绿、负数红、0 黄。
* 拼单(多份售价)或用户付款未知时不显示括号。
*/
export default function ConsignmentPriceWithDiff({
userPaymentFen,
salePriceFen,
sharingEnabled = false,
}: {
userPaymentFen: number | null | undefined
salePriceFen: number | null | undefined
sharingEnabled?: boolean
}) {
const diff = resolvePaymentPriceDiff(userPaymentFen, salePriceFen, { sharingEnabled })
return (
<Typography.Text style={{ fontSize: 13 }}>
{formatFenMoney(salePriceFen)}
{diff ? <span style={{ color: diff.color }}>({diff.text})</span> : null}
</Typography.Text>
)
}
@@ -8,6 +8,7 @@ import {
matchAdminConsignmentWorkOrder,
} from '@/services/admin/consignment'
import type { ConsignmentMatchCandidate } from '@/types/consignment'
import { formatFenMoney } from '@/utils/consignment-payment-price-diff'
import {
computeConsignmentMatchScore,
describeConsignmentMatch,
@@ -15,9 +16,7 @@ import {
} from '@/utils/consignment-match-coverage'
import { resolveConsignmentPriorityTagColor } from '@/utils/consignment-match-priority'
function money(fen: number) {
return `¥${((Number(fen || 0) || 0) / 100).toFixed(2)}`
}
import ConsignmentPriceWithDiff from './ConsignmentPriceWithDiff'
const EMPTY_INVENTORY_IDS: number[] = []
@@ -205,7 +204,7 @@ export default function ConsignmentWorkOrderMatchModal({
title="手动匹配寄卖"
open={open}
onCancel={onClose}
width="min(1180px, 96vw)"
width="min(1280px, 96vw)"
destroyOnHidden
footer={
<Space>
@@ -331,7 +330,7 @@ export default function ConsignmentWorkOrderMatchModal({
size="small"
loading={candidatesQuery.isFetching}
pagination={{ pageSize: 10, showSizeChanger: false }}
scroll={{ x: 1210, y: 420 }}
scroll={{ x: 1470, y: 420 }}
dataSource={visibleOptions}
rowSelection={{
// 整单只能选一条;拼单可多选,必须覆盖剩余份数才能提交。
@@ -417,11 +416,27 @@ export default function ConsignmentWorkOrderMatchModal({
</Tag>
),
},
{
title: '工单用户付款金额',
key: 'userPayment',
width: 140,
render: () => (
<Typography.Text style={{ fontSize: 13 }}>
{formatFenMoney(data?.userPaymentFen)}
</Typography.Text>
),
},
{
title: '售价',
key: 'price',
width: 100,
render: (_, item) => money(item.salePriceFen),
width: 180,
render: (_, item) => (
<ConsignmentPriceWithDiff
userPaymentFen={data?.userPaymentFen}
salePriceFen={item.salePriceFen}
sharingEnabled={sharingEnabled && totalQuantity > 1}
/>
),
},
{
title: '匹配说明',
+6
View File
@@ -340,10 +340,14 @@ export type PendingPistolMatchPair = {
platformOrderId: string
productName: string
workOrderCreatedAt: string | null
/** 工单用户付款金额(分);未知为 null */
userPaymentFen?: number | null
inventoryId: number
consignmentNo: string
inventoryNo: string
itemName: string
/** 该库存售价(分):sale_price_fen 优先,缺失回退 cost_price_fen */
salePriceFen?: number
inventoryInboundAt: string | null
matchType: 'exact' | 'partial' | 'conflict'
score: number
@@ -603,5 +607,7 @@ export type ConsignmentMatchCandidatesResponse = {
/** matchable=false 时的原因文案 */
blockedReason: string
workOrderStatus: string
/** 工单用户付款金额(分);未知为 null */
userPaymentFen?: number | null
options: ConsignmentMatchCandidate[]
}
@@ -0,0 +1,54 @@
/** 分 → 元;null / 非法值返回 `-`,与后台金额展示一致。 */
export function formatFenMoney(fen: number | null | undefined): string {
if (fen === null || fen === undefined) return '-'
const value = Number(fen)
if (!Number.isFinite(value)) return '-'
return `¥${(value / 100).toFixed(2)}`
}
/** 分 → 带符号元:正数 `+`,负数 `-`,0 不带符号。 */
export function formatSignedFenMoney(fen: number): string {
const value = Math.round(Number(fen) || 0)
const sign = value > 0 ? '+' : value < 0 ? '-' : ''
return `${sign}¥${(Math.abs(value) / 100).toFixed(2)}`
}
/** 差价配色:正数绿、负数红、0 黄。 */
export const PAYMENT_PRICE_DIFF_COLOR = {
positive: '#389e0d',
negative: '#cf1322',
zero: '#d4b106',
} as const
export type PaymentPriceDiffView = {
diffFen: number
text: string
color: string
}
/**
* 用户付款金额 - 售价(分)。
*
* 拼单是多份售价,不能直接拿整单用户付款与单价相减,因此不显示差价;
* 用户付款未知时同样返回 null,由调用方只展示售价。
*/
export function resolvePaymentPriceDiff(
userPaymentFen: number | null | undefined,
salePriceFen: number | null | undefined,
options: { sharingEnabled?: boolean } = {},
): PaymentPriceDiffView | null {
if (options.sharingEnabled) return null
if (userPaymentFen === null || userPaymentFen === undefined) return null
if (salePriceFen === null || salePriceFen === undefined) return null
const payment = Number(userPaymentFen)
const price = Number(salePriceFen)
if (!Number.isFinite(payment) || !Number.isFinite(price)) return null
const diffFen = Math.round(payment) - Math.round(price)
const color =
diffFen > 0
? PAYMENT_PRICE_DIFF_COLOR.positive
: diffFen < 0
? PAYMENT_PRICE_DIFF_COLOR.negative
: PAYMENT_PRICE_DIFF_COLOR.zero
return { diffFen, text: formatSignedFenMoney(diffFen), color }
}
@@ -0,0 +1,47 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import {
formatFenMoney,
formatSignedFenMoney,
PAYMENT_PRICE_DIFF_COLOR,
resolvePaymentPriceDiff,
} from '../src/utils/consignment-payment-price-diff.ts'
test('金额展示:分转元,未知返回 -', () => {
assert.equal(formatFenMoney(11000), '¥110.00')
assert.equal(formatFenMoney(0), '¥0.00')
assert.equal(formatFenMoney(null), '-')
assert.equal(formatFenMoney(undefined), '-')
})
test('差价展示:正数带 +、负数带 -、0 不带符号', () => {
assert.equal(formatSignedFenMoney(2000), '+¥20.00')
assert.equal(formatSignedFenMoney(-2000), '-¥20.00')
assert.equal(formatSignedFenMoney(0), '¥0.00')
})
test('售价差价:用户付款 - 售价,正绿负红零黄', () => {
assert.deepEqual(resolvePaymentPriceDiff(15000, 11000), {
diffFen: 4000,
text: '+¥40.00',
color: PAYMENT_PRICE_DIFF_COLOR.positive,
})
assert.deepEqual(resolvePaymentPriceDiff(10000, 11000), {
diffFen: -1000,
text: '-¥10.00',
color: PAYMENT_PRICE_DIFF_COLOR.negative,
})
assert.deepEqual(resolvePaymentPriceDiff(11000, 11000), {
diffFen: 0,
text: '¥0.00',
color: PAYMENT_PRICE_DIFF_COLOR.zero,
})
})
test('售价差价:付款未知、售价缺失或拼单不展示', () => {
assert.equal(resolvePaymentPriceDiff(null, 11000), null)
assert.equal(resolvePaymentPriceDiff(undefined, 11000), null)
assert.equal(resolvePaymentPriceDiff(15000, undefined), null)
assert.equal(resolvePaymentPriceDiff(15000, 11000, { sharingEnabled: true }), null)
})
@@ -54,3 +54,18 @@ test('一键查询待匹配订单:默认展示全部配对并按枪型/钻石/
assert.ok(source.includes('不匹配 {data?.conflictCount ?? 0}'), '必须展示不匹配数量')
assert.ok(source.includes('默认展示全部配对,按 枪型 → 钻石 → 璀璨 排序'), '界面必须说明默认口径')
})
test('一键查询 / 手动匹配:展示工单用户付款金额与售价差价', () => {
const pending = readSource('../src/components/admin/ConsignmentPendingMatchModal.tsx')
const manual = readSource('../src/components/admin/ConsignmentWorkOrderMatchModal.tsx')
for (const source of [pending, manual]) {
assert.ok(source.includes("title: '工单用户付款金额'"), '两个弹窗都必须有用户付款金额列')
assert.ok(source.includes('ConsignmentPriceWithDiff'), '售价列必须带差价展示')
}
assert.ok(pending.includes('sharingEnabled={record.sharingEnabled}'), '拼单不展示差价')
assert.ok(
manual.includes('sharingEnabled={sharingEnabled && totalQuantity > 1}'),
'拼单不展示差价',
)
})