feat: 全页面增加营业收入/优惠指标 + 修复趋势预测空数据 + 区域对比口径统一 + StorePage最新经营日概览
- 后端: 所有API的discount改为从bill_fact累计discount_total - 后端: revenue/daily-summary增加consumption字段 - 后端: situational-awareness/forecast修复c175字符串比较为timestamp - 后端: region/comparison去掉未知区域排除,统一口径 - 后端: daily-card增加营业收入/优惠指标,返回target_date/baseline_date - 前端: BossPage/DashboardPage/BankPage/StorePage/ExpenseOverviewTab/RegionalPage/RegionComparisonPage/RevenuePage 均增加营业收入和优惠指标卡 - 前端: StorePage日均经营概览改为最新经营日概览,显示具体对比日期 - 前端: 日期格式统一截取YYYY-MM-DD显示
This commit is contained in:
@@ -12,11 +12,20 @@ router.get('/overview', async (req: AuthRequest, res) => {
|
||||
try {
|
||||
const month = parseMonth(req)
|
||||
const result = await query(`
|
||||
WITH full_scope AS (
|
||||
WITH bill_discount AS (
|
||||
SELECT store_code,
|
||||
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')
|
||||
GROUP BY store_code
|
||||
),
|
||||
full_scope AS (
|
||||
SELECT
|
||||
r.store_code,
|
||||
r.store_name,
|
||||
r.received,
|
||||
e.consumption,
|
||||
COALESCE(bd.discount, e.consumption - e.received) AS discount,
|
||||
r.bill_count,
|
||||
r.theoretical_margin_pct,
|
||||
e.operating_expense,
|
||||
@@ -35,6 +44,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
|
||||
WHERE r.month_start = $1 AND r.received IS NOT NULL
|
||||
)
|
||||
SELECT
|
||||
@@ -43,6 +53,8 @@ router.get('/overview', async (req: AuthRequest, res) => {
|
||||
count(*) FILTER (WHERE actual_store_contribution <= 0 AND received > 0 AND actual_store_contribution IS NOT NULL) AS loss_stores,
|
||||
count(*) FILTER (WHERE operating_expense IS NULL) AS no_expense_stores,
|
||||
sum(bill_count)::bigint AS total_bills,
|
||||
round(sum(consumption)::numeric, 2) AS total_consumption,
|
||||
round(sum(discount)::numeric, 2) AS total_discount,
|
||||
round(sum(received)::numeric, 2) AS total_received,
|
||||
round(sum(received) / nullif(sum(bill_count), 0), 2) AS avg_bill_value,
|
||||
round(sum(operating_expense)::numeric, 2) AS total_expense,
|
||||
|
||||
Reference in New Issue
Block a user