ck 4 lat temu
rodzic
commit
c0babc48e2

+ 75 - 0
data_manage/analysis_select.py

@@ -0,0 +1,75 @@
+from model.UserAuthUtils import super_auth,get_auth_channel
+from model.CommonUtils import getLimitSumData,get_dict_list
+from model.DataBaseUtils import CkUtils
+
+
+def channel_analysis_select(arg):
+    """公众号订单跟踪查询"""
+    ck = CkUtils()
+    start = arg.get("start")
+    end = arg.get("end")
+    st = arg.get("st")
+    et = arg.get("et")
+    channel = arg.get("channel")
+    user_id = arg.get('user_id')
+    page = arg.get("page")
+    page_size = arg.get("page_size")
+    order_by = arg.get("order_by", 'cost')
+    order = arg.get("order", 'desc')
+
+    if not (start and end and st and et):
+        return {}
+    if user_id in super_auth():
+        op = ''
+    else:
+        op = f' and channel in {tuple(get_auth_channel(user_id))}'
+
+    op1 = f" and channel in {tuple(channel.split(','))}" if channel else ''
+
+    op2 = f" order by {order_by} {order}" if order_by and order else ''
+
+    op3 = f" limit {(page - 1) * page_size},{page_size} " if (page and page_size) else ''
+
+
+
+    sql = f"""
+            select a.channel,cost,amount from
+            (select channel,round(sum(cost),2) cost  from dw_daily_channel_cost
+                where  dt>='{start}' and dt<='{end}' {op} {op1} group by channel) a
+                left join
+            (select channel,round(sum(amount),2) amount from `order` where date>='{st}' and date<='{et}'  and
+            formatDateTime(reg_time,'%Y-%m-%d')>='{start}' and formatDateTime(reg_time,'%Y-%m-%d')<='{end}' {op} {op1}
+            group by channel) b
+            using (channel) {op2} {op3}"""
+    print(sql)
+    data = get_dict_list(['channel','cost','amount'],ck.getDataList(sql))
+    sum_sql = f"""select round(sum(cost),2) cost,round(sum(amount),2) amount from ({sql}) a"""
+    total_data = get_dict_list(['cost','amount'],ck.getDataList(sum_sql))
+    total_sql = f"""select count(1) from ({sql}) a"""
+    total = ck.getDataOne(total_sql)
+    # print(total_data,total)
+    return {"data":data,"total_data":total_data,"total":total}
+
+
+def channel_analysis_select_daily(arg):
+    ck = CkUtils()
+    start = arg.get("start")
+    end = arg.get("end")
+    st = arg.get("st")
+    et = arg.get("et")
+    channel = arg.get("channel")
+    if not (start and end and st and et and channel):
+        return {}
+
+
+    sql = f"""select formatDateTime(date,'%Y-%m-%d'),round(sum(amount),2) from `order` where formatDateTime(reg_time,'%Y-%m-%d')>='{start}' and formatDateTime(reg_time,'%Y-%m-%d')<='{end}'
+            and date>='{st}' and date<='{et}' and channel = '{channel}'
+            group by date order by date desc limit 10"""
+
+    data = get_dict_list(['dt','amount'],ck.getDataList(sql))
+    # print(data)
+    return {"data": data}
+
+if __name__ == '__main__':
+    arg={"channel":"白雁阅读",'start':'2021-03-01','end':'2021-03-10','st':'2021-04-01','et':'2021-04-10'}
+    channel_analysis_select_daily(arg)

+ 5 - 3
handlers/AnalysisHandler.py

@@ -2,14 +2,15 @@ from handlers.HandlerBase import BaseHandler
 from model.DataBaseUtils import MysqlUtils
 from model.DataBaseUtils import MysqlUtils
 import json
 import json
 import requests
 import requests
-from data_manage.operate import *
+from data_manage.analysis_select import *
 from model.DataBaseUtils import MysqlUtils
 from model.DataBaseUtils import MysqlUtils
 db = MysqlUtils()
 db = MysqlUtils()
 
 
 
 
 class ChannelAnalysisHandler(BaseHandler):
 class ChannelAnalysisHandler(BaseHandler):
     APP_MAP = {
     APP_MAP = {
-        "user_channel": user_channel,
+        "channel_order_track": channel_analysis_select,
+        "channel_order_track_daily": channel_analysis_select_daily,
 
 
     }
     }
 
 
@@ -20,8 +21,9 @@ class ChannelAnalysisHandler(BaseHandler):
         print(arg)
         print(arg)
         try:
         try:
             data = self.run(arg)
             data = self.run(arg)
+            print(data)
 
 
-            self.write_json(data=data)
+            self.write_json(data=data.get("data"),total=data.get('total',1),total_data=data.get('total_data',{}))
         except Exception as e:
         except Exception as e:
             print(e)
             print(e)
             self.write_fail()
             self.write_fail()

+ 8 - 0
model/DataBaseUtils.py

@@ -84,6 +84,14 @@ class CkUtils:
 
 
         return self.client.execute(sql)
         return self.client.execute(sql)
 
 
+    def getDataList(self,sql):
+        data = self.client.execute(sql)
+        return [list(i) for i in data]
+
+    def getDataOne(self,sql):
+        data = self.client.execute(sql)
+        return data[0][0]
+
     def getData_pd(self, sql, col):
     def getData_pd(self, sql, col):
         """
         """
 
 

+ 1 - 1
urls.py

@@ -53,7 +53,7 @@ urls = [
     (r'/operate/channel_group.*', OperateHandler.ChannelGroupHandler),  # 公众号分组设置
     (r'/operate/channel_group.*', OperateHandler.ChannelGroupHandler),  # 公众号分组设置
 
 
     # 自助分析
     # 自助分析
-    (r'/data/analysis.*', AnalysisHandler.ChannelAnalysisHandler),  # 公众号分组设置
+    (r'/data/analysis.*', AnalysisHandler.ChannelAnalysisHandler),