feat(consignment): 匹配弹窗增加付款金额与售价差价
一键查询待匹配订单与手动匹配寄卖新增「工单用户付款金额」列, 售价后括号显示「用户付款金额 - 售价」差价:正数绿、负数红、 0 黄;拼单不显示差价,付款未知显示 -。
This commit is contained in:
@@ -52,6 +52,7 @@ import {
|
|||||||
} from './consignment-matching-service.js'
|
} from './consignment-matching-service.js'
|
||||||
import { resolveOrderTemplateSpecValues } from './consignment-template-spec-service.js'
|
import { resolveOrderTemplateSpecValues } from './consignment-template-spec-service.js'
|
||||||
import { resolveCollectSubmittedFieldValues } from './work-order-material-mappers.js'
|
import { resolveCollectSubmittedFieldValues } from './work-order-material-mappers.js'
|
||||||
|
import { resolveUserPaymentAmountFenForDisplay } from './work-order-payment-amount.js'
|
||||||
import { recordConsignmentMatchLog } from './consignment-match-log-service.js'
|
import { recordConsignmentMatchLog } from './consignment-match-log-service.js'
|
||||||
import {
|
import {
|
||||||
matchesConsignmentCategoryFamily,
|
matchesConsignmentCategoryFamily,
|
||||||
@@ -112,7 +113,7 @@ function addMinutesIso(minutes: number, now: string): string | null {
|
|||||||
return new Date(new Date(now).getTime() + normalized * 60 * 1000).toISOString()
|
return new Date(new Date(now).getTime() + normalized * 60 * 1000).toISOString()
|
||||||
}
|
}
|
||||||
|
|
||||||
function inventorySalePriceFen(inventory: ConsignmentInventoryRow): number {
|
export function inventorySalePriceFen(inventory: ConsignmentInventoryRow): number {
|
||||||
return Math.max(0, Math.round(Number(inventory.sale_price_fen || inventory.cost_price_fen || 0)))
|
return Math.max(0, Math.round(Number(inventory.sale_price_fen || inventory.cost_price_fen || 0)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1703,6 +1704,8 @@ export async function listConsignmentMatchCandidatesForWorkOrder(workOrderId: nu
|
|||||||
matchable: availability.matchable,
|
matchable: availability.matchable,
|
||||||
blockedReason: availability.blockedReason,
|
blockedReason: availability.blockedReason,
|
||||||
workOrderStatus: String(workOrder.status || ''),
|
workOrderStatus: String(workOrder.status || ''),
|
||||||
|
/** 工单用户付款金额(分);未知为 null,供手动匹配弹窗展示 */
|
||||||
|
userPaymentFen: resolveUserPaymentAmountFenForDisplay(workOrder),
|
||||||
options,
|
options,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -409,6 +409,42 @@ test('看板新口径:同规格同分时录单时间越早排得越靠前', ()
|
|||||||
assert.equal(new Set(result.pairs.map((pair) => pair.priorityLabel)).size, 1)
|
assert.equal(new Set(result.pairs.map((pair) => pair.priorityLabel)).size, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('看板金额:带出工单用户付款金额与库存售价,付款未知为 null', () => {
|
||||||
|
const paidOrder = buildOrder({
|
||||||
|
id: 801,
|
||||||
|
material_json: JSON.stringify({ source: { orderAmountFen: 15000 } }),
|
||||||
|
})
|
||||||
|
const unknownOrder = buildOrder({
|
||||||
|
id: 802,
|
||||||
|
work_order_no: 'WK802',
|
||||||
|
material_json: JSON.stringify({}),
|
||||||
|
})
|
||||||
|
const listedInventory = buildInventory({
|
||||||
|
id: 811,
|
||||||
|
sale_price_fen: 12000,
|
||||||
|
cost_price_fen: 9000,
|
||||||
|
})
|
||||||
|
// 未单独设置售价时回退成本价,保持与手动匹配弹窗同一口径。
|
||||||
|
const fallbackInventory = buildInventory({ id: 812, cost_price_fen: 9000 })
|
||||||
|
|
||||||
|
const result = buildPendingConsignmentMatchPairs({
|
||||||
|
orders: [paidOrder, unknownOrder],
|
||||||
|
inventories: [listedInventory, fallbackInventory],
|
||||||
|
profileByOrderId: new Map([
|
||||||
|
[801, null],
|
||||||
|
[802, null],
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
|
||||||
|
const paid = result.pairs.find((pair) => pair.workOrderId === 801)
|
||||||
|
const unknown = result.pairs.find((pair) => pair.workOrderId === 802)
|
||||||
|
const fallback = result.pairs.find((pair) => pair.inventoryId === 812)
|
||||||
|
assert.equal(paid?.userPaymentFen, 15000)
|
||||||
|
assert.equal(paid?.salePriceFen, 12000)
|
||||||
|
assert.equal(unknown?.userPaymentFen, null)
|
||||||
|
assert.equal(fallback?.salePriceFen, 9000)
|
||||||
|
})
|
||||||
|
|
||||||
test('看板新口径:同钻高璀排在低配之前', () => {
|
test('看板新口径:同钻高璀排在低配之前', () => {
|
||||||
const profile = buildProfile({
|
const profile = buildProfile({
|
||||||
config: { ...DEFAULT_CONSIGNMENT_PROFILE_CONFIG, specs: BUILT_IN_SPECS },
|
config: { ...DEFAULT_CONSIGNMENT_PROFILE_CONFIG, specs: BUILT_IN_SPECS },
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
evaluateInventoryMatch,
|
evaluateInventoryMatch,
|
||||||
hasPositiveSpecSignal,
|
hasPositiveSpecSignal,
|
||||||
inventoryMatchesProfile,
|
inventoryMatchesProfile,
|
||||||
|
inventorySalePriceFen,
|
||||||
isRematchExcludedInventory,
|
isRematchExcludedInventory,
|
||||||
planConsignmentSharingTakes,
|
planConsignmentSharingTakes,
|
||||||
resolveMatchType,
|
resolveMatchType,
|
||||||
@@ -34,6 +35,7 @@ import {
|
|||||||
type ConsignmentOrderSeriesInfo,
|
type ConsignmentOrderSeriesInfo,
|
||||||
} from './consignment-sort-priority.js'
|
} from './consignment-sort-priority.js'
|
||||||
import { resolveCollectSubmittedFieldValues } from './work-order-material-mappers.js'
|
import { resolveCollectSubmittedFieldValues } from './work-order-material-mappers.js'
|
||||||
|
import { resolveUserPaymentAmountFenForDisplay } from './work-order-payment-amount.js'
|
||||||
import {
|
import {
|
||||||
matchesConsignmentCategoryScope,
|
matchesConsignmentCategoryScope,
|
||||||
normalizeConsignmentCategoryScope,
|
normalizeConsignmentCategoryScope,
|
||||||
@@ -47,10 +49,14 @@ export type PendingPistolMatchPair = {
|
|||||||
platformOrderId: string
|
platformOrderId: string
|
||||||
productName: string
|
productName: string
|
||||||
workOrderCreatedAt: string | null
|
workOrderCreatedAt: string | null
|
||||||
|
/** 工单用户付款金额(分);未知为 null */
|
||||||
|
userPaymentFen: number | null
|
||||||
inventoryId: number
|
inventoryId: number
|
||||||
consignmentNo: string
|
consignmentNo: string
|
||||||
inventoryNo: string
|
inventoryNo: string
|
||||||
itemName: string
|
itemName: string
|
||||||
|
/** 该库存售价(分):sale_price_fen 优先,缺失回退 cost_price_fen */
|
||||||
|
salePriceFen: number
|
||||||
inventoryInboundAt: string | null
|
inventoryInboundAt: string | null
|
||||||
matchType: 'exact' | 'partial' | 'conflict'
|
matchType: 'exact' | 'partial' | 'conflict'
|
||||||
score: number
|
score: number
|
||||||
@@ -141,7 +147,7 @@ export function buildPendingPistolMatchPairs(input: {
|
|||||||
serverZone: fields.serverZone,
|
serverZone: fields.serverZone,
|
||||||
series: fields.series,
|
series: fields.series,
|
||||||
})
|
})
|
||||||
return { order, specs }
|
return { order, specs, userPaymentFen: resolveUserPaymentAmountFenForDisplay(order) }
|
||||||
})
|
})
|
||||||
.filter(({ order, specs }) => {
|
.filter(({ order, specs }) => {
|
||||||
const text = [
|
const text = [
|
||||||
@@ -172,7 +178,7 @@ export function buildPendingPistolMatchPairs(input: {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const pairs: PendingPistolMatchPair[] = []
|
const pairs: PendingPistolMatchPair[] = []
|
||||||
for (const { order, specs } of preparedOrders) {
|
for (const { order, specs, userPaymentFen } of preparedOrders) {
|
||||||
const orderSeriesInfo = resolveOrderSeriesInfo({
|
const orderSeriesInfo = resolveOrderSeriesInfo({
|
||||||
categoryId: order.category_id,
|
categoryId: order.category_id,
|
||||||
productName: order.product_name,
|
productName: order.product_name,
|
||||||
@@ -203,10 +209,12 @@ export function buildPendingPistolMatchPairs(input: {
|
|||||||
platformOrderId: String(order.platform_order_id || ''),
|
platformOrderId: String(order.platform_order_id || ''),
|
||||||
productName: String(order.product_name || ''),
|
productName: String(order.product_name || ''),
|
||||||
workOrderCreatedAt: order.created_at ? String(order.created_at) : null,
|
workOrderCreatedAt: order.created_at ? String(order.created_at) : null,
|
||||||
|
userPaymentFen,
|
||||||
inventoryId: Number(inventory.id),
|
inventoryId: Number(inventory.id),
|
||||||
consignmentNo: String(inventory.source_submission_no || inventory.inventory_no || ''),
|
consignmentNo: String(inventory.source_submission_no || inventory.inventory_no || ''),
|
||||||
inventoryNo: String(inventory.inventory_no || ''),
|
inventoryNo: String(inventory.inventory_no || ''),
|
||||||
itemName: String(inventory.item_name || ''),
|
itemName: String(inventory.item_name || ''),
|
||||||
|
salePriceFen: inventorySalePriceFen(inventory),
|
||||||
inventoryInboundAt: inventory.inbound_at
|
inventoryInboundAt: inventory.inbound_at
|
||||||
? String(inventory.inbound_at)
|
? String(inventory.inbound_at)
|
||||||
: inventory.created_at
|
: inventory.created_at
|
||||||
@@ -418,6 +426,7 @@ export function buildPendingConsignmentMatchPairs(input: {
|
|||||||
requiredQuantity: number
|
requiredQuantity: number
|
||||||
friendGift: boolean
|
friendGift: boolean
|
||||||
sharingOrder: boolean
|
sharingOrder: boolean
|
||||||
|
userPaymentFen: number | null
|
||||||
orderSpecOverride: ConsignmentSpecValues | null
|
orderSpecOverride: ConsignmentSpecValues | null
|
||||||
orderValues: ConsignmentSpecValues
|
orderValues: ConsignmentSpecValues
|
||||||
orderSeriesInfo: ConsignmentOrderSeriesInfo
|
orderSeriesInfo: ConsignmentOrderSeriesInfo
|
||||||
@@ -466,6 +475,7 @@ export function buildPendingConsignmentMatchPairs(input: {
|
|||||||
requiredQuantity: sharingOrder ? remainingQuantity : totalQuantity,
|
requiredQuantity: sharingOrder ? remainingQuantity : totalQuantity,
|
||||||
friendGift: isFriendGiftAcceptanceMode(order.acceptance_mode),
|
friendGift: isFriendGiftAcceptanceMode(order.acceptance_mode),
|
||||||
sharingOrder,
|
sharingOrder,
|
||||||
|
userPaymentFen: resolveUserPaymentAmountFenForDisplay(order),
|
||||||
orderSpecOverride,
|
orderSpecOverride,
|
||||||
orderValues,
|
orderValues,
|
||||||
orderSeriesInfo,
|
orderSeriesInfo,
|
||||||
@@ -498,6 +508,7 @@ export function buildPendingConsignmentMatchPairs(input: {
|
|||||||
requiredQuantity,
|
requiredQuantity,
|
||||||
friendGift,
|
friendGift,
|
||||||
sharingOrder,
|
sharingOrder,
|
||||||
|
userPaymentFen,
|
||||||
orderSpecOverride,
|
orderSpecOverride,
|
||||||
orderValues,
|
orderValues,
|
||||||
orderSeriesInfo,
|
orderSeriesInfo,
|
||||||
@@ -641,12 +652,14 @@ export function buildPendingConsignmentMatchPairs(input: {
|
|||||||
platformOrderId: String(order.platform_order_id || ''),
|
platformOrderId: String(order.platform_order_id || ''),
|
||||||
productName: String(order.product_name || ''),
|
productName: String(order.product_name || ''),
|
||||||
workOrderCreatedAt: order.created_at ? String(order.created_at) : null,
|
workOrderCreatedAt: order.created_at ? String(order.created_at) : null,
|
||||||
|
userPaymentFen,
|
||||||
inventoryId: Number(item.inventory.id),
|
inventoryId: Number(item.inventory.id),
|
||||||
consignmentNo: String(
|
consignmentNo: String(
|
||||||
item.inventory.source_submission_no || item.inventory.inventory_no || '',
|
item.inventory.source_submission_no || item.inventory.inventory_no || '',
|
||||||
),
|
),
|
||||||
inventoryNo: String(item.inventory.inventory_no || ''),
|
inventoryNo: String(item.inventory.inventory_no || ''),
|
||||||
itemName: String(item.inventory.item_name || ''),
|
itemName: String(item.inventory.item_name || ''),
|
||||||
|
salePriceFen: inventorySalePriceFen(item.inventory),
|
||||||
inventoryInboundAt: item.inventory.inbound_at
|
inventoryInboundAt: item.inventory.inbound_at
|
||||||
? String(item.inventory.inbound_at)
|
? String(item.inventory.inbound_at)
|
||||||
: item.inventory.created_at
|
: item.inventory.created_at
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
mergeUserPaymentAmountIntoMaterial,
|
mergeUserPaymentAmountIntoMaterial,
|
||||||
normalizeUserPaymentAmountFen,
|
normalizeUserPaymentAmountFen,
|
||||||
resolveDisplayedUserPaymentAmountFen,
|
resolveDisplayedUserPaymentAmountFen,
|
||||||
|
resolveUserPaymentAmountFenForDisplay,
|
||||||
} from './work-order-payment-amount.js'
|
} from './work-order-payment-amount.js'
|
||||||
|
|
||||||
test('normalizeUserPaymentAmountFen:元转分并保留两位小数', () => {
|
test('normalizeUserPaymentAmountFen:元转分并保留两位小数', () => {
|
||||||
@@ -72,6 +73,23 @@ test('resolveDisplayedUserPaymentAmountFen:优先送码实付,其次来源
|
|||||||
assert.equal(resolveDisplayedUserPaymentAmountFen({ material_json: '{}' }), null)
|
assert.equal(resolveDisplayedUserPaymentAmountFen({ material_json: '{}' }), null)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('resolveUserPaymentAmountFenForDisplay:0 与缺失都按未知返回 null', () => {
|
||||||
|
assert.equal(
|
||||||
|
resolveUserPaymentAmountFenForDisplay({
|
||||||
|
material_json: '{}',
|
||||||
|
source_order_amount_fen: 0,
|
||||||
|
}),
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
assert.equal(resolveUserPaymentAmountFenForDisplay({ material_json: '{}' }), null)
|
||||||
|
assert.equal(
|
||||||
|
resolveUserPaymentAmountFenForDisplay({
|
||||||
|
material_json: { source: { orderAmountFen: 15000 } },
|
||||||
|
}),
|
||||||
|
15000,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('mergeUserPaymentAmountIntoMaterial:同步两处金额并保留其它资料字段', () => {
|
test('mergeUserPaymentAmountIntoMaterial:同步两处金额并保留其它资料字段', () => {
|
||||||
const merged = mergeUserPaymentAmountIntoMaterial(
|
const merged = mergeUserPaymentAmountIntoMaterial(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -78,6 +78,17 @@ export function resolveDisplayedUserPaymentAmountFen(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后台列表 / 匹配看板展示口径:0 与缺失都视为未知,避免把未知金额显示成 ¥0.00
|
||||||
|
* (前端 `getUserPaymentFen` 对派生列 0 也按未知处理)。
|
||||||
|
*/
|
||||||
|
export function resolveUserPaymentAmountFenForDisplay(
|
||||||
|
workOrder: PaymentAmountWorkOrder,
|
||||||
|
): number | null {
|
||||||
|
const amountFen = resolveDisplayedUserPaymentAmountFen(workOrder)
|
||||||
|
return amountFen !== null && amountFen > 0 ? amountFen : null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 把后台修正后的付款金额写回 material_json,保持列表、详情与后续资料更新同源。
|
* 把后台修正后的付款金额写回 material_json,保持列表、详情与后续资料更新同源。
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ import { useMemo, useState } from 'react'
|
|||||||
import PercentTable from '@/components/common/PercentTable'
|
import PercentTable from '@/components/common/PercentTable'
|
||||||
import { fetchPendingPistolMatches } from '@/services/admin/consignment'
|
import { fetchPendingPistolMatches } from '@/services/admin/consignment'
|
||||||
import type { PendingPistolMatchPair } from '@/types/consignment'
|
import type { PendingPistolMatchPair } from '@/types/consignment'
|
||||||
|
import { formatFenMoney } from '@/utils/consignment-payment-price-diff'
|
||||||
import { formatDateTime } from '@/utils/date-time'
|
import { formatDateTime } from '@/utils/date-time'
|
||||||
import { resolveConsignmentPriorityTagColor } from '@/utils/consignment-match-priority'
|
import { resolveConsignmentPriorityTagColor } from '@/utils/consignment-match-priority'
|
||||||
|
|
||||||
|
import ConsignmentPriceWithDiff from './ConsignmentPriceWithDiff'
|
||||||
import ConsignmentWorkOrderMatchModal from './ConsignmentWorkOrderMatchModal'
|
import ConsignmentWorkOrderMatchModal from './ConsignmentWorkOrderMatchModal'
|
||||||
|
|
||||||
const { Text } = Typography
|
const { Text } = Typography
|
||||||
@@ -219,6 +221,26 @@ export default function ConsignmentPendingMatchModal({
|
|||||||
</Text>
|
</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: '匹配说明',
|
title: '匹配说明',
|
||||||
key: 'reason',
|
key: 'reason',
|
||||||
@@ -285,7 +307,7 @@ export default function ConsignmentPendingMatchModal({
|
|||||||
: '匹配 · 待匹配订单 × 在库现货'
|
: '匹配 · 待匹配订单 × 在库现货'
|
||||||
}
|
}
|
||||||
open={open}
|
open={open}
|
||||||
width="min(1320px, 94vw)"
|
width="min(1480px, 96vw)"
|
||||||
footer={null}
|
footer={null}
|
||||||
destroyOnHidden
|
destroyOnHidden
|
||||||
onCancel={onClose}
|
onCancel={onClose}
|
||||||
@@ -363,7 +385,7 @@ export default function ConsignmentPendingMatchModal({
|
|||||||
loading={query.isFetching}
|
loading={query.isFetching}
|
||||||
dataSource={pairs}
|
dataSource={pairs}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
scroll={{ y: 460 }}
|
scroll={{ x: 1680, y: 460 }}
|
||||||
pagination={{
|
pagination={{
|
||||||
pageSize: 20,
|
pageSize: 20,
|
||||||
showSizeChanger: false,
|
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,
|
matchAdminConsignmentWorkOrder,
|
||||||
} from '@/services/admin/consignment'
|
} from '@/services/admin/consignment'
|
||||||
import type { ConsignmentMatchCandidate } from '@/types/consignment'
|
import type { ConsignmentMatchCandidate } from '@/types/consignment'
|
||||||
|
import { formatFenMoney } from '@/utils/consignment-payment-price-diff'
|
||||||
import {
|
import {
|
||||||
computeConsignmentMatchScore,
|
computeConsignmentMatchScore,
|
||||||
describeConsignmentMatch,
|
describeConsignmentMatch,
|
||||||
@@ -15,9 +16,7 @@ import {
|
|||||||
} from '@/utils/consignment-match-coverage'
|
} from '@/utils/consignment-match-coverage'
|
||||||
import { resolveConsignmentPriorityTagColor } from '@/utils/consignment-match-priority'
|
import { resolveConsignmentPriorityTagColor } from '@/utils/consignment-match-priority'
|
||||||
|
|
||||||
function money(fen: number) {
|
import ConsignmentPriceWithDiff from './ConsignmentPriceWithDiff'
|
||||||
return `¥${((Number(fen || 0) || 0) / 100).toFixed(2)}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const EMPTY_INVENTORY_IDS: number[] = []
|
const EMPTY_INVENTORY_IDS: number[] = []
|
||||||
|
|
||||||
@@ -205,7 +204,7 @@ export default function ConsignmentWorkOrderMatchModal({
|
|||||||
title="手动匹配寄卖"
|
title="手动匹配寄卖"
|
||||||
open={open}
|
open={open}
|
||||||
onCancel={onClose}
|
onCancel={onClose}
|
||||||
width="min(1180px, 96vw)"
|
width="min(1280px, 96vw)"
|
||||||
destroyOnHidden
|
destroyOnHidden
|
||||||
footer={
|
footer={
|
||||||
<Space>
|
<Space>
|
||||||
@@ -331,7 +330,7 @@ export default function ConsignmentWorkOrderMatchModal({
|
|||||||
size="small"
|
size="small"
|
||||||
loading={candidatesQuery.isFetching}
|
loading={candidatesQuery.isFetching}
|
||||||
pagination={{ pageSize: 10, showSizeChanger: false }}
|
pagination={{ pageSize: 10, showSizeChanger: false }}
|
||||||
scroll={{ x: 1210, y: 420 }}
|
scroll={{ x: 1470, y: 420 }}
|
||||||
dataSource={visibleOptions}
|
dataSource={visibleOptions}
|
||||||
rowSelection={{
|
rowSelection={{
|
||||||
// 整单只能选一条;拼单可多选,必须覆盖剩余份数才能提交。
|
// 整单只能选一条;拼单可多选,必须覆盖剩余份数才能提交。
|
||||||
@@ -417,11 +416,27 @@ export default function ConsignmentWorkOrderMatchModal({
|
|||||||
</Tag>
|
</Tag>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '工单用户付款金额',
|
||||||
|
key: 'userPayment',
|
||||||
|
width: 140,
|
||||||
|
render: () => (
|
||||||
|
<Typography.Text style={{ fontSize: 13 }}>
|
||||||
|
{formatFenMoney(data?.userPaymentFen)}
|
||||||
|
</Typography.Text>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '售价',
|
title: '售价',
|
||||||
key: 'price',
|
key: 'price',
|
||||||
width: 100,
|
width: 180,
|
||||||
render: (_, item) => money(item.salePriceFen),
|
render: (_, item) => (
|
||||||
|
<ConsignmentPriceWithDiff
|
||||||
|
userPaymentFen={data?.userPaymentFen}
|
||||||
|
salePriceFen={item.salePriceFen}
|
||||||
|
sharingEnabled={sharingEnabled && totalQuantity > 1}
|
||||||
|
/>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '匹配说明',
|
title: '匹配说明',
|
||||||
|
|||||||
@@ -340,10 +340,14 @@ export type PendingPistolMatchPair = {
|
|||||||
platformOrderId: string
|
platformOrderId: string
|
||||||
productName: string
|
productName: string
|
||||||
workOrderCreatedAt: string | null
|
workOrderCreatedAt: string | null
|
||||||
|
/** 工单用户付款金额(分);未知为 null */
|
||||||
|
userPaymentFen?: number | null
|
||||||
inventoryId: number
|
inventoryId: number
|
||||||
consignmentNo: string
|
consignmentNo: string
|
||||||
inventoryNo: string
|
inventoryNo: string
|
||||||
itemName: string
|
itemName: string
|
||||||
|
/** 该库存售价(分):sale_price_fen 优先,缺失回退 cost_price_fen */
|
||||||
|
salePriceFen?: number
|
||||||
inventoryInboundAt: string | null
|
inventoryInboundAt: string | null
|
||||||
matchType: 'exact' | 'partial' | 'conflict'
|
matchType: 'exact' | 'partial' | 'conflict'
|
||||||
score: number
|
score: number
|
||||||
@@ -603,5 +607,7 @@ export type ConsignmentMatchCandidatesResponse = {
|
|||||||
/** matchable=false 时的原因文案 */
|
/** matchable=false 时的原因文案 */
|
||||||
blockedReason: string
|
blockedReason: string
|
||||||
workOrderStatus: string
|
workOrderStatus: string
|
||||||
|
/** 工单用户付款金额(分);未知为 null */
|
||||||
|
userPaymentFen?: number | null
|
||||||
options: ConsignmentMatchCandidate[]
|
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('不匹配 {data?.conflictCount ?? 0}'), '必须展示不匹配数量')
|
||||||
assert.ok(source.includes('默认展示全部配对,按 枪型 → 钻石 → 璀璨 排序'), '界面必须说明默认口径')
|
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}'),
|
||||||
|
'拼单不展示差价',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user