Browse Source

MOD:渠道添加自然渠道

cxyu 3 years ago
parent
commit
9b22b9c7a4
2 changed files with 46 additions and 14 deletions
  1. 21 13
      handlers/OrderHandler.py
  2. 25 1
      model/UserAuthUtils.py

+ 21 - 13
handlers/OrderHandler.py

@@ -3,7 +3,7 @@ import time
 from model.DataBaseUtils import *
 from model.CommonUtils import *
 from model import UserAuthUtils
-from model.UserAuthUtils import super_auth
+from model.UserAuthUtils import super_auth, get_auth_game_info
 from model.DateUtils import DateUtils
 from datetime import datetime, timedelta
 
@@ -130,11 +130,16 @@ class OrderInfo(BaseHandler):
             op_game = ''
         else:
             op_game = ''
-            op_base = f' and j.game_name is not null and d.create_time >= j.create_time '
+            op_base = f' and if( h.start_date is not null,d.create_time >= UNIX_TIMESTAMP( h.start_date),1) '
 
             # 限制为自己游戏的1.自然流量,2.客服流量
             if agent_name and ('自然流量渠道' in agent_name or '客服渠道' in agent_name):
-                op_game = '' + op_base
+                game_ids = get_auth_game_info(user_id)
+                print(game_ids)
+                op_game = ''
+                for game_id, game_timestamp in game_ids:
+                    op_game = op_game + f'''or (e.id = {game_id} and a.create_time >UNIX_TIMESTAMP('{game_timestamp}') ) '''
+                op_game = ' and ' + '(' + op_game[2:] + ')' + op_base
             # 限制为自己公众号开始时候的数据
 
             if len(UserAuthUtils.get_auth_channel(user_id)) == 0:
@@ -160,7 +165,7 @@ class OrderInfo(BaseHandler):
         op10 = f" and a.status={status} " if status else ''
         op11 = f" and e.name='{game}'" if game else ''
 
-        #有自然流量和客服渠道时,其他渠道进行规避
+        # 有自然流量和客服渠道时,其他渠道进行规避
         if agent_name and '自然流量渠道' in agent_name and '客服渠道' in agent_name:
             op12 = f" and a.agent_id in (12,0) "
         elif agent_name and '自然流量渠道' in agent_name:
@@ -207,16 +212,8 @@ class OrderInfo(BaseHandler):
                         left join db_mp.h_mg_role g 
                         	on g.role_id = f.role_id and g.server_id = f.server_id 
                         	and g.app_id = a.app_id and g.mg_mem_id =a.mg_mem_id 
-                        left join quchen_text.advertiser_vx h on c.wx_name = h.name 
+                        left join quchen_text.advertiser_vx h on c.wx_name = h.name
                         left join db_mp.h_user q on a.agent_id =q.id 
-                        left join (
-                                SELECT a.pitcher as pitcher ,a.name as channel ,
-                                d.name as game_name, UNIX_TIMESTAMP(a.start_date) as create_time 
-                                FROM quchen_text.advertiser_vx a
-                                left join db_mp.mp_mp_conf b on  a.name =b.wx_name 
-                                left join db_mp.mp_conf_agent c on c.advertiser_conf_id = b.id
-                                left join db_mp.h_game d on c.app_id = d.id
-                                ) j on e.name = j.game_name
 
                         
                         where 1=1  {op} {op1} {op2} {op3} {op4} {op5}  
@@ -237,3 +234,14 @@ class OrderInfo(BaseHandler):
 
         print(len(data))
         return data, total, total_data
+
+    def get_game_pitcher(self, user_id):
+        sql = '''
+        SELECT d.name as game_name,d.id 
+    	FROM quchen_text.advertiser_vx a
+                                left join db_mp.mp_mp_conf b on  a.name =b.wx_name 
+                                left join db_mp.mp_conf_agent c on c.advertiser_conf_id = b.id
+                                left join db_mp.h_game d on c.app_id = d.id
+        where pitcher ='金康'
+        group by id
+        '''

+ 25 - 1
model/UserAuthUtils.py

@@ -43,6 +43,29 @@ def get_auth_channel(user_id):
     return tuple(data1 + data3)
 
 
+def get_auth_game_info(user_id):
+    """获取用户拥有的所有用户拥有的游戏"""
+    db = MysqlUtils()
+    # 1.获取用户名字
+    rsp = requests.get('http://api.zanxiangnet.com/erp/api/user/search/3?powerLevelMin=0')
+    user_name = None
+    for _ in rsp.json()['data']:
+        if str(_['userId']) == str(user_id):
+            user_name = _['nickName']
+    # 2.获取所有游戏id
+    sql = f'''
+    SELECT d.id ,min(DATE_FORMAT(a.start_date,"%Y-%m-%d"))
+	FROM quchen_text.advertiser_vx a
+                                left join db_mp.mp_mp_conf b on  a.name =b.wx_name 
+                                left join db_mp.mp_conf_agent c on c.advertiser_conf_id = b.id
+                                left join db_mp.h_game d on c.app_id = d.id
+        where pitcher ='{user_name}'
+        group by id
+    '''
+    user_ids = db.quchen_text.get_data_list(sql)
+    return user_ids
+
+
 def super_auth():
     "获取超级数据权限的用户列表"
     rsp = requests.get('http://api.zanxiangnet.com/erp/api/user/search/3?powerLevelMin=99')
@@ -55,4 +78,5 @@ def super_auth():
 if __name__ == '__main__':
     # print(get_auth_channel(109))
     # print(get_role(78))
-    print(f"ssed{tuple([1, 3, 4])}")
+    # print(f"ssed{tuple([1, 3, 4])}")
+    get_auth_game(85)