ck 4 năm trước cách đây
mục cha
commit
7829b26fd8
4 tập tin đã thay đổi với 106 bổ sung11 xóa
  1. 72 9
      data_manage/pitcher_panel.py
  2. 27 0
      handlers/PitcherPanelHandler.py
  3. 6 2
      model/UserAuthUtils.py
  4. 1 0
      urls.py

+ 72 - 9
data_manage/pitcher_panel.py

@@ -600,19 +600,15 @@ 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()
+        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,
@@ -640,10 +636,9 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
             
                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
+                where 1=1 {op} {op1} {op2}  {op6} {op7} GROUP BY a.channel) x
                 having 1=1  {op4} {op5}  ORDER BY {order_by} {order}
                 
-                
                 """
     print(sql)
     sumsql=f"""select '总计' channel,
@@ -663,6 +658,74 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
     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,
+                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,td_amount,yd_amount,byd_amount
+            FROM
+                (select
+                    channel,pitcher,stage,
+                    type  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,
+                    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,
+            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_trend(pitcher,start=None,end=None,page=None,page_size=None,order_by=None,order=None):
 
     db=MysqlUtils()

+ 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_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:

+ 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 

+ 1 - 0
urls.py

@@ -14,6 +14,7 @@ urls = [
     (r'/data/channel_stat/active', ChannelActive),  # 公众号激活数据
     (r'/data/channel_stat/order_trend', ChannelOrderTrend),  # 公众号趋势
     (r'/data/channel_stat/channel', ChannelSummary),  # 公众号总数据
+    (r'/data/pitcher/channelSummary', ChannelPitcherSummary),  # 公众号总数据
     (r'/data/pitcher/trend', PitcherTrend),  # 投手个人付费趋势
 
     # 公共分析