feat: 统一SearchSelect下拉组件 + 修复营销方案数据 + 平台经济性增强
- 创建SearchSelect搜索下拉组件,选项≤8自动隐藏搜索框 - 全站替换原生select为SearchSelect(13处下拉) - 修复/revenue/store-ranking优惠率字段名不匹配(discount_rate_pct→avg_discount_rate_pct) - RevenuePage门店营收明细改用FilterableTable支持筛选排序分页 - 修复/marketing/plans按门店分组改为按marketing_plan分组 - 营销方案分析补充消费额、优惠额列和Top5概览卡片 - PlatformPage门店平台经济性增加门店搜索、经济性优列(平台分色) - 平台成本率算法说明显示在标题下方
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
DROP MATERIALIZED VIEW IF EXISTS mv_risk_anomaly;
|
||||
DROP MATERIALIZED VIEW IF EXISTS mv_risk_cashier;
|
||||
DROP MATERIALIZED VIEW IF EXISTS mv_risk_zero;
|
||||
|
||||
CREATE MATERIALIZED VIEW mv_risk_anomaly AS
|
||||
SELECT
|
||||
c003 AS store_name, c005 AS bill_no, c004 AS meal_period,
|
||||
c009::numeric AS consumption, COALESCE(c068::numeric,0) AS discount_total,
|
||||
(COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)) AS received_total,
|
||||
c191 AS cashier, c176 AS closed_at, c175::timestamp AS bill_time,
|
||||
to_char(c176::timestamp, 'YYYY-MM') AS month,
|
||||
CASE
|
||||
WHEN c009::numeric > 0 AND (COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)) = 0 THEN '有消费无实收'
|
||||
WHEN c068::numeric > c009::numeric THEN '优惠大于消费'
|
||||
WHEN abs(c009::numeric - COALESCE(c068::numeric,0) - (COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0))) > 0.05 THEN '消费-优惠与实收不平'
|
||||
END AS anomaly_reason
|
||||
FROM bill_records
|
||||
WHERE c175 IS NOT NULL AND c175 != '' AND c176 IS NOT NULL AND c176 != ''
|
||||
AND (
|
||||
(c009::numeric > 0 AND (COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)) = 0)
|
||||
OR (c068::numeric > c009::numeric)
|
||||
OR (abs(c009::numeric - COALESCE(c068::numeric,0) - (COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0))) > 0.05)
|
||||
);
|
||||
|
||||
CREATE MATERIALIZED VIEW mv_risk_cashier AS
|
||||
SELECT
|
||||
c003 AS store_name, c191 AS cashier,
|
||||
count(*) AS bill_count,
|
||||
round(sum(c009::numeric),2) AS consumption_total,
|
||||
round(sum(COALESCE(c068::numeric,0)),2) AS discount_total,
|
||||
round(sum(COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)),2) AS received,
|
||||
count(*) FILTER (WHERE c009::numeric > 0 AND (COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)) = 0) AS anomaly_no_received,
|
||||
count(*) FILTER (WHERE c068::numeric > c009::numeric) AS anomaly_discount_over,
|
||||
count(*) FILTER (WHERE abs(c009::numeric - COALESCE(c068::numeric,0) - (COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0))) > 0.05) AS anomaly_unbalanced,
|
||||
to_char(c176::timestamp, 'YYYY-MM') AS month
|
||||
FROM bill_records
|
||||
WHERE c175 IS NOT NULL AND c175 != '' AND c176 IS NOT NULL AND c176 != ''
|
||||
GROUP BY c003, c191, to_char(c176::timestamp, 'YYYY-MM');
|
||||
|
||||
CREATE MATERIALIZED VIEW mv_risk_zero AS
|
||||
SELECT
|
||||
c003 AS store_name, c005 AS bill_no, c004 AS meal_period,
|
||||
c009::numeric AS consumption, COALESCE(c068::numeric,0) AS discount_total,
|
||||
c191 AS cashier, c176 AS closed_at, c175::timestamp AS bill_time,
|
||||
to_char(c176::timestamp, 'YYYY-MM') AS month,
|
||||
CASE
|
||||
WHEN c009::numeric = 0 AND COALESCE(c068::numeric,0) = 0 THEN '无消费无优惠'
|
||||
WHEN c009::numeric > 0 AND COALESCE(c068::numeric,0) >= c009::numeric THEN '全额优惠'
|
||||
ELSE '其他零实收'
|
||||
END AS zero_received_type
|
||||
FROM bill_records
|
||||
WHERE c175 IS NOT NULL AND c175 != '' AND c176 IS NOT NULL AND c176 != ''
|
||||
AND (COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)) = 0;
|
||||
|
||||
CREATE INDEX idx_mv_anomaly_month ON mv_risk_anomaly (month);
|
||||
CREATE INDEX idx_mv_anomaly_store ON mv_risk_anomaly (store_name);
|
||||
CREATE INDEX idx_mv_anomaly_cashier ON mv_risk_anomaly (cashier);
|
||||
CREATE INDEX idx_mv_anomaly_reason ON mv_risk_anomaly (anomaly_reason);
|
||||
CREATE INDEX idx_mv_cashier_month ON mv_risk_cashier (month);
|
||||
CREATE INDEX idx_mv_zero_month ON mv_risk_zero (month);
|
||||
@@ -0,0 +1,53 @@
|
||||
DROP MATERIALIZED VIEW IF EXISTS mv_time_weekday;
|
||||
DROP MATERIALIZED VIEW IF EXISTS mv_time_hourly;
|
||||
DROP MATERIALIZED VIEW IF EXISTS mv_channel_daily;
|
||||
|
||||
CREATE MATERIALIZED VIEW mv_time_weekday AS
|
||||
SELECT
|
||||
EXTRACT(isodow FROM c176::timestamp)::int AS weekday_no,
|
||||
CASE EXTRACT(isodow FROM c176::timestamp)::int
|
||||
WHEN 1 THEN '周一' WHEN 2 THEN '周二' WHEN 3 THEN '周三'
|
||||
WHEN 4 THEN '周四' WHEN 5 THEN '周五' WHEN 6 THEN '周六' ELSE '周日'
|
||||
END AS weekday,
|
||||
count(*) AS bill_count,
|
||||
round(sum(COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)),2) AS received,
|
||||
round(sum(COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)) / count(*), 2) AS avg_bill_value,
|
||||
round(avg(EXTRACT(epoch FROM (c176::timestamp - c175::timestamp))/60), 2) AS avg_duration_minutes,
|
||||
to_char(c176::timestamp, 'YYYY-MM') AS month
|
||||
FROM bill_records
|
||||
WHERE c176 IS NOT NULL AND c176 != '' AND c175 IS NOT NULL AND c175 != ''
|
||||
GROUP BY 1, 2, to_char(c176::timestamp, 'YYYY-MM');
|
||||
|
||||
CREATE MATERIALIZED VIEW mv_time_hourly AS
|
||||
SELECT
|
||||
EXTRACT(hour FROM c176::timestamp)::int AS closing_hour,
|
||||
count(*) AS bill_count,
|
||||
round(sum(COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)),2) AS received,
|
||||
round(sum(COALESCE(c143::numeric,0)+COALESCE(c144::numeric,0)+COALESCE(c145::numeric,0)+COALESCE(c146::numeric,0)+COALESCE(c147::numeric,0)+COALESCE(c148::numeric,0)+COALESCE(c149::numeric,0)+COALESCE(c150::numeric,0)+COALESCE(c151::numeric,0)+COALESCE(c152::numeric,0)+COALESCE(c153::numeric,0)+COALESCE(c155::numeric,0)+COALESCE(c160::numeric,0)+COALESCE(c161::numeric,0)+COALESCE(c164::numeric,0)+COALESCE(c166::numeric,0)+COALESCE(c169::numeric,0)+COALESCE(c173::numeric,0)+COALESCE(c174::numeric,0)+COALESCE(c118::numeric,0)+COALESCE(c119::numeric,0)+COALESCE(c120::numeric,0)+COALESCE(c121::numeric,0)+COALESCE(c139::numeric,0)+COALESCE(c141::numeric,0)+COALESCE(c142::numeric,0)) / count(*), 2) AS avg_bill_value,
|
||||
round(avg(EXTRACT(epoch FROM (c176::timestamp - c175::timestamp))/60), 2) AS avg_duration_minutes,
|
||||
to_char(c176::timestamp, 'YYYY-MM') AS month
|
||||
FROM bill_records
|
||||
WHERE c176 IS NOT NULL AND c176 != '' AND c175 IS NOT NULL AND c175 != ''
|
||||
GROUP BY 1, to_char(c176::timestamp, 'YYYY-MM');
|
||||
|
||||
CREATE MATERIALIZED VIEW mv_channel_daily AS
|
||||
SELECT
|
||||
c176::date AS business_date,
|
||||
round(sum(c143::numeric),2) AS cash,
|
||||
round(sum(c144::numeric),2) AS alipay,
|
||||
round(sum(c145::numeric),2) AS wechat,
|
||||
round(sum(c146::numeric),2) AS meituan,
|
||||
round(sum(c147::numeric),2) AS unionpay,
|
||||
round(sum(c148::numeric),2) AS douyin,
|
||||
round(sum(c149::numeric),2) AS credit,
|
||||
round(sum(c150::numeric),2) AS jd_delivery,
|
||||
round(sum(c151::numeric),2) AS meituan_delivery,
|
||||
round(sum(c152::numeric),2) AS taobao_delivery,
|
||||
to_char(c176::timestamp, 'YYYY-MM') AS month
|
||||
FROM bill_records
|
||||
WHERE c176 IS NOT NULL AND c176 != ''
|
||||
GROUP BY 1, to_char(c176::timestamp, 'YYYY-MM');
|
||||
|
||||
CREATE INDEX idx_mv_weekday_month ON mv_time_weekday (month);
|
||||
CREATE INDEX idx_mv_hourly_month ON mv_time_hourly (month);
|
||||
CREATE INDEX idx_mv_channel_month ON mv_channel_daily (month);
|
||||
Reference in New Issue
Block a user