feat: 新增老板驾驶舱页面 - 利润瀑布/风险态势/成本异常/营收排名/日度趋势

This commit is contained in:
freedakgmail
2026-07-30 14:24:17 +08:00
parent 6c5d8ed5d3
commit 22d711fb73
4 changed files with 373 additions and 1 deletions
+40
View File
@@ -499,4 +499,44 @@ router.get('/site-selection/district-benchmark', async (req: AuthRequest, res) =
} catch (err: any) { sendError(res, err.message) }
})
// 利润瀑布数据
router.get('/overview/profit-waterfall', async (req: AuthRequest, res) => {
try {
const result = await query(`
WITH full_scope AS (
SELECT
r.received,
COALESCE(e.actual_food_cost, 0) AS actual_food_cost,
COALESCE(e.wage_expense, 0) AS wage_expense,
COALESCE(e.rent_expense, 0) AS rent_expense,
COALESCE(e.utility_expense, 0) AS utility_expense,
COALESCE(e.dorm_expense, 0) AS dorm_expense,
COALESCE(e.delivery_commission_expense, 0) AS delivery_commission_expense,
COALESCE(e.card_fee_expense, 0) AS card_fee_expense,
COALESCE(e.repair_clean_expense, 0) AS repair_clean_expense,
COALESCE(e.operating_expense, 0) AS operating_expense
FROM analytics.mv_store_risk_rating r
LEFT JOIN analytics.mv_store_operating_expense_monthly e
ON r.store_code = e.sales_store_code AND e.report_month = DATE '2026-04-01'
WHERE r.received IS NOT NULL
)
SELECT
round(sum(received)::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,
round(sum(utility_expense)::numeric, 2) AS utility,
round(sum(dorm_expense)::numeric, 2) AS dorm,
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 net_profit
FROM full_scope
`)
sendSuccess(res, result.rows[0])
} catch (err: any) {
sendError(res, err.message)
}
})
export default router