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 () => { + + +