feat(admin): 收口人工履约入口并修复履约筛选
This commit is contained in:
@@ -78,6 +78,12 @@ export async function listManualFulfillmentPending(
|
||||
} else if (status === 'fulfilled') {
|
||||
conditions.push('fulfilled.fulfilled_at IS NOT NULL')
|
||||
}
|
||||
// 订单页按单打开确认框:只取该订单的待办项。
|
||||
const orderId = Number(input.orderId ?? input.order_id ?? 0)
|
||||
if (Number.isFinite(orderId) && orderId > 0) {
|
||||
params.push(Math.trunc(orderId))
|
||||
conditions.push(`oi.order_id = $${params.length}`)
|
||||
}
|
||||
if (keyword) {
|
||||
params.push(`%${escapeLike(keyword)}%`)
|
||||
const placeholder = `$${params.length}`
|
||||
@@ -565,3 +571,52 @@ function optionalText(value: unknown, maxLength: number) {
|
||||
function escapeLike(value: string) {
|
||||
return value.replace(/[\\%_]/g, (char) => `\\${char}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单列表/详情用:按订单统计「可确认履约」与「未配置履约渠道」的数量。
|
||||
*
|
||||
* - pending:有人工履约配置且还没有 manual_case 快照;
|
||||
* - unconfigured:人工单但没有绑定履约配置(需要先到成本中心配 SKU)。
|
||||
*/
|
||||
export async function getManualFulfillmentCountsByOrderIds(
|
||||
orderIds: Array<number | string>,
|
||||
): Promise<Map<number, { pending: number; unconfigured: number }>> {
|
||||
const ids = orderIds.map(Number).filter((id) => Number.isFinite(id) && id > 0)
|
||||
if (ids.length === 0) return new Map()
|
||||
const result = await query<{
|
||||
order_id: number
|
||||
pending_count: number
|
||||
unconfigured_count: number
|
||||
}>(
|
||||
`
|
||||
WITH fulfilled AS (
|
||||
SELECT order_item_id, MAX(created_at) AS fulfilled_at
|
||||
FROM cost_snapshots
|
||||
WHERE subject_type = 'manual_case' AND superseded_at IS NULL
|
||||
GROUP BY order_item_id
|
||||
)
|
||||
SELECT
|
||||
oi.order_id,
|
||||
COUNT(*) FILTER (
|
||||
WHERE cfg.id IS NOT NULL AND fulfilled.fulfilled_at IS NULL
|
||||
)::int AS pending_count,
|
||||
COUNT(*) FILTER (WHERE cfg.id IS NULL)::int AS unconfigured_count
|
||||
FROM order_items oi
|
||||
LEFT JOIN manual_fulfillment_configs cfg ON cfg.id = oi.fulfillment_config_id
|
||||
LEFT JOIN fulfilled ON fulfilled.order_item_id = oi.id
|
||||
WHERE oi.order_id = ANY($1::bigint[])
|
||||
AND oi.fulfillment_mode = 'manual'
|
||||
GROUP BY oi.order_id
|
||||
`,
|
||||
[ids],
|
||||
)
|
||||
return new Map(
|
||||
result.rows.map((row) => [
|
||||
Number(row.order_id),
|
||||
{
|
||||
pending: Number(row.pending_count || 0),
|
||||
unconfigured: Number(row.unconfigured_count || 0),
|
||||
},
|
||||
]),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user