'use strict'; /** * 外部打单平台快递接口(面单模板)模型,对应 external_print_express_interfaces 表。 * * 数据由「从平台同步数据」拉取写入;用户可为模板绑定一个快递编码(custom_code), * WMS 回读运单号时按「打单账号 + 平台 + 编码」定位唯一模板。 * * status=0 表示平台侧已不再返回该模板,记录保留用于展示失效与保留绑定。 * @param {Egg.Application} app egg application * @return {object} externalPrintExpressInterface model */ module.exports = app => { const { BIGINT, STRING, TINYINT, JSON, DATE } = app.Sequelize; const ExternalPrintExpressInterface = app.model.define('external_print_express_interface', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' }, account_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属外部打单账号ID' }, platform_type: { type: STRING(32), allowNull: false, defaultValue: '', comment: '打单平台原始平台类型' }, platform_code: { type: STRING(20), allowNull: false, defaultValue: '', comment: 'OMS 预设平台编码' }, platform_name: { type: STRING(50), comment: 'OMS 预设平台名称' }, template_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '平台面单模板ID' }, template_name: { type: STRING(128), comment: '模板名称' }, express_company_id: { type: BIGINT.UNSIGNED, comment: '平台快递公司ID' }, express_company_code: { type: STRING(50), comment: '平台快递公司编码' }, express_company_name: { type: STRING(100), comment: '平台快递公司名称' }, shop_id: { type: BIGINT.UNSIGNED, comment: '平台店铺ID' }, shop_name: { type: STRING(128), comment: '平台店铺名称' }, dbname: { type: STRING(128), comment: '拉取时使用的分区库名' }, custom_code: { type: STRING(50), comment: '绑定的快递编码(系统或自定义),回读时按账号+平台+编码定位' }, status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1有效 0失效' }, platform_updated_at: { type: DATE, comment: '平台侧更新时间' }, synced_at: { type: DATE, comment: '最近一次拉取时间' }, raw: { type: JSON, comment: '平台返回的原始结构' }, remark: { type: STRING(255), comment: '备注' }, created_at: { type: DATE, comment: '创建时间' }, updated_at: { type: DATE, comment: '更新时间' }, }, { tableName: 'external_print_express_interfaces', comment: '外部打单平台快递接口(面单模板)', }); ExternalPrintExpressInterface.associate = () => { app.model.ExternalPrintExpressInterface.belongsTo(app.model.ExternalPrintAccount, { foreignKey: 'account_id', as: 'account', }); // 自定义编码若恰好等于字典编码,可带出快递名称(仅用于展示,不参与保存校验) app.model.ExternalPrintExpressInterface.belongsTo(app.model.ExpressCompany, { foreignKey: 'custom_code', targetKey: 'code', as: 'customExpressCompany', }); }; return ExternalPrintExpressInterface; };