Sfoglia il codice sorgente

Merge branch 'dev'

ck 4 anni fa
parent
commit
15f12eaeed

+ 77 - 14
data_manage/pitcher_panel.py

@@ -600,20 +600,84 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
     if user_id in super_auth():  # 超级数据权限
         op = ''
     else:
-        user_name = UserAuthUtils.get_user_name_by_id(user_id)
-        auth_user_li = UserAuthUtils.get_auth_user(user_id)
-        if len(UserAuthUtils.get_auth_user(user_id)) == 0: # 属于普通用户
-            op = f" and pitcher='{user_name}'"
-        else:
-            op = f" and pitcher in {tuple(auth_user_li+[user_name])}"
+        channel_li = UserAuthUtils.get_auth_channel(user_id)
+        print(channel_li.__len__())
+        op = f" and a.channel in {tuple(channel_li)}"
 
     op1=f" and a.channel='{channel}'" if channel else ''
     op2=f" and pitcher='{pitcher}'" if pitcher else ''
-    op4=f" and location='{location}' " if location else ''
     op5=f" and state='{state}'" if state else ''
     op6=f" and a.dt>='{start}'" if start else ''
-    op7=f" and a.dt<='{end}'" if end else ''
+    op7 =f" and a.dt<='{end}'" if end else ''
+
+
+    sql = f"""SELECT channel,
+                if(end>date_sub(now(),interval 10 day),'在投','停投') state,
+                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,
+                td_amount,yd_amount,byd_amount
+            FROM
+                (select
+                    channel,
+                    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,
+                    sum(ba1) td_amount,sum(ba2) yd_amount,sum(ba3) byd_amount
+            
+               from  dw_channel  a 
+                left join dw_channel_amount_daily_reverse b using (dt,channel)
+                where 1=1 {op} {op1} {op2}  {op6} {op7} GROUP BY a.channel) x
+                having 1=1   {op5}  ORDER BY {order_by} {order}
+                
+                """
+    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,
+            sum(order_user) order_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 ,
+            sum(td_amount) td_amount,sum(yd_amount) yd_amount,sum(byd_amount) byd_amount
+            from ({sql}) a
+            
+    """
+
+    return getLimitSumData(db.dm,sql,sumsql,page,page_size)
+
+
+def get_pitcher_channel_summary(user_id, channel, pitcher, page, page_size, order_by, order, state, location, start, end):
+    """投手投放号"""
+
+    db = MysqlUtils()
+
+    if user_id in super_auth():  # 超级数据权限
+        op = ''
+    else:
+        user_name_li = UserAuthUtils.get_auth_user(user_id)
+        if len(user_name_li) == 1:
+            op = f" and pitcher='{user_name_li[0]}'"
+        else:
+            op = f" and pitcher in {tuple(user_name_li)}"
 
+    op1 = f" and a.channel='{channel}'" if channel else ''
+    op2 = f" and pitcher='{pitcher}'" if pitcher else ''
+    op4 = f" and location='{location}' " if location else ''
+    op5 = f" and state='{state}'" if state else ''
+    op6 = f" and a.dt>='{start}'" if start else ''
+    op7 = f" and a.dt<='{end}'" if end else ''
 
     sql = f"""SELECT channel,
                 if(end>date_sub(now(),interval 10 day),'在投','停投') state,
@@ -637,16 +701,15 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
                     sum(follow_user) follow_user,
 					sum(reg_order_user) order_user,
                     sum(ba1) td_amount,sum(ba2) yd_amount,sum(ba3) byd_amount
-            
+
                from  dw_channel  a 
                 left join dw_channel_amount_daily_reverse b using (dt,channel)
                 where 1=1 {op} {op1} {op2}  {op6} {op7} GROUP BY a.channel,type,pitcher,stage) x
                 having 1=1  {op4} {op5}  ORDER BY {order_by} {order}
-                
-                
+
                 """
     print(sql)
-    sumsql=f"""select '总计' channel,
+    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,
@@ -657,10 +720,10 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
             round(sum(total_cost)/sum(order_user),2)  order_tran_cost ,
             sum(td_amount) td_amount,sum(yd_amount) yd_amount,sum(byd_amount) byd_amount
             from ({sql}) a
-            
+
     """
 
-    return getLimitSumData(db.dm,sql,sumsql,page,page_size)
+    return getLimitSumData(db.dm, sql, sumsql, page, page_size)
 
 
 def get_pitcher_trend(pitcher,start=None,end=None,page=None,page_size=None,order_by=None,order=None):

+ 6 - 5
data_manage/public_analysis.py

@@ -19,7 +19,7 @@ def book_rank(start,end,book,stage,type,page,page_size,order_by,order):
 
     sql=f"""select 
 concat(DATE_FORMAT(min(dt),'%Y/%m/%d') ,'~',DATE_FORMAT(max(dt),'%Y/%m/%d')) date,
-pitcher,book,stage,type,
+pitcher,book,stage,type,channel,
 sum(cost) cost,
 sum(view_count) view_count,
 sum(click_count) click_count,
