'use strict'; /** * 外部打单平台基础表 + 外部打单账号表。 * * - external_print_platforms:平台字典,由开发者维护(新增平台时随适配逻辑一起通过迁移写入), * 前端只读展示。fetch_waybill_no 固化「是否回打单平台取号」,取号逻辑在程序内按平台 code 选择。 * - external_print_accounts:各主体在外部打单平台上的登录账号,在前端「店铺管理 → 外部打单平台」维护, * 密码仅供服务端调用平台使用,接口不回显。 * * 平台数据由开发者按对接情况写入(示例): * INSERT INTO external_print_platforms (code, name, url, fetch_waybill_no, sort, status) * VALUES ('example', '示例平台', 'https://example.com', 1, 10, 1); * * 平台接入实现见 app/lib/printPlatform/:一个平台一个文件,文件名 = 平台 code(如 dgj.js), * 文件内的服务类 static code 需与本表 code 列一致。 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable( 'external_print_platforms', { id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, autoIncrement: true, primaryKey: true, }, code: { type: Sequelize.STRING(50), allowNull: false, comment: '平台标识,程序按此选择打单/取号适配逻辑', }, name: { type: Sequelize.STRING(100), allowNull: false, comment: '平台名称' }, url: { type: Sequelize.STRING(255), allowNull: true, comment: '平台链接地址' }, fetch_waybill_no: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 0, comment: '是否回打单平台取号:1是 0否', }, sort: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comment: '排序,越小越靠前' }, status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' }, created_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), }, updated_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), }, }, { charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '外部打单平台表(开发者维护)' } ); await queryInterface.addIndex('external_print_platforms', { fields: [ 'code' ], unique: true, name: 'uk_external_print_platforms_code', }); await queryInterface.createTable( 'external_print_accounts', { id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, autoIncrement: true, primaryKey: true, }, principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID', references: { model: 'principals', key: 'id' }, }, platform_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '所属外部打单平台ID', references: { model: 'external_print_platforms', key: 'id' }, }, account: { type: Sequelize.STRING(100), allowNull: false, comment: '外部打单平台登录账号' }, password: { type: Sequelize.STRING(255), allowNull: false, comment: '外部打单平台登录密码(服务端调用平台时使用,接口不回显)', }, created_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), }, updated_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), }, }, { charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '外部打单账号表' } ); await queryInterface.addIndex('external_print_accounts', { fields: [ 'principal_id', 'platform_id', 'account' ], unique: true, name: 'uk_external_print_accounts_principal_platform_account', }); await queryInterface.addIndex('external_print_accounts', { fields: [ 'principal_id' ], name: 'idx_external_print_accounts_principal', }); await queryInterface.addIndex('external_print_accounts', { fields: [ 'platform_id' ], name: 'idx_external_print_accounts_platform', }); }, async down(queryInterface) { await queryInterface.dropTable('external_print_accounts'); await queryInterface.dropTable('external_print_platforms'); }, };