From 29be23d62edb47fc39c70063ca31e028658ba3de Mon Sep 17 00:00:00 2001 From: liufumingren Date: Tue, 24 Nov 2026 02:20:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=B8=A6=E8=BF=90=E5=8D=95=E7=9A=84?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=EF=BC=88=E5=BA=97=E5=B0=8F=E7=A7=98=EF=BC=89?= =?UTF-8?q?=E5=8F=96=E5=8F=B7=E4=B8=8D=E5=86=8D=E8=A6=81=E6=B1=82=E5=BF=AB?= =?UTF-8?q?=E9=80=92=E6=8E=A5=E5=8F=A3=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - waybillGet:平台 has_own_waybill=1 时模板可缺省,缺失时跳过「未绑定模板」拦截, fetchWaybillNo 收到 template=null,模板ID/菜鸟网点按空处理 - 其余平台行为不变(缺模板仍返回「暂无面单模板」等指引) - 补 2 条单测(自带运单无模板可取号 / 普通平台缺模板仍拦截) - 文档同步:取号对接 §4.5/§4.6 与店小秘接入 §6 - 实测(真实签名调 /openapi deliveryorder.getwaybill):订单 dxm-184804423947346433 无模板取号成功,waybill_code=3CAB6111900043,pdf_base64 88,796 字符, 取号记录 pdf_base64 落库、result_data 仅 414 字节(只留长度) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- WMS-OMS-取号对接.md | 6 +++- backend/app/lib/waybillGet.js | 16 +++++++--- backend/test/app/lib/waybillGet.test.js | 41 +++++++++++++++++++++++-- 店小秘接入.md | 9 ++++-- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/WMS-OMS-取号对接.md b/WMS-OMS-取号对接.md index c02d9e0..6681904 100644 --- a/WMS-OMS-取号对接.md +++ b/WMS-OMS-取号对接.md @@ -307,6 +307,9 @@ WMS 传入的 expressCode ───────┴─► external_print_express_ - **不按店铺区分**:店管家里的「店铺」是商家,同一账号下的快递接口共用。 - **同一账号 + 同一平台**下,一个快递编码只能绑定一个模板;不同平台可以重复(互不影响)。 - 平台字典 `external_print_platforms.fetch_waybill_no` 目前由**迁移/开发者维护**,前端只读。 +- **自带运单的平台**(`external_print_platforms.has_own_waybill=1`,如店小秘)**不需要模板**: + 运单号取平台订单报文里的 `agentTrackNum`,面单 PDF 由 OMS 现拉,`expressCode` 只作留痕; + 这类平台缺模板时不再拦截,`fetchWaybillNo` 拿到的 `template` 为 `null`。 ### 4.6 校验顺序与「取不到接口」的提示(真实模式) @@ -318,7 +321,8 @@ WMS 传入的 expressCode ───────┴─► external_print_express_ 4. 订单来源平台 `source_platform_code`; 5. 店铺 → `shops.type=2` → `external_print_account_id`(打单账号); 6. 打单账号 + 平台配置(`fetch_waybill_no`); -7. **按「账号 + 平台 + WMS 传入编码」定位快递接口** → 找不到时返回带入口与步骤的提示; +7. **按「账号 + 平台 + WMS 传入编码」定位快递接口** → 找不到时返回带入口与步骤的提示 + (**自带运单的平台跳过这一步**:没有模板也继续,直接按平台订单取号); 8. 调用平台取号(当前店管家未实现 → 返回「店管家取号接口尚未接入」)。 取不到快递接口时,返回一句话的简短提示(平台/快递优先带中文名,查不到名称时只显示编码),真实示例: diff --git a/backend/app/lib/waybillGet.js b/backend/app/lib/waybillGet.js index df08d54..171a8c5 100644 --- a/backend/app/lib/waybillGet.js +++ b/backend/app/lib/waybillGet.js @@ -839,13 +839,16 @@ async function callPlatform(ctx, { principalId, warehouseId, code, expressCode, } meta.accountId = account.id; - // 按「账号 + 订单平台 + WMS 传入的快递编码」定位唯一模板 + // 按「账号 + 订单平台 + WMS 传入的快递编码」定位唯一模板。 + // 平台自带运单(has_own_waybill=1,如店小秘)时不需要模板:运单号与面单都直接从平台订单报文取, + // 快递编码只用于人工指定,不参与平台取号。 + const hasOwnWaybill = Number(account.platform.has_own_waybill) === 1; const template = await ctx.service.externalPrintExpressInterface.resolveByCode( account.id, { platformCode, expressCode }, principalId ); - if (!template) { + if (!template && !hasOwnWaybill) { return fail(code, await buildTemplateMissingMessage(ctx, { account, platformCode, @@ -858,9 +861,12 @@ async function callPlatform(ctx, { principalId, warehouseId, code, expressCode, if (!platformService.needFetchWaybillNo) { return fail(code, `打单平台「${account.platform.name}」未开启回平台取号:请在平台配置中开启 fetch_waybill_no 后重试`); } - meta.templateId = String(template.template_id || (template.raw && template.raw.Id) || ''); + // 模板可缺省(自带运单的平台):缺省时模板ID与菜鸟网点为空,取号只用平台订单上的运单号 + meta.templateId = template ? String(template.template_id || (template.raw && template.raw.Id) || '') : ''; // 菜鸟授权网点ID:随取号结果回给 WMS(同平台不同网点取号用的授权不同) - const caiNiaoAuthInfoId = template.cai_niao_auth_info_id == null ? null : Number(template.cai_niao_auth_info_id); + const caiNiaoAuthInfoId = template && template.cai_niao_auth_info_id != null + ? Number(template.cai_niao_auth_info_id) + : null; // 留痕用:店铺唯一标识(WMS 重取打印数据时按它 + 运单号定位) meta.caiNiaoAuthInfoId = caiNiaoAuthInfoId; @@ -871,7 +877,7 @@ async function callPlatform(ctx, { principalId, warehouseId, code, expressCode, let fetched; try { fetched = await platformService.fetchWaybillNo(orderPlain, { - template: template.get ? template.get({ plain: true }) : template, + template: template ? (template.get ? template.get({ plain: true }) : template) : null, expressCode, platformCode, originalPlatformCode: extendProps.original_platform_code || '', diff --git a/backend/test/app/lib/waybillGet.test.js b/backend/test/app/lib/waybillGet.test.js index 391692e..a551171 100644 --- a/backend/test/app/lib/waybillGet.test.js +++ b/backend/test/app/lib/waybillGet.test.js @@ -21,7 +21,7 @@ function makeEntry(data, list) { return entry; } -function setupContext({ entries = [], legacyRecord = null, waybillCode = 'WB-NEW', fetchError = null } = {}) { +function setupContext({ entries = [], legacyRecord = null, waybillCode = 'WB-NEW', fetchError = null, hasOwnWaybill = 0, templateMissing = false } = {}) { const ctx = app.mockContext(); const fetchedKeys = []; const platformRoutes = []; @@ -59,10 +59,10 @@ function setupContext({ entries = [], legacyRecord = null, waybillCode = 'WB-NEW }); ctx.model.ExternalPrintAccount.findOne = async () => ({ id: 12, - platform: { code: 'TEST_PLATFORM', name: 'Test platform', fetch_waybill_no: 1 }, + platform: { code: 'TEST_PLATFORM', name: 'Test platform', fetch_waybill_no: 1, has_own_waybill: hasOwnWaybill }, get: () => ({ id: 12, platform: { code: 'TEST_PLATFORM', name: 'Test platform' } }), }); - ctx.service.externalPrintExpressInterface.resolveByCode = async () => ({ + ctx.service.externalPrintExpressInterface.resolveByCode = async () => (templateMissing ? null : { template_id: 'template-1', get: () => ({ template_id: 'template-1' }), }); @@ -343,4 +343,39 @@ describe('lib/waybillGet 订单级幂等', () => { assert.strictEqual(result.data.results[0].pdf_base64, 'JVBERi0xLjQK'); assert.strictEqual(state.platformRoutes.length, 0); }); + + it('自带运单的平台没有快递接口模板也能取号(模板可缺省)', async () => { + const state = setupContext({ hasOwnWaybill: 1, templateMissing: true, waybillCode: '3CAB6112100007' }); + const templates = []; + const baseCreate = state.ctx.service.externalPrintOrder.createPlatformService; + state.ctx.service.externalPrintOrder.createPlatformService = account => ({ + ...baseCreate(account), + fetchWaybillNo: async (order, options) => { + templates.push(options.template); + return { waybill_code: '3CAB6112100007', pdf_base64: 'JVBERi0xLjQK' }; + }, + }); + + const result = await waybillGet.getWaybills(state.ctx, { + principalId: PRINCIPAL_ID, + warehouseId: WAREHOUSE_ID, + data: requestBody(requestItem()), + }); + + assert.strictEqual(result.data.results[0].success, true); + assert.strictEqual(result.data.results[0].waybill_code, '3CAB6112100007'); + assert.strictEqual(templates.length, 1); + assert.strictEqual(templates[0], null); + }); + + it('非自带运单的平台缺模板仍然报未绑定模板', async () => { + const state = setupContext({ hasOwnWaybill: 0, templateMissing: true }); + const result = await waybillGet.getWaybills(state.ctx, { + principalId: PRINCIPAL_ID, + warehouseId: WAREHOUSE_ID, + data: requestBody(requestItem()), + }); + assert.strictEqual(result.data.results[0].success, false); + assert.match(result.data.results[0].message, /暂无面单模板/); + }); }); diff --git a/店小秘接入.md b/店小秘接入.md index 01ba381..641dbb7 100644 --- a/店小秘接入.md +++ b/店小秘接入.md @@ -267,9 +267,14 @@ GET /api/pddkjInventory/printExpressNote.json?id=<包裹ID> 拿到 blob 后塞进 iframe 打印)。 `dxm.js` 目前实现 `getLoginCaptcha / login / checkSession / listShopSources / listShops / listProducts / -listOrders / fetchWaybillNo`,`print` 及发货回传仍继承基类报「未实现」。后续按以下顺序补: +listOrders / fetchWaybillNo / fetchPrintPdf`,`print` 及发货回传仍继承基类报「未实现」。 -1. `print(order)`:checkPrint 校验 → 下载 PDF → 返回给打印端(存储方式待定,见下) +取号不需要快递接口模板:平台配置 `has_own_waybill=1` 时,`waybillGet` 允许模板为空, +运单号取 `extend_props.platform_waybill_code`、面单 PDF 现拉后以 `pdf_base64` 回给 WMS。 + +后续待补: + +1. `print(order)`:checkPrint 校验 → 下载 PDF → 返回给打印端(存储方式见 6.1) 2. 发货回传(`/api/package/batchShipGoods.json` 一类的交运接口) 每补一个接口,先抓真实报文确认字段口径,再补 `backend/test/app/lib/printPlatformDxm.test.js` 用例。