@@ -386,7 +386,7 @@ def pitcher_overview(user_id,start, end, pitcher, page, page_size, order_by, ord
 
 
 
-def boss_panel_summary(user_id,start,end,pitcher, type, stage, page, page_size, order_by, order):
+def boss_panel_summary(user_id,start,end,channel,pitcher, type, stage, page, page_size, order_by, order):
 
     if user_id in super_auth():
         op = ''
@@ -401,13 +401,14 @@ def boss_panel_summary(user_id,start,end,pitcher, type, stage, page, page_size,
     op3 = f" and dt<='{end}' " if end else ''
     op4 = f" and type='{type}' " if type else ''
     op5= f" and stage='{stage}' " if stage else ''
-    op6 = f" order by {order_by} {order}" if order_by and order else 'order by dt desc'
+    op6 = f" and channel='{channel}' " if stage else ''
+    op7 = f" order by {order_by} {order}" if order_by and order else 'order by dt desc'
 
     dm = MysqlUtils().dm
 
     sql=f"""select sum(order_amount) order_amount,sum(cost) cost,dt from dw_channel                                                                                                                                                                                                                                                                                                                                             
-    where 1=1 {op} {op1} {op2} {op3} {op4} {op5}
-    GROUP BY dt HAVING order_amount+cost>0 {op6} """
+    where 1=1 {op} {op1} {op2} {op3} {op4} {op5} {op6}
+    GROUP BY dt HAVING order_amount+cost>0 {op7} """
     # print(sql)
 
     return getLimitData(dm, sql, page, page_size)

+ 9 - 1
handlers/GitHookHandler.py

@@ -1,7 +1,7 @@
 from handlers.HandlerBase import BaseHandler
 import os
 from model import DingTalkUtils
-
+import json
 
 class DataCenerHook(BaseHandler):
 
@@ -19,3 +19,11 @@ class QcWebHook(BaseHandler):
         val2 = os.popen('cd /root/dev/QcWebServer && git pull')  # dev
         DingTalkUtils.send('QcWebServer代码更新:\n[master]\n '+val.read()+'\n[dev]\n'+val2.read())
         self.write('ok')
+
+
+class GetVersion(BaseHandler):
+    def get(self):
+        version = "v1.2.1"
+        msg = "1.原公众号总数据变为投手数据中投手投放号 2.现公众号总数据一个公众号一条数据 "
+
+        self.write(json.dumps({"version": version, "msg": msg}))

+ 27 - 0
handlers/PitcherPanelHandler.py

@@ -168,6 +168,33 @@ class ChannelSummary(BaseHandler):
             else:
                 self.write_json(data=data, total=total, total_data=total_data)
 
+
+class ChannelPitcherSummary(BaseHandler):
+    def post(self):
+
+        if not self._au:
+            self.write_fail(msg='auth error')
+        else:
+            arg = self.get_args()
+            print(arg)
+            user_id = arg.get('user_id')
+            channel = arg.get('channel')
+            pitcher = arg.get('pitcher')
+            page = arg.get("page")
+            page_size = arg.get("page_size")
+            location = arg.get('location')
+            order_by = arg.get("order_by", 'total_cost')
+            order = arg.get("order", 'desc')
+            state = arg.get("state")
+            start = arg.get("start")
+            end = arg.get("end")
+            data, total, total_data = get_pitcher_channel_summary(user_id,channel, pitcher, page, page_size, order_by, order, state, location,start,end)
+            if arg.get("download"):
+                self.write_download("channel_"+str(int(time.time())), data)
+            else:
+                self.write_json(data=data, total=total, total_data=total_data)
+
+
 class PitcherTrend(BaseHandler):
     def post(self):
         if not self._au:

+ 2 - 1
handlers/PublicAnalysisHandler.py

@@ -119,9 +119,10 @@ class BossPanelSummary(BaseHandler):
             pitcher = arg.get("pitcher")
             type = arg.get("type")
             stage = arg.get("stage")
+            channel = arg.get("channel")
 
             download = arg.get("download")
-            data, total = boss_panel_summary(user_id,start, end, pitcher, type,
+            data, total = boss_panel_summary(user_id,start, end,channel, pitcher, type,
                                              stage, page, page_size, order_by, order)
             if download:
                 self.write_download(str(int(time.time())), data)

+ 6 - 2
model/UserAuthUtils.py

@@ -4,16 +4,20 @@ from model.DataBaseUtils import MysqlUtils
 
 
 def get_auth_user(user_id):
-    """获取用户拥有权限的的用户"""
+    """获取用户拥有所有用户(包括自己)的权限"""
     db = MysqlUtils()
     sql = f"""select b.nick_name from t_sys_user_group_relation a
             left join t_sys_user b USING(user_id)
-            where a.group_id=(select id from t_sys_user_group where del_flag=0 and group_user_id={user_id})"""
+            where a.group_id=(select id from t_sys_user_group where del_flag=0 and group_user_id={user_id})
+            union 
+            select nick_name from t_sys_user where user_id='{user_id}'
+"""
 
     return db.zx.getOneList(sql)
 
 
 def get_auth_channel(user_id):
+    """获取用户拥有的所有公众号权限"""
     db = MysqlUtils()
     sql=f"""select nick_name from t_mp_account where 
     oper_user_id in (select user_id from t_sys_user_group_relation where  group_id=(select id from t_sys_user_group where del_flag=0 and group_user_id={user_id})) or 

+ 2 - 0
urls.py

@@ -7,6 +7,7 @@ from handlers import OperateHandler
 
 
 urls = [
+    (r'/data/version',GetVersion),  # 获取版本号
     (r'/data/pitcher_panel/daily', PitcherPanelDaily),  # 投手日期汇总
     (r'/data/pitcher_panel/overview', PitcherPanelOverview),  # 投手今天概况
     (r'/data/channel_stat/overview', ChannelOverview),  # 公众号广告投放数据
@@ -14,6 +15,7 @@ urls = [
     (r'/data/channel_stat/active', ChannelActive),  # 公众号激活数据
     (r'/data/channel_stat/order_trend', ChannelOrderTrend),  # 公众号趋势
     (r'/data/channel_stat/channel', ChannelSummary),  # 公众号总数据
+    (r'/data/pitcher/channel', ChannelPitcherSummary),  # 投手投放号
     (r'/data/pitcher/trend', PitcherTrend),  # 投手个人付费趋势
 
     # 公共分析