From 5376dff3de974f83575d9cde3e7efd571129cb48 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Tue, 3 Nov 2026 18:01:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(order):=20=E5=B9=B3=E5=8F=B0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=8F=B7=E8=90=BD=E5=BA=93=20oaid=5Forder=5Fsource=5F?= =?UTF-8?q?code=20=E5=B9=B6=E5=9C=A8=E8=AE=A2=E5=8D=95=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 拉单写入状态表时,把店管家「订单编号」(PlatformOrderId)落 oaid_order_source_code (来源订单号仍是平台「系统编号」),随单推 WMS 的 deliveryOrder.oaidOrderSourceCode - 新增迁移 20261103000300:把历史行 extend_props.platform_order_no 回填到 oaid_order_source_code(已执行:pending 17 条 / void 12 条) - 订单列表新增「平台订单号」列(手工单显示 -),订单详情、导出列同步使用该字段 - 前端 OrderStatusItem 补充 oaid_order_source_code 类型 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- backend/app/service/externalPrintOrder.js | 2 + backend/app/utils/exportDefs.js | 1 + ...261103000300-backfill-platform-order-no.js | 40 +++++++++++++++++++ frontend/src/api/orderStatus.ts | 2 + frontend/src/views/Order/StatusPanel.vue | 11 ++++- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 backend/database/migrations/20261103000300-backfill-platform-order-no.js diff --git a/backend/app/service/externalPrintOrder.js b/backend/app/service/externalPrintOrder.js index 76f575d..4c18a6b 100644 --- a/backend/app/service/externalPrintOrder.js +++ b/backend/app/service/externalPrintOrder.js @@ -367,6 +367,8 @@ class ExternalPrintOrderService extends Service { // 系统预设平台编码/名称(推 WMS 的 sourcePlatformCode/sourcePlatformName 同源) source_platform_code: truncateText(item.platform_code || item.platform_type, 50), source_platform_name: truncateText(item.platform_name || item.platform_type, 200), + // 来源订单号用的是平台「系统编号」,平台自己的「订单编号」落在这里随单推给 WMS + oaid_order_source_code: item.platform_order_no ? truncateText(item.platform_order_no, 50) : null, buyer_message: truncateText(item.remark, 500), place_order_time: item.external_created_at, pay_time: item.external_updated_at, diff --git a/backend/app/utils/exportDefs.js b/backend/app/utils/exportDefs.js index 2351607..29788eb 100644 --- a/backend/app/utils/exportDefs.js +++ b/backend/app/utils/exportDefs.js @@ -234,6 +234,7 @@ const ORDER_COLUMNS = [ { key: 'id', header: 'ID' }, { key: 'order_no', header: '订单号' }, { key: 'parent_order_no', header: '来源订单号' }, + { key: 'oaid_order_source_code', header: '平台订单号' }, { key: 'status', header: '状态', format: labels(ORDER_STATUS_LABELS) }, { key: 'order_type', header: '订单类型' }, { key: 'shop_id', header: '店铺ID' }, diff --git a/backend/database/migrations/20261103000300-backfill-platform-order-no.js b/backend/database/migrations/20261103000300-backfill-platform-order-no.js new file mode 100644 index 0000000..5508887 --- /dev/null +++ b/backend/database/migrations/20261103000300-backfill-platform-order-no.js @@ -0,0 +1,40 @@ +'use strict'; + +/** + * 外部打单平台订单:把平台「订单编号」(PlatformOrderId)回填到 oaid_order_source_code。 + * + * 背景:来源订单号(order_index.parent_order_no)已改用店管家「系统编号」LogicOrderId, + * 平台自己的「订单编号」只存在 extend_props.platform_order_no 里;该值需要随单推给 WMS, + * 因此统一落到 oaid_order_source_code(推单时映射为 deliveryOrder.oaidOrderSourceCode)。 + * + * 只回填 oaid_order_source_code 为空、且 extend_props 里带 platform_order_no 的行, + * 手工单(无 extend_props.platform_order_no)不受影响。 + */ +const STATUS_TABLES = [ + 'order_status_pending', + 'order_status_queued', + 'order_status_exception', + 'order_status_outsourcing', + 'order_status_delivery', + 'order_status_void', + 'order_status_canceled', + 'order_status_history', +]; + +module.exports = { + async up(queryInterface) { + for (const table of STATUS_TABLES) { + await queryInterface.sequelize.query( + `UPDATE \`${table}\` + SET oaid_order_source_code = JSON_UNQUOTE(JSON_EXTRACT(extend_props, '$.platform_order_no')) + WHERE oaid_order_source_code IS NULL + AND extend_props IS NOT NULL + AND JSON_EXTRACT(extend_props, '$.platform_order_no') IS NOT NULL` + ); + } + }, + + async down() { + // 数据回填不做回滚(回滚会丢掉平台单号,且不影响表结构) + }, +}; diff --git a/frontend/src/api/orderStatus.ts b/frontend/src/api/orderStatus.ts index 1bf9306..cfbbe33 100644 --- a/frontend/src/api/orderStatus.ts +++ b/frontend/src/api/orderStatus.ts @@ -101,6 +101,8 @@ export interface OrderStatusItem { source_platform_code?: string | null /** 来源平台名称(如「拼多多」) */ source_platform_name?: string | null + /** 平台自己的订单编号(店管家「订单编号」,来源订单号用的是其「系统编号」) */ + oaid_order_source_code?: string | null remark: string | null /** —— 老发货单口径字段(为容纳老表而扩展) —— */ order_type?: string | null diff --git a/frontend/src/views/Order/StatusPanel.vue b/frontend/src/views/Order/StatusPanel.vue index ba92e0a..ba061a0 100644 --- a/frontend/src/views/Order/StatusPanel.vue +++ b/frontend/src/views/Order/StatusPanel.vue @@ -548,9 +548,13 @@ function fmtNum(value: unknown): string { return Number.isFinite(num) ? String(Number(num.toFixed(2))) : String(value) } -/** 外部打单平台订单的平台单号(店管家「订单编号」,来源订单号用的是其「系统编号」) */ +/** 外部打单平台订单的平台单号(店管家「订单编号」;来源订单号用的是其「系统编号」) */ function platformOrderNoOf(row: Record | null): string { - const props = row && (row.extend_props as Record | null) + if (!row) return '' + // 现在落库在 oaid_order_source_code(随单推给 WMS),老数据回退到 extend_props + const direct = row.oaid_order_source_code + if (typeof direct === 'string' && direct) return direct + const props = row.extend_props as Record | null const value = props && props.platform_order_no return typeof value === 'string' ? value : '' } @@ -706,6 +710,9 @@ onMounted(async () => { + + +