fix(send): 发货回传用取号记录的分区,别用模板记录的 dbname
线上「意洁」整批回传失败固定报 `店管家发货同步失败:12;ErrorCode=500`。对同一单、同一 fxdd 域名、同一模板只改 dbname 做对照(该单平台侧已发货,正确报文只会回「不是待发货」): - dbname=y/2wUDWCZOk=(模板记录 external_print_express_interfaces.dbname)→ 12 / ErrorCode=500 - dbname=''(host 默认区) → 「存在不是待发货的商品」(业务类,正常) - dbname=dzh93a8…(取号记录 dbname) → 同上,正常 根因:resolveTarget 把模板记录的 dbname 当成订单分区去发 OnlineSend / 回读订单行, 而那个值是「模板接口」的区(同账号所有模板相同),平台在错的区里解析 Orders → 抛 500, Message 只回一串数字,看起来像报文缺字段(连带 §9f067c1 的实时行重试也拿不到行)。 - resolveTarget:dbname 改取 waybill_fetch_records.dbname(取号就在那一区成功),无取号记录时 '' - 模板同步/查询仍用模板记录的 dbname,两者不混用 - recordFailure:报文类失败的备注里附平台原始返回(先 500 字内),订单页即可看到真实返回 - 报文类失败但回读不到实时订单行时,备注里明确写出来(原来静默按首次错误落库) - 单测 externalSendDbname.test.js 2 例;文档补 §2.1.2(对照表 + 口径表) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
956793ba66
commit
3b1c13492c
@ -227,6 +227,8 @@ class ExternalSendSyncService extends Service {
|
||||
// 直接用平台实时订单行重发一次(实测同一单换成实时行后能正常发货)
|
||||
const rejectedPayload = this.isPayloadRejectedError(err);
|
||||
if (rejectedPayload) {
|
||||
let retryErr = null;
|
||||
let liveRowMissing = false;
|
||||
try {
|
||||
const target = await this.resolveTarget(order);
|
||||
if (target) {
|
||||
@ -258,10 +260,22 @@ class ExternalSendSyncService extends Service {
|
||||
ctx.logger.info('[external-send] 改用平台实时订单行后同步成功 %s', order.order_no);
|
||||
return { ok: true, message: 'ok' };
|
||||
}
|
||||
liveRowMissing = true;
|
||||
ctx.logger.warn('[external-send] %s 回读平台订单行失败(订单可能已不在待发货),无法用实时行重试', order.order_no);
|
||||
}
|
||||
} catch (retryErr) {
|
||||
} catch (retryErr2) {
|
||||
retryErr = retryErr2;
|
||||
ctx.logger.warn('[external-send] %s 用平台实时订单行重试仍失败:%s', order.order_no, retryErr.message);
|
||||
return await this.recordFailure(order, retryErr, now);
|
||||
}
|
||||
if (retryErr) return await this.recordFailure(order, retryErr, now);
|
||||
if (liveRowMissing) {
|
||||
return await this.recordFailure(
|
||||
order,
|
||||
Object.assign(new Error(`${err.message}(回读平台订单行失败,未能用实时行重试)`), {
|
||||
rawResponse: err.rawResponse,
|
||||
}),
|
||||
now
|
||||
);
|
||||
}
|
||||
}
|
||||
return await this.recordFailure(order, err, now);
|
||||
@ -351,10 +365,16 @@ class ExternalSendSyncService extends Service {
|
||||
*/
|
||||
async recordFailure(order, err, now) {
|
||||
const { ctx } = this;
|
||||
const message = truncateText(err && err.message ? err.message : '同步失败', 500);
|
||||
const rawMessage = truncateText(err && err.message ? err.message : '同步失败', 500);
|
||||
// 平台限流(服务商级 QPS 超限)不是这单的问题:不计入重试次数,等下一轮调度再试,
|
||||
// 否则批量重试时容易一批单被限流打成「异常」,还得人工再清
|
||||
const rateLimited = /isv\.request-limited|请求太频繁|访问QPS|接口限流/i.test(message);
|
||||
const rateLimited = /isv\.request-limited|请求太频繁|访问QPS|接口限流/i.test(rawMessage);
|
||||
// 报文类失败把平台原始返回摘一段拼进备注:订单页能直接看到「12」背后到底是什么,
|
||||
// 不用再去翻日志(完整原始返回仍写日志)
|
||||
const raw = err && err.rawResponse;
|
||||
const message = raw && isPayloadRejected(raw, rawMessage)
|
||||
? truncateText(`${rawMessage}|平台原始返回:${JSON.stringify(raw)}`, 500)
|
||||
: rawMessage;
|
||||
if (rateLimited) {
|
||||
await order.update({
|
||||
external_send_status: SEND_STATUS.RETRY,
|
||||
@ -536,7 +556,12 @@ class ExternalSendSyncService extends Service {
|
||||
platformType = template ? template.platform_type : (typeof resolvePlatformType === 'function' ? resolvePlatformType(platformCode) : '');
|
||||
}
|
||||
if (!platformType) return null;
|
||||
return { service, account, platformType, dbname: template ? template.dbname : '', platformCode, template, fetchRecord };
|
||||
// 回传发货要发到**订单所在分区**:取号记录里的 dbname 就是取号当时命中的那个区
|
||||
// (取号在那一区成功,说明订单就在那里)。
|
||||
// ⚠️ 不能用模板记录的 dbname:那是模板接口用的区,实测拿它回传发货,同一单会返回
|
||||
// `{"Success":false,"ErrorCode":"500","Message":"12"}`(平台在错的区里解析订单),见文档 §2.1.2。
|
||||
const dbname = String((fetchRecord && fetchRecord.dbname) || '').trim();
|
||||
return { service, account, platformType, dbname, platformCode, template, fetchRecord };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
54
backend/test/app/lib/externalSendDbname.test.js
Normal file
54
backend/test/app/lib/externalSendDbname.test.js
Normal file
@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
const { app, assert } = require('egg-mock/bootstrap');
|
||||
|
||||
/**
|
||||
* 造一个 resolveTarget 需要的最小上下文
|
||||
* @param {Object} ctx egg context
|
||||
* @param {Object} [fetchRecord] 取号记录(null 表示没有)
|
||||
* @return {Object} 服务实例
|
||||
*/
|
||||
function prepare(ctx, fetchRecord) {
|
||||
const service = ctx.service.externalSendSync;
|
||||
ctx.model.Shop.findByPk = async () => ({ id: 19, type: 2, external_print_account_id: 1 });
|
||||
ctx.model.ExternalPrintAccount.findByPk = async () => ({ id: 1, platform: { code: 'dgj' } });
|
||||
ctx.service.externalPrintOrder.createPlatformService = () => ({
|
||||
constructor: { resolvePlatformType: () => 'TouTiao' },
|
||||
});
|
||||
service.findLatestFetchRecord = async () => fetchRecord;
|
||||
service.resolveSendTemplate = async () => ({
|
||||
// 模板记录里的 dbname 是模板接口的区,不能拿来发订单
|
||||
dbname: 'y/2wUDWCZOk=',
|
||||
platform_type: 'TouTiao',
|
||||
template_id: '12360764',
|
||||
express_company_code: 'YUNDA',
|
||||
express_company_id: 7,
|
||||
});
|
||||
return service;
|
||||
}
|
||||
|
||||
const ORDER = {
|
||||
shop_id: 19,
|
||||
principal_id: 5,
|
||||
order_no: 'dgj-875172836006880609',
|
||||
parent_order_no: '875172836006880609',
|
||||
source_platform_code: 'DYXD',
|
||||
extend_props: { original_platform_code: 'DYXD' },
|
||||
};
|
||||
|
||||
describe('service/externalSendSync 发货分区(dbname)口径', () => {
|
||||
it('用取号记录的分区,不用模板记录的 dbname', async () => {
|
||||
const ctx = app.mockContext();
|
||||
const service = prepare(ctx, { id: 5, express_code: 'YUNDA', dbname: 'dzh93a8yur84Y3Yln2ha9RbPovVMhBTc' });
|
||||
const target = await service.resolveTarget({ ...ORDER });
|
||||
assert.strictEqual(target.dbname, 'dzh93a8yur84Y3Yln2ha9RbPovVMhBTc');
|
||||
assert.notStrictEqual(target.dbname, 'y/2wUDWCZOk=');
|
||||
});
|
||||
|
||||
it('没有取号记录时用 host 默认区(空串),同样不拿模板 dbname', async () => {
|
||||
const ctx = app.mockContext();
|
||||
const service = prepare(ctx, null);
|
||||
const target = await service.resolveTarget({ ...ORDER });
|
||||
assert.strictEqual(target.dbname, '');
|
||||
});
|
||||
});
|
||||
@ -162,6 +162,31 @@ NOT_MATCH_SEGMENT_CHANNEL#…此运单号非抖音的运单号…`。
|
||||
判定口径刻意排除业务类失败:「不是待发货状态」「当前选中的订单都没有打印」「风控拦截」「请先勾选要发货的订单」
|
||||
以及限流文案——这些重发也没用,按原逻辑计数/提示。
|
||||
|
||||
#### 2.1.2 发货 500「Message=12」的真凶:用了模板记录的 `dbname`
|
||||
|
||||
2026-11-07 线上「意洁」整批回传失败,文案固定是 `店管家发货同步失败:12;ErrorCode=500`。
|
||||
对**同一单、同一域名 `fxdd`、同一模板 12360764** 只改 `dbname` 做对照(该单平台侧已发货,正确报文只会回「不是待发货」):
|
||||
|
||||
| 请求带的 `dbname` | 平台响应 |
|
||||
|---|---|
|
||||
| `y/2wUDWCZOk=`(**模板记录 `external_print_express_interfaces.dbname`**) | `{"Success":false,"ErrorCode":"500","Message":"12"}` ← 线上同款 |
|
||||
| `''`(host 默认区) | `存在不是待发货的商品,发货失败`(业务类,正常) |
|
||||
| `dzh93a8yur84Y3Yln2ha9RbPovVMhBTc`(**取号记录 `dbname`**) | `存在不是待发货的商品,发货失败`(业务类,正常) |
|
||||
|
||||
根因:`externalSendSync.resolveTarget` 之前把**模板记录**的 `dbname` 当成订单分区回传发货。
|
||||
模板的 `dbname` 是「模板接口」用的区(同一账号所有模板都是同一个值),拿它去发订单,
|
||||
平台在错的区里解析 `Orders[i]` → 抛 500,只回一串数字,看起来像报文缺字段。
|
||||
|
||||
修正口径(`resolveTarget`):
|
||||
|
||||
| 用途 | 取值 |
|
||||
|---|---|
|
||||
| 回传发货 / 回读订单行 | **取号记录 `waybill_fetch_records.dbname`**(取号就在那一区成功);没有取号记录时用 `''`(host 默认区) |
|
||||
| 模板同步 / 模板查询 | 仍用模板记录的 `dbname`(那是模板接口的区,两者不要混用) |
|
||||
|
||||
因此 §2.1.1 的「改用实时订单行重试」只有在 `dbname` 正确后才有意义——之前回读订单行也在错的区,拿不到行。
|
||||
|
||||
|
||||
|
||||
**失败单不转表**:进了配送说明仓库已打包发货,是既成事实,必须留在配送表可见/可导出;
|
||||
只在配送表标记 `external_send_status`(2 待重试 / 3 同步异常),由「配送异常」视图筛出来处理。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user