修复(寄卖): 恢复待抢单手枪简单匹配看板

This commit is contained in:
yml
2026-11-18 20:39:27 +08:00
parent 97a98ac162
commit d521c6b259
9 changed files with 233 additions and 277 deletions
@@ -43,7 +43,10 @@ import {
listInventoryMatchableOrders,
listWorkOrderInventoryMatchOptions,
} from '../../../services/worker-platform/consignment-fulfillment-service.js'
import { listPendingConsignmentMatches } from '../../../services/worker-platform/consignment-pending-match-service.js'
import {
listPendingConsignmentMatches,
listPendingSuernanPistolMatches,
} from '../../../services/worker-platform/consignment-pending-match-service.js'
import { listConsignmentMatchLogs } from '../../../services/worker-platform/consignment-match-log-service.js'
import { buildTemplateSpecProposalForCategory } from '../../../services/worker-platform/consignment-template-spec-service.js'
import {
@@ -405,7 +408,26 @@ router.post(
// ---------------- 匹配与履约 ----------------
// 全局待抢单匹配看板:按寄卖配置匹配待抢单工单 × 在库待匹配现货,只读。
// 一键查询待匹配订单:恢复为简单只读的待抢单苏尔南手枪看板。
router.get(
'/worker-platform/consignment/pending-suernan-pistol-matches',
requireAdminPermission('consignment.view'),
createJsonHandler(
(req) =>
listPendingSuernanPistolMatches({
keyword: String(req.query.keyword || ''),
includeConflicts: String(req.query.includeConflicts || '') === 'true',
limit: Number(req.query.limit || 0) || undefined,
}),
{
successMessage: 'ok',
errorMessage: '读取待匹配手枪订单失败',
scope: '[admin/consignment/pending-suernan-pistol-matches]',
},
),
)
// 库存侧手动匹配候选:按完整寄卖配置匹配待抢单工单 × 在库待匹配现货,只读。
router.get(
'/worker-platform/consignment/pending-pistol-matches',
requireAdminPermission('consignment.view'),
@@ -245,6 +245,18 @@ test('匹配看板:按分数降序,同分录单时间早的优先', () => {
)
})
test('匹配看板:在库待匹配件数按剩余数量统计,不按库存行数统计', () => {
const result = buildPendingPistolMatchPairs({
orders: [buildOrder()],
inventories: [
buildInventory({ id: 10, quantity: 3, remaining_quantity: 2 }),
buildInventory({ id: 11, quantity: 5, remaining_quantity: 4 }),
],
})
assert.equal(result.inStockInventoryCount, 6)
})
const BUILT_IN_SPECS = [
['system', '操作系统', 10],
['serverZone', '游戏区服', 20],
@@ -49,25 +49,15 @@ 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
reason: string
conflicts: string[]
/** 枪型 → 钻石 → 璀璨 的排序层级文案 */
priorityLabel: string
seriesMatched: boolean
seriesSpecified: boolean
diamondGap: number
brillianceGap: number
}
export type PendingPistolMatchResult = {
@@ -147,7 +137,7 @@ export function buildPendingPistolMatchPairs(input: {
serverZone: fields.serverZone,
series: fields.series,
})
return { order, specs, userPaymentFen: resolveUserPaymentAmountFenForDisplay(order) }
return { order, specs }
})
.filter(({ order, specs }) => {
const text = [
@@ -161,6 +151,7 @@ export function buildPendingPistolMatchPairs(input: {
const preparedInventories = input.inventories.filter((inventory) => {
if (inventory.status !== 'in_stock' || inventory.allow_matching !== true) return false
if (Number(inventory.remaining_quantity ?? 1) <= 0) return false
return (
detectItemCategory(
`${inventory.item_name} ${inventory.series || ''} ${inventory.category_name || ''}`,
@@ -178,30 +169,10 @@ export function buildPendingPistolMatchPairs(input: {
)
const pairs: PendingPistolMatchPair[] = []
for (const { order, specs, userPaymentFen } of preparedOrders) {
const orderSeriesInfo = resolveOrderSeriesInfo({
categoryId: order.category_id,
productName: order.product_name,
parsedSeries: String(specs.series || ''),
})
for (const { order, specs } of preparedOrders) {
for (const inventory of preparedInventories) {
const inventorySpecValues = resolveConsignmentInventorySpecValues(inventory)
if (isCrossSeriesInventory(orderSeriesInfo, String(inventorySpecValues.series || ''))) {
continue
}
const scored = scoreConsignmentMatchDetails(specs, inventory)
if (scored.matchType === 'conflict' && !includeConflicts) continue
const priority = resolveConsignmentMatchPriorityFromSpecs({
orderValues: {
series: orderSeriesInfo.series,
diamondLevel: specs.diamondLevel,
brillianceCount: specs.brillianceCount,
},
inventoryValues: inventorySpecValues,
orderSeriesInfo,
exact: scored.matchType === 'exact',
fallbackConflict: scored.matchType === 'conflict',
})
const pair: PendingPistolMatchPair = {
workOrderId: Number(order.id),
@@ -209,12 +180,10 @@ 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
@@ -224,11 +193,6 @@ export function buildPendingPistolMatchPairs(input: {
score: scored.score,
reason: scored.reason,
conflicts: scored.conflicts,
priorityLabel: priority.priorityLabel,
seriesMatched: priority.seriesMatched,
seriesSpecified: priority.seriesSpecified,
diamondGap: priority.diamondGap,
brillianceGap: priority.brillianceGap,
}
if (keyword && !buildPairHaystack(pair).includes(keyword)) continue
@@ -253,7 +217,10 @@ export function buildPendingPistolMatchPairs(input: {
return {
pendingOrderCount: preparedOrders.length,
inStockInventoryCount: preparedInventories.length,
inStockInventoryCount: preparedInventories.reduce(
(sum, inventory) => sum + Math.max(0, Number(inventory.remaining_quantity ?? 1)),
0,
),
pairCount: pairs.length,
exactCount,
partialCount,
@@ -263,6 +230,64 @@ export function buildPendingPistolMatchPairs(input: {
}
}
/**
* 旧版「待抢单手枪匹配」查询:完整读取全部 open 工单,不再只取最近 500 单。
* 看板本身仍是只读工具,不参与自动匹配或工单状态修改。
*/
async function listAllOpenWorkOrdersForPistolBoard(): Promise<WorkOrderRow[]> {
const pageSize = OPEN_ORDER_FETCH_LIMIT
const items: WorkOrderRow[] = []
let page = 1
let total = 0
do {
const result = await listWorkOrders({
statuses: [WORK_ORDER_STATUS.OPEN],
page,
pageSize,
includeTotal: true,
sort: 'id_desc',
})
total = result.total
items.push(...result.items)
if (result.items.length === 0) break
page += 1
} while (items.length < total)
return items
}
/**
* 后台「寄售仓库 → 一键查询待匹配订单」的简单版。
*
* 固定口径:
* - 只查非拼单 open 工单;
* - 只查苏尔南手枪 × 在库手枪;
* - 使用内置五字段固定权重评分;
* - 默认隐藏冲突,允许操作者显式查看;
* - 查询全部 open 工单后再过滤,避免关键字只能命中最近一页。
*/
export async function listPendingSuernanPistolMatches(
input: {
keyword?: string | undefined
includeConflicts?: boolean | undefined
limit?: number | undefined
} = {},
): Promise<PendingPistolMatchResult> {
const [orders, inventories] = await Promise.all([
listAllOpenWorkOrdersForPistolBoard(),
listActiveConsignmentInventoriesForMatching(),
])
return buildPendingPistolMatchPairs({
orders,
inventories,
keyword: input.keyword,
includeConflicts: input.includeConflicts,
limit: input.limit,
})
}
export type PendingConsignmentMatchDetail = {
key: string
label: string
@@ -273,6 +298,16 @@ export type PendingConsignmentMatchDetail = {
/** 看板配对:在旧字段基础上补充规格明细、订单剩余数量与命中的寄卖配置。 */
export type PendingConsignmentMatchPair = PendingPistolMatchPair & {
/** 工单用户付款金额(分);未知为 null */
userPaymentFen: number | null
/** 该库存售价(分):sale_price_fen 优先,缺失回退 cost_price_fen */
salePriceFen: number
/** 枪型 → 钻石 → 璀璨的排序层级文案 */
priorityLabel: string
seriesMatched: boolean
seriesSpecified: boolean
diamondGap: number
brillianceGap: number
matchDetails: PendingConsignmentMatchDetail[]
remainingQuantity: number
totalQuantity: number