'use strict'; /** * 定义快递接口配置模型。 * @param {Object} app Egg 应用对象。 * @return {Object} 快递接口配置模型。 */ module.exports = app => { const { INTEGER, STRING, BIGINT, TINYINT, JSON } = app.Sequelize; const ExpressInterface = app.model.define('express_interface', { id: { type: INTEGER(11).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID', }, name: { type: STRING(255), allowNull: true, comment: '接口名称', }, express_code: { type: STRING(255), allowNull: false, comment: '快递编码', }, platform_code: { type: STRING(50), allowNull: false, comment: '平台编码', }, sys_express_code: { type: STRING(50), allowNull: false, comment: '系统快递编码', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '仓库编码', }, shop_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '店铺ID', }, platform_shop_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '平台店铺ID', }, template_id: { type: STRING(50), allowNull: true, comment: '模板ID', }, paymode: { type: INTEGER(11), allowNull: true, comment: '付款方式', }, brandno: { type: STRING(255), allowNull: true, comment: '品牌编码', }, providertype: { type: STRING(50), allowNull: true, comment: '服务商类型编码', }, providerid: { type: INTEGER(11), allowNull: true, comment: '服务商ID', }, sender_name: { type: STRING(50), allowNull: true, comment: '寄件人', }, sender_tel: { type: STRING(11), allowNull: true, comment: '寄件电话', }, weight: { type: INTEGER(11), allowNull: true, comment: '排序', }, token: { type: STRING(500), allowNull: true, comment: '令牌', }, viewer: { type: STRING(50), allowNull: true, comment: '验视员', }, client_id: { type: STRING(50), allowNull: true, comment: '客户id', }, is_share: { type: TINYINT(1), allowNull: true, defaultValue: 0, comment: '是否分享接口', }, share_id: { type: INTEGER(11).UNSIGNED, allowNull: true, comment: '分享id', }, can_use_count: { type: INTEGER(11), allowNull: true, defaultValue: 0, comment: '可用数量', }, province_name: { type: STRING(255), allowNull: true, comment: '寄件人名称', }, city_name: { type: STRING(255), allowNull: true, comment: '寄件人城市', }, district_name: { type: STRING(255), allowNull: true, comment: '寄件人区/县', }, site_code: { type: STRING(255), allowNull: true, comment: '网点编码', }, product_type: { type: STRING(50), allowNull: true, comment: '产品编码', }, weight_type: { type: INTEGER(10), allowNull: true, comment: '重量类型', }, shop_name: { type: STRING(255), allowNull: true, comment: '平台店铺', }, address: { type: STRING(255), allowNull: true, comment: '地址', }, town_name: { type: STRING(255), allowNull: true, comment: '寄件人街道', }, ispickup: { type: TINYINT(1), allowNull: true, defaultValue: 0, comment: '是否上门取件', }, is_hide_goods: { type: TINYINT(1), allowNull: true, defaultValue: 0, comment: '是否隐藏物品信息', }, is_enabled: { type: TINYINT(1), allowNull: true, defaultValue: 1, comment: '是否启用(1=启用,0=停用)', }, shipperno: { type: STRING(255), allowNull: true, comment: '寄件网点编码', }, template_url: { type: STRING(500), allowNull: true, comment: '打印模板链接', }, ext_data: { type: JSON, allowNull: true, comment: '扩展信息', }, }, { tableName: 'wms_express_interface', freezeTableName: true, underscored: true, timestamps: false, paranoid: false, comment: '快递接口配置表', indexes: [ { name: 'idx_warehouse_id', fields: [ 'warehouse_id' ], }, ], }); /** * 定义快递接口与系统快递、店铺、打印平台的关联关系。 * * 说明: * - `wms_express_interface.sys_express_code` 对应 `wms_express.code` * - `wms_express_interface.shop_id` 对应 `wms_shops.id` * - `wms_express_interface.platform_code` 对应 `wms_print_platform.platform_code` */ ExpressInterface.associate = function() { const { Express, Shop, PrintPlatform } = app.model; if (Express && typeof ExpressInterface.belongsTo === 'function') { ExpressInterface.belongsTo(Express, { foreignKey: 'sys_express_code', targetKey: 'code', as: 'express', constraints: false, }); } if (Shop && typeof ExpressInterface.belongsTo === 'function') { ExpressInterface.belongsTo(Shop, { foreignKey: 'shop_id', targetKey: 'id', as: 'shop', constraints: false, }); } if (PrintPlatform && typeof ExpressInterface.belongsTo === 'function') { ExpressInterface.belongsTo(PrintPlatform, { foreignKey: 'platform_code', targetKey: 'platform_code', as: 'printPlatform', constraints: false, }); } }; return ExpressInterface; };