From 8da669b1fdfe2db3e4742590c9c8672a0e366dc1 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Mon, 2 Nov 2026 13:36:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(finance):=20=E5=8D=A1=E5=88=B8=E5=95=86?= =?UTF-8?q?=E5=93=81=E8=A1=A5=E5=86=85=E9=83=A8=20SKU=20=E8=A7=84=E5=88=99?= =?UTF-8?q?=EF=BC=8C=E5=BE=85=E5=88=86=E7=B1=BB=E8=87=AA=E5=8A=A8=E5=88=86?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 自动创建 tpv: 商品时补渠道能力和 internal_sku 规则 - 迁移 116 为已存在的卡券商品回填内部 SKU 规则 - 同内部中文 SKU 的待分类订单自动进入第三方卡券 --- .../116_voucher_internal_sku_backfill.sql | 23 +++++++++++++++++++ .../cost-center/product-normalize-service.ts | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 apps/backend/src/db/migrations/116_voucher_internal_sku_backfill.sql diff --git a/apps/backend/src/db/migrations/116_voucher_internal_sku_backfill.sql b/apps/backend/src/db/migrations/116_voucher_internal_sku_backfill.sql new file mode 100644 index 00000000..0a014b25 --- /dev/null +++ b/apps/backend/src/db/migrations/116_voucher_internal_sku_backfill.sql @@ -0,0 +1,23 @@ +-- 116_voucher_internal_sku_backfill.sql +-- +-- 为已存在的三方卡券商品补齐渠道能力和内部中文 SKU 规则: +-- 卡券商品可能是自动创建后才补的迁移,旧商品没有 capability; +-- 补齐后同内部 SKU 的不同平台码会由 channel_assign 自动分流到卡券渠道。 + +INSERT INTO product_channel_capabilities (product_id, channel, priority, is_fallback, enabled, source) +SELECT p.id, 'third_party_voucher', 10, FALSE, TRUE, 'backfill' +FROM product_catalog p +WHERE p.status = 'active' AND p.canonical_sku LIKE 'tpv:%' +ON CONFLICT (product_id, channel) DO NOTHING; + +INSERT INTO sku_channel_rules ( + provider, shop_id, match_key_type, match_key, channel, priority, + source, enabled, note, created_at, updated_at +) +SELECT '', '', 'internal_sku', btrim(p.canonical_name), 'third_party_voucher', 10, + 'voucher', TRUE, '卡券商品内部SKU回填', NOW(), NOW() +FROM product_catalog p +WHERE p.status = 'active' + AND p.canonical_sku LIKE 'tpv:%' + AND btrim(p.canonical_name) <> '' +ON CONFLICT (provider, shop_id, match_key_type, match_key, channel) DO NOTHING; diff --git a/apps/backend/src/services/cost-center/product-normalize-service.ts b/apps/backend/src/services/cost-center/product-normalize-service.ts index 9403ff05..de89759c 100644 --- a/apps/backend/src/services/cost-center/product-normalize-service.ts +++ b/apps/backend/src/services/cost-center/product-normalize-service.ts @@ -182,6 +182,29 @@ async function ensureVoucherProductForItem(item: ItemRow): Promise