cxyu 3 лет назад
Родитель
Сommit
24c0e5f5c8
2 измененных файлов с 42 добавлено и 22 удалено
  1. 20 16
      handlers/OrderHandler.py
  2. 22 6
      model/UserAuthUtils.py

+ 20 - 16
handlers/OrderHandler.py

@@ -106,7 +106,7 @@ class OrderInfoNobody(BaseHandler):
                             sum(if(agent='当日总量',sum_amount,0)) as all_order
                             from 
                             (select sum(amount) sum_amount,toDate(FROM_UNIXTIME(a.create_time)) dt,
-                            b.name ,if(a.agent_id in ('sdk_one_0','sdk_two_0'),'自然流量','买量流量') as agent 
+                            b.name ,if(a.agent_id in ('sdk_one_0','sdk_two_0','sdk_three_0'),'自然流量','买量流量') as agent 
                             from GameDataSum.h_pay_sum a 
                             left join GameDataSum.h_game_sum b on a.app_id = b.id
                             where a.status = 2 {op}
@@ -227,12 +227,13 @@ class OrderInfo(BaseHandler):
             op_base = f' and if( h.start_date is not null,d.create_time >= toUnixTimestamp(toDateTime(start_date)),1) '
 
             # 限制为自己游戏的1.自然流量,2.客服流量
+
             if agent_name and ('自然流量渠道' in agent_name or '客服渠道' in agent_name):
                 game_ids = get_auth_game_info(user_id)
                 print(game_ids)
                 op_game = ''
                 for game_id, game_name, 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 = op_game + f'''or (e.id = {game_id} and a.create_time >{game_timestamp} ) '''
                 op_game = ' and ' + '(' + op_game[2:] + ')' + op_base
             # 限制为自己公众号开始时候的数据
 
@@ -263,11 +264,11 @@ class OrderInfo(BaseHandler):
         op12_user = ''
         # 有自然流量和客服渠道时,其他渠道进行规避
         if agent_name and '自然流量渠道' in agent_name and '客服渠道' in agent_name:
-            op12_pay = f" and agent_id in (12,0) "
+            op12_pay = f" and agent_id in ('sdk_one_12','sdk_two_12','sdk_three_12','sdk_one_0','sdk_two_0','sdk_three_0') "
         elif agent_name and '自然流量渠道' in agent_name:
-            op12_pay = f" and agent_id=0 "
+            op12_pay = f" and agent_id in ('sdk_one_0','sdk_two_0','sdk_three_0')  "
         elif agent_name and '客服渠道' in agent_name:
-            op12_pay = f" and agent_id=12 "
+            op12_pay = f" and agent_id in ('sdk_one_12','sdk_two_12','sdk_three_12') "
         else:
             op12_user = f''' where user_nicename in ({"'" + "','".join(agent_name) + "'"}) ''' if agent_name else ''
 
@@ -332,6 +333,7 @@ class OrderInfo(BaseHandler):
                 {op} {op1} {op5}
               {op15}
             """
+
         limit_start = (page - 1) * page_size
         limit_sql = sql + '\n' + f''' limit {limit_start},{page_size} '''
         print(limit_sql)
@@ -453,7 +455,7 @@ class OrderH5Info(BaseHandler):
             (select toDate(FROM_UNIXTIME(a.create_time)) dt,a.app_id as app_id ,
                 min(b.name) as h5_game_name,
                 min(c.app_id) as c_app_id,d.name as channel_game_name,
-                if(min(c.agent_id) in ('sdk_one_0','sdk_two_0'),1,0) as is_natural ,
+                if(min(c.agent_id) in ('sdk_one_0','sdk_two_0','sdk_three_0'),1,0) as is_natural ,
                 sum(amount) as sum_amount,count(DISTINCT(a.mem_id)) as human_counts
                 from (select * from GameDataSum.h_pay_sum where 1=1  {op1} {op2} ) a
                 LEFT  join GameDataSum.h_game_sum b on a.app_id = b.id
@@ -465,7 +467,7 @@ class OrderH5Info(BaseHandler):
                 and c.id is not null
                 and a.status = 2
                 group by toDate(FROM_UNIXTIME(a.create_time)),a.app_id ,
-                c.app_id ,d.name,if(c.agent_id in ('sdk_one_0','sdk_two_0'),1,0) ) as a
+                c.app_id ,d.name,if(c.agent_id in ('sdk_one_0','sdk_two_0','sdk_three_0'),1,0) ) as a
             left join
             (select toDate(FROM_UNIXTIME(a.create_time)) as dt,a.app_id ,
                 sum(a.amount) sum_amount, 
@@ -573,7 +575,7 @@ class OrderH5Info(BaseHandler):
        (select toDate(FROM_UNIXTIME(a.create_time)) dt,a.app_id as app_id ,
                 min(b.name) as h5_game_name,
                 min(c.app_id) as c_app_id,d.name as channel_game_name,
-                if(min(c.agent_id) in ('sdk_one_0','sdk_two_0'),1,0) as is_natural ,
+                if(min(c.agent_id) in ('sdk_one_0','sdk_two_0','sdk_three_0'),1,0) as is_natural ,
                 sum(amount) as sum_amount,count(DISTINCT(a.mem_id)) as human_counts
                 from (select * from GameDataSum.h_pay_sum where 1=1  {op1} {op2} ) a
                 LEFT  join GameDataSum.h_game_sum b on a.app_id = b.id
@@ -585,7 +587,7 @@ class OrderH5Info(BaseHandler):
                 and a.app_id != c.app_id 
                 and a.status = 2
                 group by toDate(FROM_UNIXTIME(a.create_time)),a.app_id ,
-                c.app_id ,d.name,if(c.agent_id in ('sdk_one_0','sdk_two_0'),1,0) ) as a
+                c.app_id ,d.name,if(c.agent_id in ('sdk_one_0','sdk_two_0','sdk_three_0'),1,0) ) as a
             left join
             (select toDate(FROM_UNIXTIME(a.create_time)) as dt,a.app_id ,
                 sum(a.amount) sum_amount, 
@@ -664,10 +666,10 @@ class OrderH5InfoSpecial(BaseHandler):
 
         sql = f'''
       select a.order_id ,h.pitcher,
-            if(a.agent_id in ('sdk_one_21','sdk_two_21'),
-                    '客服渠道',if(a.agent_id in ('sdk_one_0','sdk_two_0'),'自然流量',q.user_nicename)) as agent_name,
-            if(a.agent_id in ('sdk_one_21','sdk_two_21'),
-                    '客服渠道',if(a.agent_id in ('sdk_one_0','sdk_two_0'),'自然流量',c.wx_name)) as channel,
+            if(a.agent_id in ('sdk_one_21','sdk_two_21','sdk_three_21'),
+                    '客服渠道',if(a.agent_id in ('sdk_one_0','sdk_two_0','sdk_three_0'),'自然流量',q.user_nicename)) as agent_name,
+            if(a.agent_id in ('sdk_one_21','sdk_two_21','sdk_three_21'),
+                    '客服渠道',if(a.agent_id in ('sdk_one_0','sdk_two_0','sdk_three_0'),'自然流量',c.wx_name)) as channel,
              formatDateTime(FROM_UNIXTIME(a.create_time),'%Y-%m-%d %H:%M:%S') order_time,
             formatDateTime(FROM_UNIXTIME(d.create_time),'%Y-%m-%d %H:%M:%S') user_create_time,
             e2.name as source_game,
@@ -694,10 +696,12 @@ class OrderH5InfoSpecial(BaseHandler):
             left join GameDataSum.h_user_sum q on a.agent_id =q.id 
             where
              a.app_id not in('sdk_one_6','sdk_one_13','sdk_one_23',
-            				'sdk_two_6','sdk_two_13','sdk_two_23')
-            and a.agent_id in( 'sdk_two_0','sdk_one_0')
+            				'sdk_two_6','sdk_two_13','sdk_two_23',
+            				'sdk_three_6','sdk_three_13','sdk_three_23')
+            and a.agent_id in( 'sdk_two_0','sdk_one_0','sdk_three_0')
             and d.app_id in('sdk_one_6','sdk_one_13','sdk_one_23',
-            				'sdk_two_6','sdk_two_13','sdk_two_23')
+            				'sdk_two_6','sdk_two_13','sdk_two_23',
+            				'sdk_three_6','sdk_three_13','sdk_three_23')
             and a.status =2
             and d.id is not null and g.role_name is not null 
             '''

+ 22 - 6
model/UserAuthUtils.py

@@ -1,4 +1,4 @@
-from model.DataBaseUtils import MysqlUtils
+from model.DataBaseUtils import MysqlUtils,CkUtils
 import base64
 import requests
 import time
@@ -98,7 +98,8 @@ def get_auth_channel(user_id):
 
 def get_auth_game_info(user_id):
     """获取用户拥有的所有用户拥有的游戏"""
-    db = MysqlUtils()
+    ck = CkUtils()
+
     # 1.获取用户名字
     g_time = int(time.time())
     base_url = 'https://api.zanxiangnet.com'
@@ -112,18 +113,33 @@ def get_auth_game_info(user_id):
     for _ in rsp.json()['data']:
         if str(_['userId']) == str(user_id):
             user_name = _['nickName']
+    print(user_name)
     # 2.获取所有游戏id
-    sql = f'''
-    SELECT d.id ,d.name,min(DATE_FORMAT(a.start_date,"%Y-%m-%d"))
+
+    '''
+        SELECT d.id ,d.name,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}' and d.id is not null
         group by id
+        '''
+    sql = f'''
+        
+        SELECT d.id ,d.name,toUnixTimestamp(concat(toString(min(a.start_date)),' 00:00:00'),'Asia/Shanghai')
+       FROM CostSourceData.advertiser_vx a
+		left join GameDataSum.mp_mp_conf_sum b on  a.name =b.wx_name 
+		left join GameDataSum.mp_conf_agent_sum c on c.advertiser_conf_id = b.id
+		left join GameDataSum.h_game_sum d on c.app_id = d.id
+		where LENGTH (d.id)>0  and a.pitcher = '{user_name}'
+        group by d.id,d.name
+        
     '''
-    user_ids = db.quchen_text.get_data_list(sql)
-    return user_ids
+    data_res = ck.execute(sql)
+
+    # user_ids = db.quchen_text.get_data_list(sql)
+    return data_res
 
 
 def get_auth_game_name(user_id):