'use strict'; /** * 订单与订单明细增加外部打单平台(如店管家)来源字段。 * * orders: * - external_print_account_id / external_order_id:来源打单账号与平台订单号(PlatformOrderId),用于去重与回查 * - platform_type / platform_status:平台类型(TouTiao/Taobao…)与平台侧状态(ErpState) * - external_shop_id / external_shop_name:平台侧店铺(一个商家可有多个平台店铺) * - external_created_at / external_updated_at / synced_at:平台上创建、更新时间与最近同步时间 * - external_data:平台返回的订单原始结构 * * order_items: * - external_item_id:平台明细ID(OrderItemId),与订单ID一起唯一标识一条明细 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.addColumn('orders', 'external_print_account_id', { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '来源外部打单账号ID', }); await queryInterface.addColumn('orders', 'external_order_id', { type: Sequelize.STRING(64), allowNull: true, comment: '平台订单号(店管家 PlatformOrderId)', }); await queryInterface.addColumn('orders', 'platform_type', { type: Sequelize.STRING(32), allowNull: true, comment: '平台类型:TouTiao/Taobao/Pinduoduo 等', }); await queryInterface.addColumn('orders', 'platform_status', { type: Sequelize.STRING(32), allowNull: true, comment: '平台侧订单状态(如 waitsellersend)', }); await queryInterface.addColumn('orders', 'external_shop_id', { type: Sequelize.STRING(64), allowNull: true, comment: '平台侧店铺ID(店管家 ShopId)', }); await queryInterface.addColumn('orders', 'external_shop_name', { type: Sequelize.STRING(128), allowNull: true, comment: '平台侧店铺名称', }); await queryInterface.addColumn('orders', 'external_created_at', { type: Sequelize.DATE, allowNull: true, comment: '平台侧订单创建时间', }); await queryInterface.addColumn('orders', 'external_updated_at', { type: Sequelize.DATE, allowNull: true, comment: '平台侧订单更新时间', }); await queryInterface.addColumn('orders', 'synced_at', { type: Sequelize.DATE, allowNull: true, comment: '最近一次从平台同步的时间', }); await queryInterface.addColumn('orders', 'external_data', { type: Sequelize.JSON, allowNull: true, comment: '平台返回的订单原始结构', }); await queryInterface.addIndex('orders', { fields: [ 'principal_id', 'external_order_id' ], name: 'idx_orders_principal_external' }); await queryInterface.addIndex('orders', { fields: [ 'shop_id', 'external_order_id' ], name: 'idx_orders_shop_external' }); await queryInterface.addColumn('order_items', 'external_item_id', { type: Sequelize.STRING(64), allowNull: true, comment: '平台明细ID(店管家 OrderItemId)', }); await queryInterface.addIndex('order_items', { fields: [ 'order_id', 'external_item_id' ], unique: true, name: 'uk_order_items_order_external', }); }, async down(queryInterface) { await queryInterface.removeIndex('order_items', 'uk_order_items_order_external'); await queryInterface.removeColumn('order_items', 'external_item_id'); await queryInterface.removeIndex('orders', 'idx_orders_shop_external'); await queryInterface.removeIndex('orders', 'idx_orders_principal_external'); await queryInterface.removeColumn('orders', 'external_data'); await queryInterface.removeColumn('orders', 'synced_at'); await queryInterface.removeColumn('orders', 'external_updated_at'); await queryInterface.removeColumn('orders', 'external_created_at'); await queryInterface.removeColumn('orders', 'external_shop_name'); await queryInterface.removeColumn('orders', 'external_shop_id'); await queryInterface.removeColumn('orders', 'platform_status'); await queryInterface.removeColumn('orders', 'platform_type'); await queryInterface.removeColumn('orders', 'external_order_id'); await queryInterface.removeColumn('orders', 'external_print_account_id'); }, };