feat(cost-center): 第三方卡券渠道归一与采购价配置
- 归一新增 tpv:<SKU> 直达,卡券单无需手工映射 - 成本配置/总览/异常支持 third_party_voucher 与 archived 维度 - 新增卡券采购价面板,写入 sys_third_party_voucher_cost - 修正 man: 商品改价误用不存在的 sys_manual_cost
This commit is contained in:
@@ -567,7 +567,7 @@ export async function listAdminCostExceptions(payload: JsonObject = {}) {
|
||||
params.push(since)
|
||||
clauses.push(`ce.created_at >= $${params.length}::timestamptz`)
|
||||
}
|
||||
// 履约方式筛选:异常表不再存载体,改为 join order_items 读 fulfillment_mode。
|
||||
// 履约渠道筛选:异常表不存渠道,改为 join order_items 读 channel/status。
|
||||
// 用 IN 半连接而不是 EXISTS:248k 异常 × 316k 订单项下,EXISTS 会逐行回表,
|
||||
// 半连接能一次物化候选集合(实测 2.7s -> 0.4s)。
|
||||
const fulfillmentMode = text(payload.fulfillmentMode ?? payload.fulfillment_mode)
|
||||
@@ -576,7 +576,7 @@ export async function listAdminCostExceptions(payload: JsonObject = {}) {
|
||||
params.push(fulfillmentMode)
|
||||
clauses.push(
|
||||
`ce.order_item_id IN (
|
||||
SELECT oi.id FROM order_items oi WHERE oi.fulfillment_mode = $${params.length}
|
||||
SELECT oi.id FROM order_items oi WHERE COALESCE(oi.fulfillment_channel, CASE WHEN oi.fulfillment_status = 'archived' THEN 'archived' ELSE 'pending' END) = $${params.length}
|
||||
)`,
|
||||
)
|
||||
}
|
||||
@@ -591,7 +591,7 @@ export async function listAdminCostExceptions(payload: JsonObject = {}) {
|
||||
`
|
||||
SELECT
|
||||
ce.*,
|
||||
oi.fulfillment_mode
|
||||
COALESCE(oi.fulfillment_channel, CASE WHEN oi.fulfillment_status = 'archived' THEN 'archived' ELSE 'pending' END) AS fulfillment_mode
|
||||
FROM cost_exceptions ce
|
||||
LEFT JOIN order_items oi ON oi.id = ce.order_item_id
|
||||
${where}
|
||||
@@ -635,7 +635,7 @@ export async function summarizeAdminCostExceptions(
|
||||
params.push(fulfillmentMode)
|
||||
clauses.push(
|
||||
`ce.order_item_id IN (
|
||||
SELECT oi.id FROM order_items oi WHERE oi.fulfillment_mode = $${params.length}
|
||||
SELECT oi.id FROM order_items oi WHERE COALESCE(oi.fulfillment_channel, CASE WHEN oi.fulfillment_status = 'archived' THEN 'archived' ELSE 'pending' END) = $${params.length}
|
||||
)`,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user