fix(商城管理): 报价单改价回写客户商品库

按配送系统口径:报价单内商品改价同时写 customer_skus.sale_price;不在报价单只写客户商品库;保留共享报价单并发锁。
This commit is contained in:
Ubuntu
2026-10-28 20:30:44 +08:00
parent 94de4e60de
commit 64c5230aa8
3 changed files with 40 additions and 2 deletions
@@ -13,6 +13,33 @@ function validCode(value: string) {
return value.length > 0 && value.length <= 64 && /^[A-Za-z0-9._:-]+$/.test(value);
}
/** 报价单 / 客户商品库改价后的同一事务内回写客户商品库,保证商城取不到报价单时仍有价。 */
async function upsertCustomerSkuPrice(
client: PoolClient,
input: {
customerCode: string;
skuCode: string;
branchCode: string;
salePrice: number;
operatorId?: string | null;
}
): Promise<void> {
await client.query(
`INSERT INTO customer_skus
(customer_code, sku_code, customer_sku_name, customer_unit, branch_code,
sale_price, price_updated_at, price_updated_by)
VALUES ($1::text, $2::text,
(SELECT sku_name FROM skus WHERE sku_code = $2::text),
(SELECT unit FROM skus WHERE sku_code = $2::text),
$3::text, $4, NOW(), $5::uuid)
ON CONFLICT (customer_code, sku_code) DO UPDATE
SET sale_price = EXCLUDED.sale_price,
price_updated_at = NOW(),
price_updated_by = EXCLUDED.price_updated_by`,
[input.customerCode, input.skuCode, input.branchCode, input.salePrice, input.operatorId || null]
);
}
export async function setCustomerSkuSalePrice(input: {
customerCode: string;
skuCode: string;
@@ -162,6 +189,14 @@ export async function setCustomerSkuSalePrice(input: {
wroteQuote = true;
target = 'quote_sheet';
quoteSheetCode = sheetCode;
// 与配送系统一致:报价单改价时同一事务回写客户商品库,报价单失效后商城仍有价。
await upsertCustomerSkuPrice(client, {
customerCode,
skuCode,
branchCode,
salePrice: price,
operatorId: input.operatorId || null,
});
}
}
}
@@ -222,6 +257,7 @@ export async function setCustomerSkuSalePrice(input: {
sale_price: price,
target,
quote_sheet_code: quoteSheetCode || null,
synced_customer_sku: target === 'quote_sheet',
},
branchCode,
actionCategory: 'pricing',
@@ -29,6 +29,8 @@ describe('客户 SKU 销售价二期', () => {
// 自动选择报价单也必须校验共享单,避免商城/排行改价串改其他客户价格
expect(svc).toContain('先锁报价单条目');
expect(svc).toContain('customer_quote_sheet_customers');
expect(svc).toContain('upsertCustomerSkuPrice');
expect(svc).toContain('synced_customer_sku: target');
expect(svc).toContain('INSERT INTO customer_skus');
expect(svc).toContain('customer_sku_sale_price_update');
expect(svc).not.toMatch(/UPDATE orders|INSERT INTO order_items|inventory|settlement/i);
+2 -2
View File
@@ -197,8 +197,8 @@ const MallCard: React.FC<MallCardProps> = ({
}
setPending((n) => n + 1);
try {
// 改价复用既有入口:执行中报价单里有该商品 → 写报价单条目;
// 没有报价单 → 写客户商品库。
// 改价复用既有入口:执行中报价单里有该商品 → 写报价单条目并回写客户商品库;
// 没有报价单 → 只写客户商品库。
await setCustomerSkuSalePriceApi({
customerCode,
sku_code: item.sku_code,