From 64c5230aa85bb98b1290a33e620595c558a94ba6 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 28 Oct 2026 20:30:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=95=86=E5=9F=8E=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=8A=A5=E4=BB=B7=E5=8D=95=E6=94=B9=E4=BB=B7=E5=9B=9E=E5=86=99?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=95=86=E5=93=81=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 按配送系统口径:报价单内商品改价同时写 customer_skus.sale_price;不在报价单只写客户商品库;保留共享报价单并发锁。 --- .../src/services/customerSkuPriceService.ts | 36 +++++++++++++++++++ server/tests/customerSkuPriceEdit.test.ts | 2 ++ src/pages/customers/MallManagement.tsx | 4 +-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/server/src/services/customerSkuPriceService.ts b/server/src/services/customerSkuPriceService.ts index f3cae1a..1ac35d6 100644 --- a/server/src/services/customerSkuPriceService.ts +++ b/server/src/services/customerSkuPriceService.ts @@ -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 { + 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', diff --git a/server/tests/customerSkuPriceEdit.test.ts b/server/tests/customerSkuPriceEdit.test.ts index 96aec56..841a869 100644 --- a/server/tests/customerSkuPriceEdit.test.ts +++ b/server/tests/customerSkuPriceEdit.test.ts @@ -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); diff --git a/src/pages/customers/MallManagement.tsx b/src/pages/customers/MallManagement.tsx index f69f882..47c322e 100644 --- a/src/pages/customers/MallManagement.tsx +++ b/src/pages/customers/MallManagement.tsx @@ -197,8 +197,8 @@ const MallCard: React.FC = ({ } setPending((n) => n + 1); try { - // 改价复用既有入口:执行中报价单里有该商品 → 写报价单条目; - // 没有报价单 → 写客户商品库。 + // 改价复用既有入口:执行中报价单里有该商品 → 写报价单条目并回写客户商品库; + // 没有报价单 → 只写客户商品库。 await setCustomerSkuSalePriceApi({ customerCode, sku_code: item.sku_code,