fix(limit-management): 排除拆单合单父单破价
This commit is contained in:
parent
c4eba8a76f
commit
b371b96e4e
@ -28,6 +28,7 @@
|
||||
- 成交数量与商家实收取**换入行**(换货不改变订单成交金额);换入行金额抓不到时回退订单主表商家实收 → 订单主表买家实付,都取不到才按 0(由运营申诉说明);
|
||||
- 换货行配对成功后按原编码生成一条,不再按换入编码单独生成,避免同一订单重复生成两条破价单;
|
||||
- 配对优先按 `sku_uuid` 精确匹配,剩余行仅在一对一时顺序配对;复杂结构(多对多)暂不强行配对,相关行按各自编码现状处理。
|
||||
14. **拆单 / 合单父单**:聚水潭 `jst_Orders.status` 为 `Split` 或 `Merged` 的记录只表达父单与子单/合并目标的关系,不作为有效成交订单参与破价;金额和数量统一取实际子单或合并目标单,避免父单空金额被 `ISNULL(...,0)` 误判为 0 元破价并造成重复。
|
||||
|
||||
## 二、申诉与审核
|
||||
|
||||
|
||||
@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@ -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: ['老链接,上架时间早于限价流程', '京喜换主体 / 老店转新店'] },
|
||||
|
||||
@ -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<ItemRow>(`
|
||||
@ -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'
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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()) ?? '',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user