【新增模块】 - app/model/store_express_binding_policy.js: 策略数据模型(17字段,JSON数组) - app/service/systems/store_express_binding_policy.js: CRUD+列表(含名称批量解析) - app/service/systems/express_policy.js: 缓存优先策略查询 + 6维漏斗匹配引擎 - app/service/systemMethods/store_express_binding_policy.js: method路由层 - database/designs/store-express-binding-policy-design.md: 设计文档 【策略漏斗匹配逻辑】 - 按priority DESC逐条匹配: store_ids→shop_name→prohibited→regions→exclude→weight - NULL/空数组=不限, 未命中自动continue到下一条 - 地区/店铺匹配使用子串包含(省/市/区/详细地址均生效) - 违禁品匹配使用数组交集 - 输出快递编码+重量类型, 未命中返回null 【订单创建链路集成】 - addOrder→addOrderLines后触发matchPolicy(weight可用) - 命中: 写入logistics/sys_logistics 4字段+weight_type+操作日志 - 未命中: 降级到resolveExpressSnapshot默认值+兜底DEFAULT_STORE_SUBJECT_CONFIG(STO) - 系统快递4字段一致, 自定义映射(express_setting)分流写入 【运单号分配优化】 - pickWaybillExpressInterface两步兜底: Step1: logistics_code仅匹配express_code(自定义编码精确) Step2: sys_logistics_code匹配全候选码(系统编码兜底) - 新增weight_type过滤器(接口NULL=通配, 设限须精确匹配) - groupedOrder.options新增sys_logistics_code/weight_type传递 【操作码翻译】 - ORDER_EXPRESS_POLICY_MATCH: '策略命中' - ORDER_EXPRESS_FALLBACK: '快递降级' - 无策略命中时写入快递降级日志 【API文档】 - methods/system.json: 策略模块4接口+响应字段(express_name/数组类型等) 【数据库迁移】 - 13个migration: 建表→字段迭代→TEXT改JSON→prohibited改数组(dev+prod均执行)
130 lines
4.0 KiB
JavaScript
130 lines
4.0 KiB
JavaScript
'use strict';
|
||
|
||
const TABLE_NAME = 'wms_store_express_binding_policy';
|
||
|
||
module.exports = {
|
||
/**
|
||
* 创建订单自定义店铺-快递绑定策略表。
|
||
* @param {Object} queryInterface Sequelize QueryInterface 实例。
|
||
* @param {Object} Sequelize Sequelize 类。
|
||
* @return {Promise<void>} 迁移执行结果。
|
||
*/
|
||
up: async (queryInterface, Sequelize) => {
|
||
const tables = await queryInterface.showAllTables();
|
||
const exists = tables.some(t => (typeof t === 'string' ? t : t.tableName) === TABLE_NAME);
|
||
if (exists) return;
|
||
|
||
await queryInterface.createTable(TABLE_NAME, {
|
||
id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '仓库ID,策略所属仓库',
|
||
},
|
||
custom_name: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: false,
|
||
comment: '自定义策略名称,便于人工识别',
|
||
},
|
||
store_id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
comment: '货主ID(stores.id),NULL=适用所有货主',
|
||
},
|
||
shop_id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
comment: '店铺ID(shops.id),NULL=适用所有店铺',
|
||
},
|
||
express_code: {
|
||
type: Sequelize.STRING(50),
|
||
allowNull: false,
|
||
comment: '绑定的快递编码(wms_express.code)',
|
||
},
|
||
priority: {
|
||
type: Sequelize.INTEGER(11),
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '优先级,数值越大越优先匹配',
|
||
},
|
||
is_enabled: {
|
||
type: Sequelize.TINYINT(1),
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '是否启用:0=停用,1=启用',
|
||
},
|
||
match_condition: {
|
||
type: Sequelize.JSON,
|
||
allowNull: true,
|
||
comment: '附加匹配条件(JSON):platform_codes/provinces/cities/item_codes/min_weight_g/max_weight_g/min_amount/max_amount',
|
||
},
|
||
remark: {
|
||
type: Sequelize.STRING(500),
|
||
allowNull: true,
|
||
comment: '备注说明',
|
||
},
|
||
creator_id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
comment: '创建人账户ID(accounts.id)',
|
||
},
|
||
created_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '创建时间',
|
||
},
|
||
updated_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
comment: '更新时间',
|
||
},
|
||
deleted_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
comment: '软删除时间',
|
||
},
|
||
}, {
|
||
comment: '订单自定义店铺-快递绑定策略表',
|
||
engine: 'InnoDB',
|
||
charset: 'utf8mb4',
|
||
collate: 'utf8mb4_general_ci',
|
||
});
|
||
|
||
// 索引:按仓库查询启用策略
|
||
await queryInterface.addIndex(TABLE_NAME, {
|
||
name: 'idx_warehouse_enabled',
|
||
fields: [ 'warehouse_id', 'is_enabled', 'deleted_at' ],
|
||
});
|
||
|
||
// 索引:按仓库+货主+店铺精确匹配
|
||
await queryInterface.addIndex(TABLE_NAME, {
|
||
name: 'idx_warehouse_store_shop',
|
||
fields: [ 'warehouse_id', 'store_id', 'shop_id', 'deleted_at' ],
|
||
});
|
||
|
||
// 索引:按仓库+快递反查绑定店铺
|
||
await queryInterface.addIndex(TABLE_NAME, {
|
||
name: 'idx_warehouse_express',
|
||
fields: [ 'warehouse_id', 'express_code', 'deleted_at' ],
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 回滚:删除表。
|
||
* @param {Object} queryInterface Sequelize QueryInterface 实例。
|
||
* @param {Object} Sequelize Sequelize 类。
|
||
* @return {Promise<void>} 迁移执行结果。
|
||
*/
|
||
down: async (queryInterface, Sequelize) => {
|
||
await queryInterface.dropTable(TABLE_NAME);
|
||
},
|
||
};
|