oms/backend/database/migrations/20261107010000-backfill-order-platform-for-database-and-handmade.js
liufumingren ba0d03414a feat(order): 电商平台筛选可遍历实际平台,数据库店铺与手工单默认淘宝
- 订单筛选项新增 platforms:系统预设 ∪ 当前主体订单里实际出现过的编码(带数量,
  未收录进预设的标记 preset=false),下拉按用量排序,店管家新增平台类型时不会「筛不到」
- 手工单默认 source_platform_code=TB(淘宝),新建/编辑弹窗新增「电商平台」下拉;
  编辑改平台时按系统预设同步名称;外部打单平台拉取的订单该字段置灰不可改
- 数据库店铺拉单按店铺配置的平台落库(未配置时默认淘宝),待审核订单可见可筛
- 迁移 20261107010000:把「数据库店铺订单(extend_props.source=shop_database)」与
  「手工单(extend_props.labels 含手工单)」里为空的电商平台回填为 TB/淘宝

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 01:18:21 +08:00

52 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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;
},
};