'use strict'; /** * 回填「数据库店铺拉取的订单」与「手工单」的电商平台(淘宝)。 * * 背景:订单页新增「电商平台」列与筛选后,这两类订单的 source_platform_code/name 一直是空, * 列表只能显示 '-'、按平台也筛不出来。口径调整为: * - 数据库店铺(type=3)拉单:没有平台回传,按店铺配置的平台,未配置时按淘宝; * - 手工单:默认淘宝。 * 这里只回填「当前为空」的历史行,已有值的(外部打单平台订单)不动。 */ /** 订单状态表(与 app/lib/orderStatus.js 的 ORDER_STATUS 对齐) */ 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', ]; /** 回填口径:数据库店铺拉取的订单 + 手工建单 */ const BACKFILL_WHERE = "WHERE (source_platform_code IS NULL OR source_platform_code = '') " + "AND (JSON_UNQUOTE(JSON_EXTRACT(extend_props, '$.source')) = 'shop_database' " + "OR JSON_UNQUOTE(JSON_EXTRACT(extend_props, '$.labels')) LIKE '%手工单%')"; module.exports = { async up(queryInterface) { const transaction = await queryInterface.sequelize.transaction(); try { for (const table of STATUS_TABLES) { await queryInterface.sequelize.query( `UPDATE \`${table}\` SET source_platform_code = 'TB', source_platform_name = '淘宝' ${BACKFILL_WHERE}`, { transaction } ); } await transaction.commit(); } catch (err) { await transaction.rollback(); throw err; } }, // 回填属数据修正:撤销会重新让这两类订单失去平台信息,故不做反向操作 async down() { return undefined; }, };