feat(finance): 接单模板发单金额落规则级成本版本
此前接单平台成本版本只有 sys_work_order_reward 的全局 0 元占位,662 个模板的发单金额从未进入 cost_versions。\n\n现在为 662 个模板各生成一条规则级版本:634 条固定发单金额 + 28 条按件单价;全局 0 元版本仅作“按工单实际结算”占位。成本版本页新增“用户实付均价”和“平均实发/项”,支持按模板名称/规则键搜索,按商品筛选也能命中规则版本。\n\n历史工单快照关联到对应模板版本;模板保存时自动同步单条成本版本;删除模板会先把历史版本脱钩停用,保留快照可追溯。\n\n新增迁移 112 覆盖索引,用户实付聚合从约 1.1s 降到约 150ms。
This commit is contained in:
@@ -312,6 +312,25 @@ export async function syncOpenWorkOrderPriceFromRule(input: {
|
||||
})
|
||||
}
|
||||
|
||||
export async function detachWorkProductRuleCostVersions(
|
||||
ruleId: number,
|
||||
label: string,
|
||||
): Promise<{ updated: number }> {
|
||||
const result = await query(
|
||||
`
|
||||
UPDATE cost_versions
|
||||
SET work_product_rule_id = NULL,
|
||||
status = 'retired',
|
||||
effective_to = COALESCE(effective_to, NOW()),
|
||||
change_reason = LEFT('已删除模板 ' || $2 || ';' || change_reason, 500),
|
||||
updated_at = NOW()
|
||||
WHERE work_product_rule_id = $1
|
||||
`,
|
||||
[ruleId, label],
|
||||
)
|
||||
return { updated: result.rowCount || 0 }
|
||||
}
|
||||
|
||||
export async function deleteWorkProductRule(
|
||||
ruleId: number | string,
|
||||
): Promise<{ deleted: boolean }> {
|
||||
|
||||
Reference in New Issue
Block a user