oms/backend/app/model/waybillFetchRecord.js
liufumingren 09587bc3e7 feat(waybill): 新增 deliveryorder.getprintdata,打印前按运单号换新 params
店管家面单打印数据(params)只有 10 分钟有效期,取号返回的 printinfo 存着不能用,
WMS 真正打印前必须换新的。新增对外方法:

  method = deliveryorder.getprintdata
  入参:{ caiNiaoAuthInfoIds: [6838859], waybillCodes: ["770357408441408"] }
       也支持直传 { printHistoryIds: ["10000078656212"] }(命中即跳过查库)
  出参:{ total, success, failed, expires_in: 600, results: [...] }
       每单含 print_data / printer_config / document(documentID = 运单号)

实现:
- app/lib/waybillPrintData.js:按「店铺标识 + 运单号」查 waybill_fetch_records 定位打印记录,
  同账号同分区合并成一次 PrintHistory/LoadPrintData(只读,不消耗面单)
- 取号记录补 platform_host(实际命中的订单域名):1688 分销单在 fxali、真实抖音单在 fxdd,
  用被换算过的 source_platform_code 推域名会打错
- waybillGet 落 platform_host;迁移 20261107050000 加列

实测(只读):运单号 770357408441408 → 新 params 7888 字符,documentID 770357408441408,
printer 默认打印机;不存在的运单号返回「未找到该运单号的取号记录」。

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 06:38:34 +08:00

52 lines
2.9 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';
/**
* 取号明细记录模型,对应 waybill_fetch_records。
*
* 每次 `deliveryorder.getwaybill` 逐单取号(成功/复用/失败)都写一条,保存打单平台的原始返回,
* 以及需要透传给 WMS 的 `printinfo / signature`。
* 仅做留痕,不参与业务状态流转(取号与订单表暂不关联)。
* @param {Egg.Application} app egg application
* @return {object} waybillFetchRecord model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, TEXT, DATE } = app.Sequelize;
const WaybillFetchRecord = app.model.define('waybill_fetch_record', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '主体ID(来自 app_key)' },
warehouse_id: { type: BIGINT.UNSIGNED, comment: '仓库ID(来自 app_key)' },
request_id: { type: STRING(100), comment: '调用方 request_id' },
delivery_order_code: { type: STRING(100), allowNull: false, comment: 'OMS 发货单号' },
express_code: { type: STRING(50), comment: '本次取号的快递编码' },
platform_code: { type: STRING(50), comment: '订单来源平台编码' },
account_id: { type: BIGINT.UNSIGNED, comment: '外部打单账号ID' },
template_id: { type: STRING(100), comment: '面单模板ID' },
status: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '状态:1成功 0失败' },
waybill_source: { type: STRING(20), comment: '运单号来源:express_print / platform_last' },
waybill_code: { type: STRING(100), comment: '主运单号' },
waybill_codes: { type: TEXT, comment: '全部运单号(JSON 数组)' },
printinfo: { type: TEXT('medium'), comment: '面单打印数据(平台原样返回)' },
signature: { type: TEXT('medium'), comment: '面单签名(平台原样返回)' },
print_history_ids: {
type: TEXT,
comment: '打印记录(平台 PrintHistoryIds,JSON 数组:id/pid/waybill_code/batch_index),重打/作废用',
},
cai_niao_auth_info_id: {
type: BIGINT.UNSIGNED,
comment: '菜鸟授权网点ID(=店铺唯一标识,重取打印数据时按它+运单号定位)',
},
dbname: { type: STRING(100), comment: '实际命中的打单平台分区(重取打印数据要带同一个 dbname)' },
platform_host: { type: STRING(100), comment: '实际命中的订单域名(重取打印数据要发到同一个域名)' },
raw_response: { type: TEXT('medium'), comment: '平台原始返回(JSON)' },
error_message: { type: TEXT, comment: '失败原因' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
}, {
tableName: 'waybill_fetch_records',
comment: '取号明细记录(平台原始返回留痕)',
});
return WaybillFetchRecord;
};