- 拉单任务:新增 order_sync_tasks 异步任务池,按店铺逐店拉取外部打单平台订单,前端轮询进度 - 外部发货同步:配送后把发货结果同步回店管家,提供数量统计与批量重试(externalSendSync) - 取号:新增 waybill_fetch_records 记录取号过程,外部快递接口补充菜鸟授权信息 - 补齐相关迁移、订单页同步入口/状态展示,并新增对接说明文档 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
130 lines
4.5 KiB
JavaScript
130 lines
4.5 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 取号明细记录表。
|
||
*
|
||
* `deliveryorder.getwaybill` 每次向打单平台取号(含「复用平台已有运单号」与失败)都落一条,
|
||
* 目的是把**平台原始返回**留存下来,便于:
|
||
* - 核对 WMS 该拿什么格式回写(printinfo / signature 原样透传);
|
||
* - 面单重复、号码不变、模板异常等问题复盘(不用再靠日志里截断的响应);
|
||
* - 与 `openapi_request_idempotency` 的请求级幂等对齐(同一次请求的所有单据可按 request_id 串起来)。
|
||
*
|
||
* 与订单表的关系:**不写订单表**(取号与订单暂不关联),本表只做留痕,可随时清理。
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.createTable('waybill_fetch_records', {
|
||
id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
comment: '主键',
|
||
},
|
||
principal_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
comment: '主体ID(来自 app_key)',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: true,
|
||
comment: '仓库ID(来自 app_key)',
|
||
},
|
||
request_id: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: true,
|
||
comment: '调用方 request_id(同一次批量取号共用)',
|
||
},
|
||
delivery_order_code: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: false,
|
||
comment: 'OMS 发货单号(WMS 传入的 deliveryOrderCode)',
|
||
},
|
||
express_code: {
|
||
type: Sequelize.STRING(50),
|
||
allowNull: true,
|
||
comment: '本次取号的快递编码(报文传入)',
|
||
},
|
||
platform_code: {
|
||
type: Sequelize.STRING(50),
|
||
allowNull: true,
|
||
comment: '订单来源平台编码',
|
||
},
|
||
account_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: true,
|
||
comment: '外部打单账号ID',
|
||
},
|
||
template_id: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: true,
|
||
comment: '面单模板ID(平台侧)',
|
||
},
|
||
status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '状态:1成功 0失败',
|
||
},
|
||
waybill_source: {
|
||
type: Sequelize.STRING(20),
|
||
allowNull: true,
|
||
comment: '运单号来源:express_print=本次取号 platform_last=复用平台已有运单号',
|
||
},
|
||
waybill_code: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: true,
|
||
comment: '主运单号',
|
||
},
|
||
waybill_codes: {
|
||
type: Sequelize.TEXT,
|
||
allowNull: true,
|
||
comment: '全部运单号(JSON 数组,多包裹场景)',
|
||
},
|
||
printinfo: {
|
||
type: Sequelize.TEXT('medium'),
|
||
allowNull: true,
|
||
comment: '面单打印数据(平台原样返回,透传给 WMS)',
|
||
},
|
||
signature: {
|
||
type: Sequelize.TEXT('medium'),
|
||
allowNull: true,
|
||
comment: '面单签名(平台原样返回,透传给 WMS)',
|
||
},
|
||
raw_response: {
|
||
type: Sequelize.TEXT('medium'),
|
||
allowNull: true,
|
||
comment: '平台原始返回(JSON,调试用)',
|
||
},
|
||
error_message: {
|
||
type: Sequelize.TEXT,
|
||
allowNull: true,
|
||
comment: '失败原因',
|
||
},
|
||
created_at: { type: Sequelize.DATE, allowNull: true, comment: '创建时间' },
|
||
updated_at: { type: Sequelize.DATE, allowNull: true, comment: '更新时间' },
|
||
});
|
||
|
||
await queryInterface.addIndex('waybill_fetch_records', [ 'delivery_order_code' ], {
|
||
name: 'idx_waybill_fetch_order_code',
|
||
});
|
||
await queryInterface.addIndex('waybill_fetch_records', [ 'waybill_code' ], {
|
||
name: 'idx_waybill_fetch_waybill_code',
|
||
});
|
||
await queryInterface.addIndex('waybill_fetch_records', [ 'request_id' ], {
|
||
name: 'idx_waybill_fetch_request_id',
|
||
});
|
||
await queryInterface.addIndex('waybill_fetch_records', [ 'created_at' ], {
|
||
name: 'idx_waybill_fetch_created',
|
||
});
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.removeIndex('waybill_fetch_records', 'idx_waybill_fetch_created');
|
||
await queryInterface.removeIndex('waybill_fetch_records', 'idx_waybill_fetch_request_id');
|
||
await queryInterface.removeIndex('waybill_fetch_records', 'idx_waybill_fetch_waybill_code');
|
||
await queryInterface.removeIndex('waybill_fetch_records', 'idx_waybill_fetch_order_code');
|
||
await queryInterface.dropTable('waybill_fetch_records');
|
||
},
|
||
};
|