fix: 修复门店评估数据不一致问题

- 恢复被误删的5家门店旧账单数据(58377行)
- 合并哈马尔罕大钟寺店费用到大钟寺店(0022)
- 修改v_store_operating_expense_monthly视图按sales_store_code聚合费用
- 修复利润机会池食材成本差异为负时opportunity不为负
- 修复前端totalOpportunity只累加正数机会
- 刷新bill_fact/mv_store_risk_rating_monthly等物化视图
- 新增PromotionPage和promotion路由
This commit is contained in:
freedakgmail
2026-08-11 07:26:11 +08:00
parent 353dad24a2
commit 3f1c291486
30 changed files with 4521 additions and 149 deletions
+5 -4
View File
@@ -12,8 +12,9 @@ router.get('/overview', async (req: AuthRequest, res) => {
try {
const month = parseMonth(req)
const result = await query(`
WITH bill_discount AS (
WITH bill_consumption AS (
SELECT store_code,
round(sum(consumption)::numeric, 2) AS consumption,
round(sum(discount_total)::numeric, 2) AS discount
FROM analytics.bill_fact
WHERE closed_at >= $1::date AND closed_at < ($1::date + interval '1 month')
@@ -24,8 +25,8 @@ router.get('/overview', async (req: AuthRequest, res) => {
r.store_code,
r.store_name,
r.received,
e.consumption,
COALESCE(bd.discount, e.consumption - e.received) AS discount,
COALESCE(e.consumption, bc.consumption) AS consumption,
COALESCE(bc.discount, e.consumption - e.received, 0) AS discount,
r.bill_count,
r.theoretical_margin_pct,
e.operating_expense,
@@ -44,7 +45,7 @@ router.get('/overview', async (req: AuthRequest, res) => {
FROM analytics.mv_store_risk_rating_monthly r
LEFT JOIN analytics.mv_store_operating_expense_monthly e
ON r.store_code = e.sales_store_code AND e.report_month = $1::date
LEFT JOIN bill_discount bd ON bd.store_code = r.store_code
LEFT JOIN bill_consumption bc ON bc.store_code = r.store_code
WHERE r.month_start = $1 AND r.received IS NOT NULL
)
SELECT