|
@@ -6,32 +6,37 @@
|
|
|
平台分账与代理商分账是一样的数据,市场经费是代理商分账的一半
|
|
|
*/
|
|
|
|
|
|
-
|
|
|
|
|
|
DROP TABLE IF EXISTS report_agent_income;
|
|
|
+
|
|
|
CREATE TABLE report_agent_income AS
|
|
|
-WITH trans_base AS (
|
|
|
- SELECT
|
|
|
- wtr.district ,
|
|
|
- wtr.trans_time ,
|
|
|
- wtr.wallet_id ,
|
|
|
- wtr.amount ,
|
|
|
- w.owner_id
|
|
|
- FROM wallet_trans_records wtr
|
|
|
- INNER JOIN wallet w ON w.id = wtr.wallet_id
|
|
|
- WHERE wtr.role = '代理商'
|
|
|
- AND wtr.deleted_at IS NULL
|
|
|
-)
|
|
|
-SELECT
|
|
|
+
|
|
|
+DROP VIEW IF EXISTS view_agent_income;
|
|
|
+
|
|
|
+CREATE OR REPLACE VIEW view_agent_income AS
|
|
|
+WITH
|
|
|
+ trans_base AS (
|
|
|
+ SELECT wtr.district , wtr.trans_time , wtr.wallet_id , wtr.amount , w.owner_id
|
|
|
+ FROM
|
|
|
+ wallet_trans_records wtr
|
|
|
+ INNER JOIN wallet w ON w.id = wtr.wallet_id
|
|
|
+ WHERE
|
|
|
+ wtr.role = 6
|
|
|
+ AND wtr.deleted_at IS NULL
|
|
|
+ )
|
|
|
+SELECT
|
|
|
tb.district as district ,
|
|
|
tb.trans_time as trans_time ,
|
|
|
mu.nickname as nickname ,
|
|
|
tb.amount as agent_amount ,
|
|
|
tb.amount as platform_amount ,
|
|
|
tb.amount / 2 as market_amount
|
|
|
-FROM trans_base tb
|
|
|
-INNER JOIN agent_infos ai ON ai.id = tb.owner_id AND ai.deleted_at IS NULL
|
|
|
-INNER JOIN member_users mu ON mu.id = ai.user_id AND mu.deleted_at IS NULL
|
|
|
-ORDER BY
|
|
|
- tb.district,
|
|
|
- tb.trans_time DESC;
|
|
|
+FROM
|
|
|
+ trans_base tb
|
|
|
+ INNER JOIN agent_infos ai ON ai.id = tb.owner_id
|
|
|
+ AND ai.deleted_at IS NULL
|
|
|
+ INNER JOIN member_users mu ON mu.id = ai.user_id
|
|
|
+ AND mu.deleted_at IS NULL
|
|
|
+ORDER BY tb.district, tb.trans_time DESC;
|
|
|
+
|
|
|
+select * from view_agent_income;
|