'use strict'; /** * 外部打单平台快递接口(面单模板)表。 * * 每个打单账号从平台拉取到的面单模板落一行,用于: * - 查看平台支持的快递接口(平台 / 店铺 / 模板 / 快递公司); * - 绑定快递编码(custom_code,系统或自定义快递编码), * WMS 回读运单号时按「打单账号 + 平台 + 编码」定位唯一模板。 * * status=0 表示平台侧已不再返回该模板:数据保留(绑定的快递编码不丢), * 前端标记为「已失效」,避免映射配置被自动清理。 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable('external_print_express_interfaces', { id: { type: Sequelize.BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键', }, principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID', }, account_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '所属外部打单账号ID(external_print_accounts)', }, platform_type: { type: Sequelize.STRING(32), allowNull: false, defaultValue: '', comment: '打单平台原始平台类型(如 Pinduoduo / TouTiao)', }, platform_code: { type: Sequelize.STRING(20), allowNull: false, defaultValue: '', comment: 'OMS 预设平台编码(如 PDD,见 app/lib/platformCode.js)', }, platform_name: { type: Sequelize.STRING(50), allowNull: true, comment: 'OMS 预设平台名称(如 拼多多)', }, template_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '平台面单模板ID(店管家 LoadTemplateListInOrderList 返回的 Id)', }, template_name: { type: Sequelize.STRING(128), allowNull: true, comment: '模板名称(如 【拼多多】韵达一联3)', }, express_company_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '平台快递公司ID', }, express_company_code: { type: Sequelize.STRING(50), allowNull: true, comment: '平台快递公司编码(如 YUNDA / STO)', }, express_company_name: { type: Sequelize.STRING(100), allowNull: true, comment: '平台快递公司名称(如 韵达)', }, shop_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '平台店铺(商家)ID', }, shop_name: { type: Sequelize.STRING(128), allowNull: true, comment: '平台店铺(商家)名称', }, dbname: { type: Sequelize.STRING(128), allowNull: true, comment: '拉取时使用的分区库名(查看明细时复用)', }, custom_code: { type: Sequelize.STRING(50), allowNull: true, comment: '绑定的快递编码(系统或自定义),回读运单号时按 账号 + 平台 + 编码 定位', }, status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1有效 0平台已不再返回(失效,保留自定义设置)', }, platform_updated_at: { type: Sequelize.DATE, allowNull: true, comment: '平台侧更新时间(模板 UpdateDate)', }, synced_at: { type: Sequelize.DATE, allowNull: true, comment: '最近一次从平台拉取到的时间', }, raw: { type: Sequelize.JSON, allowNull: true, comment: '平台返回的模板原始结构', }, remark: { type: Sequelize.STRING(255), allowNull: true, comment: '备注', }, created_at: { type: Sequelize.DATE, allowNull: true, comment: '创建时间' }, updated_at: { type: Sequelize.DATE, allowNull: true, comment: '更新时间' }, }); await queryInterface.addIndex('external_print_express_interfaces', [ 'account_id', 'template_id' ], { name: 'uk_external_print_express_template', unique: true, }); await queryInterface.addIndex('external_print_express_interfaces', [ 'principal_id', 'account_id' ], { name: 'idx_external_print_express_account', }); await queryInterface.addIndex('external_print_express_interfaces', [ 'principal_id', 'platform_code' ], { name: 'idx_external_print_express_platform', }); await queryInterface.addIndex('external_print_express_interfaces', [ 'principal_id', 'express_company_code' ], { name: 'idx_external_print_express_company', }); }, async down(queryInterface) { await queryInterface.removeIndex('external_print_express_interfaces', 'idx_external_print_express_company'); await queryInterface.removeIndex('external_print_express_interfaces', 'idx_external_print_express_platform'); await queryInterface.removeIndex('external_print_express_interfaces', 'idx_external_print_express_account'); await queryInterface.removeIndex('external_print_express_interfaces', 'uk_external_print_express_template'); await queryInterface.dropTable('external_print_express_interfaces'); }, };