oms/backend/database/migrations/20261104000000-create-external-print-express-interfaces.js
liufumingren eaf957ed14 feat(express): 外部打单快递接口、自定义快递编码与回 OMS 取号
- 外部打单平台快递接口:按账号同步平台模板、绑定快递编码、查看模板明细;打开列表只读库,仅「从平台同步数据」时拉取
- 系统管理新增自定义快递编码字典,订单改快递 / 物流下拉合并系统与自定义编码,推送奇门沿用订单上的编码
- 新增 OpenAPI deliveryorder.getwaybill:WMS 批量回取号(单次≤100、并发4、逐单结果),快递编码只取 WMS 报文,取消/作废/归档返回失败,已取号直接复用
- 新增 openapi_request_idempotency 请求级幂等:request_id 回放、报文摘要校验、30 分钟 stale 接管、7 天定时清理
- 外部打单平台订单按平台 fetch_waybill_no 下发 need_oms_waybill,推送时实时判定并回写单据
- 店铺、打单账号平台配置与「平台+编码→模板」绑定走 Redis 缓存,绑定/账号变更主动失效,避免批量推送与取号逐单查库

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-04 04:10:37 +08:00

148 lines
5.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 外部打单平台快递接口(面单模板)表。
*
* 每个打单账号从平台拉取到的面单模板落一行,用于:
* - 查看平台支持的快递接口(平台 / 店铺 / 模板 / 快递公司);
* - 绑定快递编码(custom_code,系统或自定义快递编码),
* WMS 回读运单号时按「打单账号 + 平台 + 编码」定位唯一模板。
*
* status=0 表示平台侧已不再返回该模板:数据保留(绑定的快递编码不丢),
* 前端标记为「已失效」,避免映射配置被自动清理。
*/
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('external_print_express_interfaces', {
id: {
type: Sequelize.BIGINT.UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键',
},
principal_id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: false,
comment: '所属主体ID',
},
account_id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: false,
comment: '所属外部打单账号ID(external_print_accounts)',
},
platform_type: {
type: Sequelize.STRING(32),
allowNull: false,
defaultValue: '',
comment: '打单平台原始平台类型(如 Pinduoduo / TouTiao)',
},
platform_code: {
type: Sequelize.STRING(20),
allowNull: false,
defaultValue: '',
comment: 'OMS 预设平台编码(如 PDD,见 app/lib/platformCode.js)',
},
platform_name: {
type: Sequelize.STRING(50),
allowNull: true,
comment: 'OMS 预设平台名称(如 拼多多)',
},
template_id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: false,
comment: '平台面单模板ID(店管家 LoadTemplateListInOrderList 返回的 Id)',
},
template_name: {
type: Sequelize.STRING(128),
allowNull: true,
comment: '模板名称(如 【拼多多】韵达一联3)',
},
express_company_id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: true,
comment: '平台快递公司ID',
},
express_company_code: {
type: Sequelize.STRING(50),
allowNull: true,
comment: '平台快递公司编码(如 YUNDA / STO)',
},
express_company_name: {
type: Sequelize.STRING(100),
allowNull: true,
comment: '平台快递公司名称(如 韵达)',
},
shop_id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: true,
comment: '平台店铺(商家)ID',
},
shop_name: {
type: Sequelize.STRING(128),
allowNull: true,
comment: '平台店铺(商家)名称',
},
dbname: {
type: Sequelize.STRING(128),
allowNull: true,
comment: '拉取时使用的分区库名(查看明细时复用)',
},
custom_code: {
type: Sequelize.STRING(50),
allowNull: true,
comment: '绑定的快递编码(系统或自定义),回读运单号时按 账号 + 平台 + 编码 定位',
},
status: {
type: Sequelize.TINYINT,
allowNull: false,
defaultValue: 1,
comment: '状态:1有效 0平台已不再返回(失效,保留自定义设置)',
},
platform_updated_at: {
type: Sequelize.DATE,
allowNull: true,
comment: '平台侧更新时间(模板 UpdateDate)',
},
synced_at: {
type: Sequelize.DATE,
allowNull: true,
comment: '最近一次从平台拉取到的时间',
},
raw: {
type: Sequelize.JSON,
allowNull: true,
comment: '平台返回的模板原始结构',
},
remark: {
type: Sequelize.STRING(255),
allowNull: true,
comment: '备注',
},
created_at: { type: Sequelize.DATE, allowNull: true, comment: '创建时间' },
updated_at: { type: Sequelize.DATE, allowNull: true, comment: '更新时间' },
});
await queryInterface.addIndex('external_print_express_interfaces', [ 'account_id', 'template_id' ], {
name: 'uk_external_print_express_template',
unique: true,
});
await queryInterface.addIndex('external_print_express_interfaces', [ 'principal_id', 'account_id' ], {
name: 'idx_external_print_express_account',
});
await queryInterface.addIndex('external_print_express_interfaces', [ 'principal_id', 'platform_code' ], {
name: 'idx_external_print_express_platform',
});
await queryInterface.addIndex('external_print_express_interfaces', [ 'principal_id', 'express_company_code' ], {
name: 'idx_external_print_express_company',
});
},
async down(queryInterface) {
await queryInterface.removeIndex('external_print_express_interfaces', 'idx_external_print_express_company');
await queryInterface.removeIndex('external_print_express_interfaces', 'idx_external_print_express_platform');
await queryInterface.removeIndex('external_print_express_interfaces', 'idx_external_print_express_account');
await queryInterface.removeIndex('external_print_express_interfaces', 'uk_external_print_express_template');
await queryInterface.dropTable('external_print_express_interfaces');
},
};