fix: 统一利润瀑布口径,与费用总览API一致

profit-waterfall API的received/consumption/discount/store_contribution
改为仅计算has_expense门店(FILTER WHERE has_expense)
修复前: received=6441万(94家) store_contribution=770万
修复后: received=6369万(92家) store_contribution=698万
现在瀑布图和指标卡的贡献利润/食材率/费用率/贡献率完全一致

同时创建数据溯源审计文档,覆盖全部页面的指标溯源和口径对比
This commit is contained in:
freedakgmail
2026-08-11 20:13:58 +08:00
parent 5ffde42590
commit 915345bfd6
2 changed files with 312 additions and 4 deletions
+4 -4
View File
@@ -1068,9 +1068,9 @@ router.get('/overview/profit-waterfall', async (req: AuthRequest, res) => {
WHERE r.month_start = $1 AND r.received IS NOT NULL
)
SELECT
round(sum(consumption)::numeric, 2) AS consumption,
round(sum(discount)::numeric, 2) AS discount,
round(sum(received)::numeric, 2) AS received,
round(sum(consumption) FILTER (WHERE has_expense)::numeric, 2) AS consumption,
round(sum(discount) FILTER (WHERE has_expense)::numeric, 2) AS discount,
round(sum(received) FILTER (WHERE has_expense)::numeric, 2) AS received,
round(sum(actual_food_cost)::numeric, 2) AS food_cost,
round(sum(wage_expense)::numeric, 2) AS wage,
round(sum(rent_expense)::numeric, 2) AS rent,
@@ -1079,7 +1079,7 @@ router.get('/overview/profit-waterfall', async (req: AuthRequest, res) => {
round(sum(delivery_commission_expense)::numeric, 2) AS commission,
round(sum(card_fee_expense + repair_clean_expense)::numeric, 2) AS other_expense,
round(sum(operating_expense)::numeric, 2) AS total_expense,
round(sum(received) - sum(actual_food_cost) - sum(operating_expense), 2) AS store_contribution,
round(sum(received) FILTER (WHERE has_expense) - sum(actual_food_cost) - sum(operating_expense), 2) AS store_contribution,
count(*) AS covered_stores,
count(*) FILTER (WHERE has_expense) AS stores_with_expense
FROM full_scope