oms/backend/app/model/externalPrintExpressInterface.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

59 lines
3.2 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';
/**
* 外部打单平台快递接口(面单模板)模型,对应 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;
};