ck 4 anni fa
parent
commit
cf07591718
2 ha cambiato i file con 44 aggiunte e 8 eliminazioni
  1. 41 7
      data_manage/pitcher_panel.py
  2. 3 1
      handlers/PitcherPanelHandler.py

+ 41 - 7
data_manage/pitcher_panel.py

@@ -717,7 +717,7 @@ from order where  dt>='{start}' {channel_op}  group by formatDateTime(reg_time,'
 
 
     return data,total
     return data,total
 
 
-def get_channel_summary(channel,pitcher,page,page_size,order_by,order,state,location):
+def get_channel_summary(channel,pitcher,page,page_size,order_by,order,state,location,start,end):
     db=MysqlUtils()
     db=MysqlUtils()
 
 
     op1=f" and channel='{channel}'" if channel else ''
     op1=f" and channel='{channel}'" if channel else ''
@@ -730,13 +730,47 @@ def get_channel_summary(channel,pitcher,page,page_size,order_by,order,state,loca
     op3=f" and channel='{channel}'" if channel else ''
     op3=f" and channel='{channel}'" if channel else ''
     op4=f" and location='{location}' " if location else ''
     op4=f" and location='{location}' " if location else ''
     op5=f" and state='{state}'" if state else ''
     op5=f" and state='{state}'" if state else ''
-
-
-    sql = f"""SELECT * 
-               from dm_channel_summary where 1=1  {op1} {op2} {op3} {op4} {op5}  ORDER BY {order_by} {order}
+    op6=f" and dt>='{start}'" if start else ''
+    op7=f" and dt<='{end}'" if end else ''
+
+
+    sql = f"""SELECT channel,
+                if(end>date_sub(now(),interval 10 day),'在投','停投') state,
+                location,start,end,total_cost,total_amount,
+                total_amount-total_cost profit,
+                if(total_cost=0,0,round(total_amount/total_cost,4)) roi,
+                follow_user,
+                if(follow_user=0,0,round(total_cost/follow_user,2)) follow_per_cost,
+                order_user,
+                if(follow_user=0,0,round(order_user/follow_user,4)) order_tran_rate,
+                if(order_user=0,0,round(total_cost/order_user,2))  order_tran_cost,
+                pitcher,stage
+            FROM
+                (select
+                    channel,pitcher,stage,
+                    case when type ='vx' then 'MP' when type ='qq' then 'GDT' end location,
+                    min(if(cost>0,dt,null)) start,
+                    max(if(cost>0,dt,null)) end,
+                    sum(cost) total_cost,
+                    sum(reg_order_amount) total_amount,
+                    sum(follow_user) follow_user,
+					sum(reg_order_user) order_user
+               from dw_channel_daily   where 1=1 {op1} {op2} {op3} {op4} {op6} {op7} GROUP BY channel,type,pitcher,stage) a where 1=1  {op5}  ORDER BY {order_by} {order}
                 """
                 """
-    print(sql)
-    return getLimitData(db.quchen_text,sql,page,page_size)
+    # print(sql)
+    sumsql=f"""select '总计' channel,
+            sum(total_cost) total_cost,
+            sum(total_amount) total_amount,sum(profit) profit, 
+            round(sum(total_amount)/sum(total_cost),4) roi,
+            sum(follow_user) follow_user,
+            round(sum(total_cost)/sum(follow_user),2) follow_per_cost,
+            round(sum(order_user)/sum(follow_user),4) order_tran_rate,
+            round(sum(total_cost)/sum(order_user),2)  order_tran_cost 
+            from ({sql}) a
+            
+    """
+
+    return getLimitSumData(db.quchen_text,sql,sumsql,page,page_size)
 
 
 
 
 def get_pitcher_trend(pitcher,start=None,end=None,page=None,page_size=None,order_by=None,order=None):
 def get_pitcher_trend(pitcher,start=None,end=None,page=None,page_size=None,order_by=None,order=None):

+ 3 - 1
handlers/PitcherPanelHandler.py

@@ -132,7 +132,9 @@ class ChannelSummary(BaseHandler):
         order_by = arg.get("order_by", 'total_cost')
         order_by = arg.get("order_by", 'total_cost')
         order = arg.get("order", 'desc')
         order = arg.get("order", 'desc')
         state=arg.get("state")
         state=arg.get("state")
-        data,total=get_channel_summary(channel,pitcher,page,page_size,order_by,order,state,location)
+        start=arg.get("start")
+        end=arg.get("end")
+        data,total=get_channel_summary(channel,pitcher,page,page_size,order_by,order,state,location,start,end)
         self.write_json(data=data,total=total)
         self.write_json(data=data,total=total)