fix(waybill): 取号回读订单时按分区兜底,避免「未找到订单」
模板记录的分区可能与订单实际所在分区不同(店铺迁区/模板按账号同步), 只在模板分区里查会直接报「店管家未找到订单」,且把模板分区也带进报错便于定位。 - fetchWaybillNo:模板分区查不到时用 listProductAreas 逐个分区回读,命中即改写 dbname - 分区回读异常(非法 dbname 等)不中断,继续下一个分区 - 找不到订单时在错误信息里带上域名 + 分区 实测:1688 抖音分销单 10000280844952 在 fxali/新系统区 命中; 传原始平台域名 + 故意用错分区仍能回读成功,不传原始平台则复现 fxdd「未找到订单」。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
6ffe7cc889
commit
c5bf929b3a
@ -2245,19 +2245,39 @@ class DgjService extends PrintPlatformService {
|
||||
// 忽略:traceId 缺失不阻断取号(与模板查询同口径)
|
||||
}
|
||||
|
||||
const dbname = String(template.dbname || '').trim();
|
||||
// 分区:模板记录的分区优先,订单不一定同区(模板按账号同步、店铺可能迁区),命中会改写
|
||||
let dbname = String(template.dbname || '').trim();
|
||||
const logicalOrderId = String(order.parent_order_no || String(order.order_no || '').replace(/^[^-]+-/, '')).trim();
|
||||
const platformOrderId = String((order.extend_props && order.extend_props.platform_order_no) || order.oaid_order_source_code || '').trim();
|
||||
if (!logicalOrderId) throw new Error('订单缺少店管家系统编号(parent_order_no),无法取号');
|
||||
|
||||
const row = await this.findPlatformOrderRow(host, {
|
||||
traceId,
|
||||
dbname,
|
||||
logicalOrderId,
|
||||
platformOrderId,
|
||||
placeOrderTime: order.place_order_time || order.pay_time || order.created_at,
|
||||
});
|
||||
if (!row) throw new Error(`店管家未找到订单:系统编号 ${logicalOrderId}(域名 ${host})`);
|
||||
const placeOrderTime = order.place_order_time || order.pay_time || order.created_at;
|
||||
let row = await this.findPlatformOrderRow(host, { traceId, dbname, logicalOrderId, platformOrderId, placeOrderTime });
|
||||
if (!row) {
|
||||
// 模板分区里查不到时逐个分区回读(取号要用平台的订单行,分区不对就会「未找到订单」)
|
||||
let areas = [];
|
||||
try {
|
||||
areas = await this.listProductAreas(host);
|
||||
} catch {
|
||||
areas = [];
|
||||
}
|
||||
for (const area of areas) {
|
||||
const candidate = String((area && area.dbname) || '').trim();
|
||||
if (!candidate || candidate === dbname) continue;
|
||||
try {
|
||||
row = await this.findPlatformOrderRow(host, {
|
||||
traceId, dbname: candidate, logicalOrderId, platformOrderId, placeOrderTime,
|
||||
});
|
||||
} catch {
|
||||
row = null;
|
||||
}
|
||||
if (row) {
|
||||
dbname = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!row) throw new Error(`店管家未找到订单:系统编号 ${logicalOrderId}(域名 ${host},分区 ${dbname || '-'})`);
|
||||
|
||||
// 平台侧已发货/已终结:不能再取号,也不能把旧运单号当成取号成功(该单应作废/取消)
|
||||
if (isOrderFinished(row)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user