fix(报价单): 提交基准改为「最近一次已通过价」;superseded/pending 不再导致全量重发,仅 rejected 强制重发
This commit is contained in:
@@ -363,14 +363,19 @@ export async function submitPriceProposal(input: {
|
||||
ORDER BY requested_at DESC`,
|
||||
[branchCode, quoteSheetCode]
|
||||
);
|
||||
const latestPerSku = new Map<string, { price: number; status: string }>();
|
||||
/** 每个 SKU 最近一次出现在**任何**提案里的状态(用于判断"上次是否被驳回") */
|
||||
const latestStatus = new Map<string, string>();
|
||||
/** 每个 SKU 最近一次出现在**已通过**提案里的价格(真正的"配送商已认可的价") */
|
||||
const lastApprovedPrice = new Map<string, number>();
|
||||
for (const proposal of history.rows) {
|
||||
const status = String(proposal.status || '');
|
||||
const list = Array.isArray(proposal.items) ? (proposal.items as Array<Record<string, unknown>>) : [];
|
||||
for (const raw of list) {
|
||||
const sku = toText(raw?.sku_code);
|
||||
const price = Number(raw?.price);
|
||||
if (!sku || !Number.isFinite(price) || latestPerSku.has(sku)) continue;
|
||||
latestPerSku.set(sku, { price, status: String(proposal.status || '') });
|
||||
if (!sku || !Number.isFinite(price)) continue;
|
||||
if (!latestStatus.has(sku)) latestStatus.set(sku, status);
|
||||
if (status === 'approved' && !lastApprovedPrice.has(sku)) lastApprovedPrice.set(sku, price);
|
||||
}
|
||||
}
|
||||
const skipped: Array<{ sku_code: string; reason: string }> = [];
|
||||
@@ -388,9 +393,20 @@ export async function submitPriceProposal(input: {
|
||||
skipped.push({ sku_code: item.sku_code, reason: 'invalid_price' });
|
||||
continue;
|
||||
}
|
||||
const last = latestPerSku.get(item.sku_code);
|
||||
if (last && last.status === 'approved' && Math.abs(Number(item.price) - last.price) < 0.0001) {
|
||||
// 上次已通过且价没变 ⇒ 无需再发(驳回/在途的即使没改也要能重发)
|
||||
const approvedPrice = lastApprovedPrice.get(item.sku_code);
|
||||
const lastStatus = latestStatus.get(item.sku_code);
|
||||
/**
|
||||
* 跳过条件(三者同时成立):
|
||||
* ① 该 SKU 有过"已通过"的价;
|
||||
* ② 当前价与**那次已通过**的价一致;
|
||||
* ③ 最近一次提交**不是驳回**(驳回的即使没改价也必须能重发)。
|
||||
* 注意:`superseded` / `pending` 不应导致重发(那会反复把全单推给对方)。
|
||||
*/
|
||||
if (
|
||||
approvedPrice !== undefined &&
|
||||
lastStatus !== 'rejected' &&
|
||||
Math.abs(Number(item.price) - approvedPrice) < 0.0001
|
||||
) {
|
||||
skipped.push({ sku_code: item.sku_code, reason: 'no_change' });
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user