feat(cost-center): 卡券商品创建即生成渠道规则,补齐成本项预设
- 新建 tpv: 商品时自动写 third_party_voucher 规则,避免新卡券 SKU 停在待分类 - 成本项预设新增「第三方卡券采购成本」
This commit is contained in:
@@ -553,6 +553,25 @@ export const CHANNEL_RULE_KEY_TYPES = MATCH_KEY_TYPES
|
||||
export const CHANNEL_RULE_SOURCES = RULE_SOURCES
|
||||
export const CHANNEL_VALUES = FULFILLMENT_CHANNELS
|
||||
|
||||
/** 为单个卡券 SKU 建规则(商品创建时调用,幂等)。 */
|
||||
export async function ensureVoucherRuleForSku(skuCode: string): Promise<boolean> {
|
||||
const key = String(skuCode || '').trim()
|
||||
if (!key) return false
|
||||
const result = await query<{ id: number }>(
|
||||
`
|
||||
INSERT INTO sku_channel_rules (
|
||||
provider, shop_id, match_key_type, match_key, channel, priority,
|
||||
source, enabled, note, created_at, updated_at
|
||||
)
|
||||
VALUES ('', '', 'sku_code', $1, 'third_party_voucher', 70, 'voucher', TRUE, '卡券商品自动生成', NOW(), NOW())
|
||||
ON CONFLICT (provider, shop_id, match_key_type, match_key, channel) DO NOTHING
|
||||
RETURNING id
|
||||
`,
|
||||
[key],
|
||||
)
|
||||
return (result.rowCount || 0) > 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 为卡券商品(tpv: 前缀)批量补渠道规则。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user