refactor(finance)!: 事实维度与接口字段统一改名 channel

- migration 114 将 sales_daily_facts.fulfillment_mode 重命名为 channel
- DTO/查询参数/前端类型从 fulfillmentMode 统一为 channel
- 成本中心类型 FulfillmentMode 更名为 FulfillmentChannel,并补齐卡券/待分类/归档取值
- 销售事实响应分组改为 byChannel
This commit is contained in:
yml2213
2026-10-31 20:26:15 +08:00
parent 657e49f324
commit 6cd6401eca
38 changed files with 220 additions and 208 deletions
@@ -4,7 +4,7 @@
* 把数据库行映射成接口 DTO,并提供「成本模型是否适用于履约方式」这类口径函数。
*/
import { GENERIC_COST_MODELS, PRODUCT_SOURCE_PREFIXES } from './cost-center-constants.js'
import type { FulfillmentMode } from './cost-center-constants.js'
import type { FulfillmentChannel } from './cost-center-constants.js'
import { parseJsonObject } from './cost-center-normalizers.js'
import type {
CostExceptionDraft,
@@ -49,12 +49,12 @@ export function productSourceFilterSql(paramIndex: number, column = 'p.canonical
* 专属模型只对对应履约方式生效;通用模型(平台费/支付费/售后损失/其他)
* 对所有履约方式生效。
*/
export function costModelAppliesTo(costModel: string, fulfillmentMode: string) {
export function costModelAppliesTo(costModel: string, channel: string) {
if ((GENERIC_COST_MODELS as readonly string[]).includes(costModel)) return true
if (costModel === 'affiliate_purchase') return fulfillmentMode === 'affiliate_dash'
if (costModel === 'work_order_reward') return fulfillmentMode === 'work_order'
if (costModel === 'third_party_voucher_cost') return fulfillmentMode === 'third_party_voucher'
if (costModel === 'manual_actual') return fulfillmentMode === 'manual'
if (costModel === 'affiliate_purchase') return channel === 'affiliate_dash'
if (costModel === 'work_order_reward') return channel === 'work_order'
if (costModel === 'third_party_voucher_cost') return channel === 'third_party_voucher'
if (costModel === 'manual_actual') return channel === 'manual'
return false
}
@@ -62,17 +62,17 @@ export function costModelAppliesTo(costModel: string, fulfillmentMode: string) {
* 成本模型适用范围的 SQL 片段。
* 参数是「履约方式」的 SQL 表达式(可以是占位符 $n,也可以是列引用)。
*/
export function costModelScopeSql(fulfillmentModeExpression: string): string {
export function costModelScopeSql(channelExpression: string): string {
return `(
ci.cost_model IN (${GENERIC_COST_MODELS.map((model) => `'${model}'`).join(', ')})
OR (ci.cost_model = 'affiliate_purchase'
AND ${fulfillmentModeExpression} = 'affiliate_dash')
AND ${channelExpression} = 'affiliate_dash')
OR (ci.cost_model = 'work_order_reward'
AND ${fulfillmentModeExpression} = 'work_order')
AND ${channelExpression} = 'work_order')
OR (ci.cost_model = 'third_party_voucher_cost'
AND ${fulfillmentModeExpression} = 'third_party_voucher')
AND ${channelExpression} = 'third_party_voucher')
OR (ci.cost_model = 'manual_actual'
AND ${fulfillmentModeExpression} = 'manual')
AND ${channelExpression} = 'manual')
)`
}
@@ -225,7 +225,7 @@ export function mapCostException(row: CostExceptionRow) {
subjectId: Number(row.subject_id),
orderItemId: row.order_item_id ? Number(row.order_item_id) : null,
workOrderId: row.work_order_id ? Number(row.work_order_id) : null,
fulfillmentMode: row.fulfillment_mode || '',
channel: row.channel || '',
reason: row.reason,
status: row.status,
detail: parseJsonObject(row.detail_json),
@@ -246,7 +246,7 @@ export type CostPreview = {
shopId: string
skuCode: string
skuName: string
fulfillmentMode: FulfillmentMode
channel: FulfillmentChannel
quantity: number
normalizedQuantity: number
revenueFen: number