'use strict'; /** * 订单自定义店铺-快递绑定策略模型。 * * 支持在仓库维度下,为用户自定义店铺标签配置快递绑定策略, * 按优先级匹配,可附加商品、地区、重量等条件。 * * @param {import('egg').Application} app Egg 应用实例。 * @return {import('sequelize').ModelCtor} Sequelize 模型。 */ module.exports = app => { const { BIGINT, STRING, INTEGER, TINYINT, DATE, TEXT, JSON: JSON_TYPE } = app.Sequelize; const StoreExpressBindingPolicy = app.model.define('store_express_binding_policy', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID', }, warehouse_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '仓库ID,策略所属仓库', }, custom_name: { type: STRING(100), allowNull: false, comment: '策略名称,便于人工识别', }, shop_name: { type: JSON_TYPE, allowNull: true, comment: '包含店铺名称,字符串数组,如["旗舰店","奥莱店"],NULL=不限制', }, store_ids: { type: JSON_TYPE, allowNull: true, comment: '限定货主ID,数字数组,如[1000000,1000001],NULL=不限制', }, express_code: { type: STRING(50), allowNull: false, comment: '绑定的快递编码(wms_express.code)', }, priority: { type: INTEGER(11), allowNull: false, defaultValue: 0, comment: '优先级,数值越大越优先匹配', }, is_enabled: { type: TINYINT(1), allowNull: false, defaultValue: 1, validate: { isIn: { args: [[ 0, 1 ]], msg: '启用状态不合法,0=停用,1=启用', }, }, comment: '是否启用:0=停用,1=启用', }, regions: { type: JSON_TYPE, allowNull: true, comment: '限定地区,字符串数组,如["广东省","广州市"],NULL=不限制', }, exclude_regions: { type: JSON_TYPE, allowNull: true, comment: '排除地区,字符串数组,如["新疆维吾尔自治区"],NULL=不排除', }, min_weight_g: { type: INTEGER, allowNull: true, comment: '最小重量(克),NULL=不限制', }, max_weight_g: { type: INTEGER, allowNull: true, comment: '最大重量(克),NULL=不限制', }, weight_type: { type: TINYINT(1), allowNull: false, defaultValue: 0, validate: { isIn: { args: [[ 0, 1, 2, 3 ]], msg: '重量类型不合法,0=常规/1=轻货/2=重货/3=冷链' } }, comment: '重量段类型:0=常规/1=轻货/2=重货/3=冷链', }, prohibited_type_id: { type: JSON_TYPE, allowNull: true, comment: '违禁品类型ID数组(关联 wms_prohibited_type.id),如[1,2],NULL=不限制违禁品', }, remark: { type: STRING(500), allowNull: true, comment: '备注说明', }, creator_id: { type: BIGINT.UNSIGNED, allowNull: true, comment: '创建人账户ID(accounts.id)', }, created_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '创建时间', }, updated_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '更新时间', }, deleted_at: { type: DATE, allowNull: true, comment: '软删除时间', }, }, { tableName: 'wms_store_express_binding_policy', freezeTableName: true, underscored: true, timestamps: false, comment: '订单自定义店铺-快递绑定策略表', indexes: [ { name: 'idx_warehouse_enabled', fields: [ 'warehouse_id', 'is_enabled', 'deleted_at' ], }, { name: 'idx_warehouse_express', fields: [ 'warehouse_id', 'express_code', 'deleted_at' ], }, ], }); return StoreExpressBindingPolicy; };