oms/backend/test/app/lib/pullOrderHint.test.js
liufumingren d179cd3993 fix(pull): 一区(老分区)声明缺失时补扫 + 退化全量时提示可能漏单
用户报「抖音/抖店一区的 5 单拉不到」。按平台单号定位:5 单全部在
`fxdd.dgjapp.com(抖店-186,即一区)`,`ErpState=waitsellersend`、
`UpFxUserId=953516`、`ShopId=4500493`,新系统区/精选区里没有它们。
一区能拉到的前提是「待发货」过滤生效(`Contract` 必须是单个 `=`)。

- dgj.listOrders:把分区扫描抽成 scanArea;声明里没有老分区时不再直接跳过,
  而是先挂起(deferredLegacy),新系统分区一单都没拉到时回头补扫老分区
  (rescueHosts),命中会记 warn;确实有单时仍跳过并在 skippedLegacy 里列出
- externalPrintOrder:buildSupplementHint 兼容「补扫老分区」与「补查其它域名」两类;
  新增 buildFallbackHint —— 有分区退化为「时间窗全量」时提示
  「平台全量列表不含待发货单,可能漏拉,请检查后端版本(订单过滤 Contract 需为单个等号)」
- 单测:pullOrderHint.test.js 补 2 例(补扫老分区提示、退化兜底提示),
  test/app/lib 75 passing

实测(本地库,同账号):只声明「抖店-二区」时 listOrders 仍能拿到
6931208417510390802 / 6931197358224080335 / 6931209886018010885 /
6919330748987944687 / 6931230754941796036 这 5 单(待处理 7 单)。

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 21:03:14 +08:00

88 lines
3.4 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';
const { app, assert } = require('egg-mock/bootstrap');
describe('service/externalPrintOrder 拉单 0 单的排查提示', () => {
let service;
beforeEach(() => {
service = app.mockContext().service.externalPrintOrder;
});
it('平台出现了别的商家、没出现本店商家时给出提示', () => {
const hint = service.buildZeroOrderHint(
{ external_data: { FxUserId: 1921984 } },
{
total: 0,
merchantSeen: false,
otherMerchants: [{ fx_user_id: '953516', shop_name: '13668975305(意洁)', count: 450 }],
hosts: [ 'fxdd.dgjapp.com(抖店-186)' ],
fallbackHosts: [ 'fxdd.dgjapp.com(抖店-186)' ],
},
{ startTime: new Date('2026-10-23T00:00:00Z'), endTime: new Date('2026-11-07T00:00:00Z') }
);
console.log('提示:', hint);
assert.match(hint, /近 15 天/);
assert.match(hint, /FxUserId=1921984/);
assert.match(hint, /953516/);
assert.match(hint, /刷新/);
// 分区去重
assert.strictEqual(hint.split('抖店-186').length - 1, 1);
});
it('有单 / 商家出现过 / 没看到别的商家时都不提示', () => {
const shop = { external_data: { FxUserId: 1 } };
const base = { merchantSeen: false, otherMerchants: [{ fx_user_id: '2', shop_name: 'A', count: 3 }], hosts: [] };
assert.strictEqual(service.buildZeroOrderHint(shop, { ...base, total: 5 }), '');
assert.strictEqual(service.buildZeroOrderHint(shop, { ...base, total: 0, merchantSeen: true }), '');
assert.strictEqual(service.buildZeroOrderHint(shop, { ...base, total: 0, otherMerchants: [] }), '');
assert.strictEqual(service.buildZeroOrderHint(shop, null), '');
});
it('声明分区没拉到单、补查其它域名才拉到时给出提示', () => {
const hint = service.buildSupplementHint(
{ external_data: { FxUserId: 953516 } },
{
total: 6,
declaredHosts: [ 'fxdd.dgjapp.com' ],
supplementHosts: [ 'fxali.dgjapp.com', 'fxpdd.dgjapp.com' ],
}
);
console.log('补查提示:', hint);
assert.match(hint, /fxdd\.dgjapp\.com/);
assert.match(hint, /fxali\.dgjapp\.com/);
assert.match(hint, /拉到 6 单/);
assert.match(hint, /刷新/);
});
it('没补查 / 没拉到单时不提示', () => {
assert.strictEqual(service.buildSupplementHint({}, { total: 6, supplementHosts: [] }), '');
assert.strictEqual(service.buildSupplementHint({}, { total: 0, supplementHosts: [ 'fxali.dgjapp.com' ] }), '');
assert.strictEqual(service.buildSupplementHint({}, null), '');
});
it('补扫老分区才拉到单时也算补查', () => {
const hint = service.buildSupplementHint({}, {
total: 5,
declaredHosts: [ 'fxdd.dgjapp.com' ],
rescueHosts: [ 'fxdd.dgjapp.com(抖店-186)' ],
});
console.log('补扫老分区提示:', hint);
assert.match(hint, /抖店-186/);
assert.match(hint, /拉到 5 单/);
});
it('走了「不支持状态过滤 → 全量」兜底时提示可能漏单', () => {
const hint = service.buildFallbackHint({
total: 0,
fallbackHosts: [ 'fxdd.dgjapp.com(抖店-186)' ],
});
console.log('兜底提示:', hint);
assert.match(hint, /抖店-186/);
assert.match(hint, /全量列表不含待发货单/);
assert.match(hint, /单个等号/);
assert.strictEqual(service.buildFallbackHint({ total: 0, fallbackHosts: [] }), '');
assert.strictEqual(service.buildFallbackHint(null), '');
});
});