From b371b96e4e9b6c70e5ea2e936656d3a6d32985f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E5=B1=85?= Date: Fri, 13 Nov 2026 14:50:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(limit-management):=20=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E6=8B=86=E5=8D=95=E5=90=88=E5=8D=95=E7=88=B6=E5=8D=95=E7=A0=B4?= =?UTF-8?q?=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs/限价与破价判定规则.md | 1 + .../src/lib/supply-chain-breach-order.test.ts | 8 +++ .../src/lib/supply-chain-breach-order.ts | 7 +++ .../jst-breach-order-source.repository.ts | 8 ++- ...in-breach-order-generation.service.test.ts | 51 +++++++++++++++++++ .../supply-chain-breach-order.service.ts | 10 ++-- 6 files changed, 79 insertions(+), 6 deletions(-) diff --git a/furniture-3d-system/docs/限价与破价判定规则.md b/furniture-3d-system/docs/限价与破价判定规则.md index 5fb8aa54..a98c5656 100644 --- a/furniture-3d-system/docs/限价与破价判定规则.md +++ b/furniture-3d-system/docs/限价与破价判定规则.md @@ -28,6 +28,7 @@ - 成交数量与商家实收取**换入行**(换货不改变订单成交金额);换入行金额抓不到时回退订单主表商家实收 → 订单主表买家实付,都取不到才按 0(由运营申诉说明); - 换货行配对成功后按原编码生成一条,不再按换入编码单独生成,避免同一订单重复生成两条破价单; - 配对优先按 `sku_uuid` 精确匹配,剩余行仅在一对一时顺序配对;复杂结构(多对多)暂不强行配对,相关行按各自编码现状处理。 +14. **拆单 / 合单父单**:聚水潭 `jst_Orders.status` 为 `Split` 或 `Merged` 的记录只表达父单与子单/合并目标的关系,不作为有效成交订单参与破价;金额和数量统一取实际子单或合并目标单,避免父单空金额被 `ISNULL(...,0)` 误判为 0 元破价并造成重复。 ## 二、申诉与审核 diff --git a/furniture-3d-system/src/lib/supply-chain-breach-order.test.ts b/furniture-3d-system/src/lib/supply-chain-breach-order.test.ts index 8bdff0d2..3108c5d0 100644 --- a/furniture-3d-system/src/lib/supply-chain-breach-order.test.ts +++ b/furniture-3d-system/src/lib/supply-chain-breach-order.test.ts @@ -2,6 +2,7 @@ import { BREACH_ORDER_MONITOR_START_DATE, breachOrderMonthBounds, breachMonitorStartAt, + isEffectiveBreachOrderStatus, } from './supply-chain-breach-order' describe('破价订单审核业务起点', () => { @@ -36,4 +37,11 @@ describe('破价订单审核业务起点', () => { endAtExclusive: new Date('2026-12-31T16:00:00.000Z'), }) }) + + it('拆单和合单父单不作为有效成交订单', () => { + expect(isEffectiveBreachOrderStatus('Split')).toBe(false) + expect(isEffectiveBreachOrderStatus('MERGED')).toBe(false) + expect(isEffectiveBreachOrderStatus('Sent')).toBe(true) + expect(isEffectiveBreachOrderStatus('Cancelled')).toBe(true) + }) }) diff --git a/furniture-3d-system/src/lib/supply-chain-breach-order.ts b/furniture-3d-system/src/lib/supply-chain-breach-order.ts index 8b0541a7..6380c121 100644 --- a/furniture-3d-system/src/lib/supply-chain-breach-order.ts +++ b/furniture-3d-system/src/lib/supply-chain-breach-order.ts @@ -63,6 +63,13 @@ export function isBreachOrderMonitored(payDate: Date | null | undefined) { return payDate instanceof Date && payDate >= breachMonitorStartAt() } +const NON_EFFECTIVE_ORDER_STATUSES = new Set(['SPLIT', 'MERGED']) + +/** 拆单/合单父单只保存聚合关系,成交金额以子单或合并目标单为准。 */ +export function isEffectiveBreachOrderStatus(status: string | null | undefined) { + return !NON_EFFECTIVE_ORDER_STATUSES.has(String(status ?? '').trim().toUpperCase()) +} + /** 申诉类型(页面下拉,按组展示)——按业务确认后的简化版:链接时间 / 优惠·活动 / 流程申请 / 其他原因。 */ export const BREACH_APPEAL_TYPE_GROUPS: Array<{ label: string; types: string[] }> = [ { label: '链接时间', types: ['老链接,上架时间早于限价流程', '京喜换主体 / 老店转新店'] }, diff --git a/furniture-3d-system/src/server/repositories/jst-breach-order-source.repository.ts b/furniture-3d-system/src/server/repositories/jst-breach-order-source.repository.ts index a625704e..c2ef4e3c 100644 --- a/furniture-3d-system/src/server/repositories/jst-breach-order-source.repository.ts +++ b/furniture-3d-system/src/server/repositories/jst-breach-order-source.repository.ts @@ -1,4 +1,5 @@ import sql from 'mssql' +import { isEffectiveBreachOrderStatus } from '@/lib/supply-chain-breach-order' export type JstBreachOrderSourceRow = { oId: string @@ -176,6 +177,7 @@ class JstBreachOrderSourceRepository { WHERE o.o_id = i.o_id AND o.pay_date >= @dateFrom AND o.pay_date < DATEADD(day, 1, @dateTo) + AND UPPER(ISNULL(o.status, '')) NOT IN (N'SPLIT', N'MERGED') ) `), request().query(` @@ -205,6 +207,7 @@ class JstBreachOrderSourceRepository { WHERE o.o_id = i.o_id AND o.pay_date >= @dateFrom AND o.pay_date < DATEADD(day, 1, @dateTo) + AND UPPER(ISNULL(o.status, '')) NOT IN (N'SPLIT', N'MERGED') ) `), ]) @@ -226,8 +229,9 @@ class JstBreachOrderSourceRepository { ...mergeRows('jst', jstHeaders.recordset, jstItems.recordset), ...mergeRows('qmcust', qmcustHeaders.recordset, qmcustItems.recordset), ] - if (!itemCodeSet) return rows - return rows.filter((row) => { + const effectiveRows = rows.filter((row) => isEffectiveBreachOrderStatus(row.orderStatus)) + if (!itemCodeSet) return effectiveRows + return effectiveRows.filter((row) => { if (itemCodeSet.has(String(row.itemCode ?? '').trim().toUpperCase())) return true if (!options?.includeSwapRows) return false return row.itemStatus === 'Replaced' diff --git a/furniture-3d-system/src/server/services/__tests__/supply-chain-breach-order-generation.service.test.ts b/furniture-3d-system/src/server/services/__tests__/supply-chain-breach-order-generation.service.test.ts index 7b1acb7f..e5f7a9ad 100644 --- a/furniture-3d-system/src/server/services/__tests__/supply-chain-breach-order-generation.service.test.ts +++ b/furniture-3d-system/src/server/services/__tests__/supply-chain-breach-order-generation.service.test.ts @@ -197,6 +197,57 @@ describe('SupplyChainBreachOrderService generate', () => { expect(mockPrisma.supplyChainLinkLimitPrice.findMany).toHaveBeenCalled() }) + it('拆单父单不参与破价,只使用成交子单金额', async () => { + const base = { + soId: 'SO-SPLIT-1', + platform: '京东厂家直送', + shopName: '店铺甲', + payDate: new Date('2026-11-11T02:00:00Z'), + itemCode: 'BARCODE-1', + shopItemCode: 'SHOP-SKU-1', + shopStyleCode: 'LINK-1', + qty: 1, + orderStatus: 'Split', + refundStatus: '', + orderSellerIncomeAmount: 0, + orderPaidAmount: 0, + itemStatus: '', + itemSource: '', + skuUuid: null, + sourceKind: 'jst' as const, + } + mockRepository.listOrderItems.mockResolvedValue([{ + ...base, + oId: 'PARENT', + buyerPaidAmount: 0, + sellerIncomeAmount: 0, + }, { + ...base, + oId: 'CHILD', + orderStatus: 'Sent', + buyerPaidAmount: 80, + sellerIncomeAmount: 100, + }]) + mockRepository.listListingTimes.mockResolvedValue(new Map([ + ['LINK-1::SHOP-SKU-1::BARCODE-1', new Date('2026-09-01T00:00:00Z')], + ])) + + const result = await service.generate({ + dateFrom: '2026-11-11', + dateTo: '2026-11-11', + viewer: { id: 'tester', name: 'tester', canReview: true }, + }) + + expect(result.created).toBe(1) + const created = mockPrisma.supplyChainBreachOrder.createMany.mock.calls[0][0].data + expect(created).toHaveLength(1) + expect(created[0]).toMatchObject({ + oId: 'CHILD', + orderStatus: 'Sent', + }) + expect(Number(created[0].buyerPaidAmount)).toBe(80) + }) + it('重跑时刷新历史限价快照和空元数据,不修改审核与申诉状态', async () => { mockPrisma.supplyChainBreachOrder.findMany.mockResolvedValue([{ id: 'BREACH-1', diff --git a/furniture-3d-system/src/server/services/supply-chain-breach-order.service.ts b/furniture-3d-system/src/server/services/supply-chain-breach-order.service.ts index 489619e3..b7b9d862 100644 --- a/furniture-3d-system/src/server/services/supply-chain-breach-order.service.ts +++ b/furniture-3d-system/src/server/services/supply-chain-breach-order.service.ts @@ -21,6 +21,7 @@ import { BREACH_ORDER_MONITOR_START_DATE, breachOrderMonthBounds, breachMonitorStartAt, + isEffectiveBreachOrderStatus, isBreachOrderMonitored, BREACH_ORDER_STATUS, BREACH_ORDER_STATUS_LABELS, @@ -755,21 +756,22 @@ class SupplyChainBreachOrderService { sourceRows.push(...dayRows) } } + const effectiveSourceRows = sourceRows.filter((row) => isEffectiveBreachOrderStatus(row.orderStatus)) const missingOrderOwnerBarcodes = [...new Set( - sourceRows + effectiveSourceRows .map((row) => String(row.itemCode ?? '').trim().toUpperCase()) .filter((barcode) => barcode && !authContext.orderOwnerByBarcode.has(barcode)), )] const [listedAtByLink, linkOwnerByItemId, fallbackItemOwnerByBarcode] = await Promise.all([ - jstBreachOrderSourceRepository.listListingTimes(sourceRows), - jstBreachOrderSourceRepository.listLinkOwners(sourceRows.map((row) => row.shopStyleCode)), + jstBreachOrderSourceRepository.listListingTimes(effectiveSourceRows), + jstBreachOrderSourceRepository.listLinkOwners(effectiveSourceRows.map((row) => row.shopStyleCode)), jstBreachOrderSourceRepository.listItemOwners(missingOrderOwnerBarcodes), ]) const orderOwnerByBarcode = new Map(authContext.orderOwnerByBarcode) for (const [barcode, ownerName] of fallbackItemOwnerByBarcode) { if (!orderOwnerByBarcode.has(barcode)) orderOwnerByBarcode.set(barcode, ownerName) } - const sourceRowsWithMetadata = sourceRows.map((row) => ({ + const sourceRowsWithMetadata = effectiveSourceRows.map((row) => ({ ...row, listedAt: listedAtByLink.get(buildBreachListingKey(row)) ?? null, linkOwnerName: linkOwnerByItemId.get(String(row.shopStyleCode ?? '').trim()) ?? '',