feat(consignment): 匹配弹窗增加付款金额与售价差价
一键查询待匹配订单与手动匹配寄卖新增「工单用户付款金额」列, 售价后括号显示「用户付款金额 - 售价」差价:正数绿、负数红、 0 黄;拼单不显示差价,付款未知显示 -。
This commit is contained in:
@@ -52,6 +52,7 @@ import {
|
||||
} from './consignment-matching-service.js'
|
||||
import { resolveOrderTemplateSpecValues } from './consignment-template-spec-service.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 {
|
||||
matchesConsignmentCategoryFamily,
|
||||
@@ -112,7 +113,7 @@ function addMinutesIso(minutes: number, now: string): string | null {
|
||||
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)))
|
||||
}
|
||||
|
||||
@@ -1703,6 +1704,8 @@ export async function listConsignmentMatchCandidatesForWorkOrder(workOrderId: nu
|
||||
matchable: availability.matchable,
|
||||
blockedReason: availability.blockedReason,
|
||||
workOrderStatus: String(workOrder.status || ''),
|
||||
/** 工单用户付款金额(分);未知为 null,供手动匹配弹窗展示 */
|
||||
userPaymentFen: resolveUserPaymentAmountFenForDisplay(workOrder),
|
||||
options,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,6 +409,42 @@ test('看板新口径:同规格同分时录单时间越早排得越靠前', ()
|
||||
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('看板新口径:同钻高璀排在低配之前', () => {
|
||||
const profile = buildProfile({
|
||||
config: { ...DEFAULT_CONSIGNMENT_PROFILE_CONFIG, specs: BUILT_IN_SPECS },
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
evaluateInventoryMatch,
|
||||
hasPositiveSpecSignal,
|
||||
inventoryMatchesProfile,
|
||||
inventorySalePriceFen,
|
||||
isRematchExcludedInventory,
|
||||
planConsignmentSharingTakes,
|
||||
resolveMatchType,
|
||||
@@ -34,6 +35,7 @@ import {
|
||||
type ConsignmentOrderSeriesInfo,
|
||||
} from './consignment-sort-priority.js'
|
||||
import { resolveCollectSubmittedFieldValues } from './work-order-material-mappers.js'
|
||||
import { resolveUserPaymentAmountFenForDisplay } from './work-order-payment-amount.js'
|
||||
import {
|
||||
matchesConsignmentCategoryScope,
|
||||
normalizeConsignmentCategoryScope,
|
||||
@@ -47,10 +49,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
|
||||
@@ -141,7 +147,7 @@ export function buildPendingPistolMatchPairs(input: {
|
||||
serverZone: fields.serverZone,
|
||||
series: fields.series,
|
||||
})
|
||||
return { order, specs }
|
||||
return { order, specs, userPaymentFen: resolveUserPaymentAmountFenForDisplay(order) }
|
||||
})
|
||||
.filter(({ order, specs }) => {
|
||||
const text = [
|
||||
@@ -172,7 +178,7 @@ export function buildPendingPistolMatchPairs(input: {
|
||||
)
|
||||
|
||||
const pairs: PendingPistolMatchPair[] = []
|
||||
for (const { order, specs } of preparedOrders) {
|
||||
for (const { order, specs, userPaymentFen } of preparedOrders) {
|
||||
const orderSeriesInfo = resolveOrderSeriesInfo({
|
||||
categoryId: order.category_id,
|
||||
productName: order.product_name,
|
||||
@@ -203,10 +209,12 @@ export function buildPendingPistolMatchPairs(input: {
|
||||
platformOrderId: String(order.platform_order_id || ''),
|
||||
productName: String(order.product_name || ''),
|
||||
workOrderCreatedAt: order.created_at ? String(order.created_at) : null,
|
||||
userPaymentFen,
|
||||
inventoryId: Number(inventory.id),
|
||||
consignmentNo: String(inventory.source_submission_no || inventory.inventory_no || ''),
|
||||
inventoryNo: String(inventory.inventory_no || ''),
|
||||
itemName: String(inventory.item_name || ''),
|
||||
salePriceFen: inventorySalePriceFen(inventory),
|
||||
inventoryInboundAt: inventory.inbound_at
|
||||
? String(inventory.inbound_at)
|
||||
: inventory.created_at
|
||||
@@ -418,6 +426,7 @@ export function buildPendingConsignmentMatchPairs(input: {
|
||||
requiredQuantity: number
|
||||
friendGift: boolean
|
||||
sharingOrder: boolean
|
||||
userPaymentFen: number | null
|
||||
orderSpecOverride: ConsignmentSpecValues | null
|
||||
orderValues: ConsignmentSpecValues
|
||||
orderSeriesInfo: ConsignmentOrderSeriesInfo
|
||||
@@ -466,6 +475,7 @@ export function buildPendingConsignmentMatchPairs(input: {
|
||||
requiredQuantity: sharingOrder ? remainingQuantity : totalQuantity,
|
||||
friendGift: isFriendGiftAcceptanceMode(order.acceptance_mode),
|
||||
sharingOrder,
|
||||
userPaymentFen: resolveUserPaymentAmountFenForDisplay(order),
|
||||
orderSpecOverride,
|
||||
orderValues,
|
||||
orderSeriesInfo,
|
||||
@@ -498,6 +508,7 @@ export function buildPendingConsignmentMatchPairs(input: {
|
||||
requiredQuantity,
|
||||
friendGift,
|
||||
sharingOrder,
|
||||
userPaymentFen,
|
||||
orderSpecOverride,
|
||||
orderValues,
|
||||
orderSeriesInfo,
|
||||
@@ -641,12 +652,14 @@ export function buildPendingConsignmentMatchPairs(input: {
|
||||
platformOrderId: String(order.platform_order_id || ''),
|
||||
productName: String(order.product_name || ''),
|
||||
workOrderCreatedAt: order.created_at ? String(order.created_at) : null,
|
||||
userPaymentFen,
|
||||
inventoryId: Number(item.inventory.id),
|
||||
consignmentNo: String(
|
||||
item.inventory.source_submission_no || item.inventory.inventory_no || '',
|
||||
),
|
||||
inventoryNo: String(item.inventory.inventory_no || ''),
|
||||
itemName: String(item.inventory.item_name || ''),
|
||||
salePriceFen: inventorySalePriceFen(item.inventory),
|
||||
inventoryInboundAt: item.inventory.inbound_at
|
||||
? String(item.inventory.inbound_at)
|
||||
: item.inventory.created_at
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
mergeUserPaymentAmountIntoMaterial,
|
||||
normalizeUserPaymentAmountFen,
|
||||
resolveDisplayedUserPaymentAmountFen,
|
||||
resolveUserPaymentAmountFenForDisplay,
|
||||
} from './work-order-payment-amount.js'
|
||||
|
||||
test('normalizeUserPaymentAmountFen:元转分并保留两位小数', () => {
|
||||
@@ -72,6 +73,23 @@ test('resolveDisplayedUserPaymentAmountFen:优先送码实付,其次来源
|
||||
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:同步两处金额并保留其它资料字段', () => {
|
||||
const merged = mergeUserPaymentAmountIntoMaterial(
|
||||
{
|
||||
|
||||
@@ -78,6 +78,17 @@ export function resolveDisplayedUserPaymentAmountFen(
|
||||
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,保持列表、详情与后续资料更新同源。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user