oms/backend/database/migrations/20261102000600-shop-db-mode-fields.js
liufumingren ab630e7c01 feat(external-print): 订单拉取与定时同步,组合商品拆分为最小单位
后端能力:
- 接入店管家订单接口(/NewOrder/List),明细归一化后按店铺商品匹配系统商品/组合商品
- 新增 service/externalPrintOrder:手动与定时拉单共用入库逻辑,同时写入待审核状态分表
- 新增 schedule/fetchExternalShopOrders:按店铺配置的间隔自动拉单(最小 3 分钟,起点重叠 10 分钟)
- 新增 lib/orderItemExpand + service/orderItemResolve:平台行与最小单位行互转;
  绑定组合商品时按「数量 = 平台数量 x 组合内数量、单价取子商品零售价」拆成子商品行,解绑可还原
- 明细新增 platform_snapshot,保留平台原样(编码/名称/规格/图片/原行号/原数量/原单价)
- 店铺商品列表支持 has_unbound_order 筛选,订单列表支持 exclude_unbound(均已同步导出定义)
- 店铺商品只读化:移除新增/编辑/删除动作,仅保留查询与绑定;
  同步商品时平台已不存在的商品自动清理(未绑定且未被订单引用直接删除,已绑定或被引用仅下架)
- 新增 scripts/rebuild-order-items 存量明细重建脚本,新增 orderItemExpand 单测(8 项)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-03 03:29:09 +08:00

70 lines
2.6 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';
/**
* 修正「数据库模式」语义:它是店铺的一种类型(预约),
* 用于店铺配置自己的数据库账号密码以自动取单,与外部打单平台无关。
*
* - 删除此前误加的 db_mode(曾用于存平台分区标识;平台原始结构仍保留在 external_data 中)
* - 新增数据库连接配置字段(type=3 数据库模式店铺使用,具体逻辑后续实现)
* - type 注释补充 3=数据库模式(预留)
*/
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.removeColumn('shops', 'db_mode');
await queryInterface.addColumn('shops', 'db_host', {
type: Sequelize.STRING(255),
allowNull: true,
comment: '数据库地址(type=3 数据库模式店铺使用,预留)',
});
await queryInterface.addColumn('shops', 'db_port', {
type: Sequelize.INTEGER,
allowNull: true,
comment: '数据库端口(type=3 数据库模式店铺使用,预留)',
});
await queryInterface.addColumn('shops', 'db_name', {
type: Sequelize.STRING(100),
allowNull: true,
comment: '数据库名(type=3 数据库模式店铺使用,预留)',
});
await queryInterface.addColumn('shops', 'db_username', {
type: Sequelize.STRING(100),
allowNull: true,
comment: '数据库账号(type=3 数据库模式店铺使用,预留)',
});
await queryInterface.addColumn('shops', 'db_password', {
type: Sequelize.STRING(255),
allowNull: true,
comment: '数据库密码(type=3 数据库模式店铺使用,预留,接口不回显)',
});
await queryInterface.changeColumn('shops', 'type', {
type: Sequelize.TINYINT,
allowNull: false,
defaultValue: 1,
comment: '店铺类型:1平台店铺 2外部打单平台商家 3数据库模式(预留)',
});
},
async down(queryInterface, Sequelize) {
await queryInterface.removeColumn('shops', 'db_password');
await queryInterface.removeColumn('shops', 'db_username');
await queryInterface.removeColumn('shops', 'db_name');
await queryInterface.removeColumn('shops', 'db_port');
await queryInterface.removeColumn('shops', 'db_host');
await queryInterface.addColumn('shops', 'db_mode', {
type: Sequelize.STRING(50),
allowNull: true,
comment: '数据库模式(预留,后续分区/多库逻辑使用)',
});
await queryInterface.changeColumn('shops', 'type', {
type: Sequelize.TINYINT,
allowNull: false,
defaultValue: 1,
comment: '店铺类型:1平台店铺 2外部打单平台商家',
});
},
};