fix(pdd): 停止旧单刷匹配日志,并修复订单列表商品显示为 0

同步时已有工单/匹配结果未变不再写日志;列表按 Number(order_id) 挂 items,并补齐 PDD goods_name 回退与嵌套商品解析。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-09-15 12:05:02 +08:00
co-authored by Cursor
parent 2e197f93e0
commit 8e996e01fb
7 changed files with 222 additions and 43 deletions
@@ -93,7 +93,7 @@ export async function getAdminOrders(
dateTo: normalizeDateQuery(query.dateTo, true),
})
const orderIds = items.map((item) => item.id)
const orderIds = items.map((item) => Number(item.id)).filter((id) => id > 0)
const oids = items.map((item) => item.platform_order_id).filter(Boolean)
const [orderItems, tasks, vouchers] = await Promise.all([
listOrderItemsByOrderIds(orderIds),
@@ -105,23 +105,29 @@ export async function getAdminOrders(
const vouchersByOid = groupRowsByOid(vouchers)
return {
items: items.map((item) =>
mapAdminOrderListItem(item, {
orderItems: orderItemsByOrderId.get(item.id) || [],
tasks: tasksByOrderId.get(item.id) || [],
items: items.map((item) => {
const orderId = Number(item.id)
return mapAdminOrderListItem(item, {
orderItems: orderItemsByOrderId.get(orderId) || [],
tasks: tasksByOrderId.get(orderId) || [],
vouchers: vouchersByOid.get(item.platform_order_id) || [],
}),
),
})
}),
pagination: { page, pageSize, total },
}
}
function groupRowsByOrderId<T extends { order_id: number }>(rows: T[]): Map<number, T[]> {
function groupRowsByOrderId<T extends { order_id: number | string }>(rows: T[]): Map<number, T[]> {
const grouped = new Map<number, T[]>()
for (const row of rows) {
const group = grouped.get(row.order_id) || []
// pg BIGINT 常以 string 返回;统一 Number 键,避免列表挂不上 order_items →「商品 0」。
const orderId = Number(row.order_id)
if (!Number.isFinite(orderId) || orderId <= 0) {
continue
}
const group = grouped.get(orderId) || []
group.push(row)
grouped.set(row.order_id, group)
grouped.set(orderId, group)
}
return grouped
}