Browse Source

MOD:h5_order_spical

cxyu 3 years ago
parent
commit
6576102e88
1 changed files with 39 additions and 28 deletions
  1. 39 28
      handlers/OrderHandler.py

+ 39 - 28
handlers/OrderHandler.py

@@ -218,7 +218,7 @@ class OrderInfo(BaseHandler):
                        game, agent_name,
                        page, page_size, order_, order_by):
         db = MysqlUtils()
-        # todo:订单之后写个专门的clickhouse订单表,clickhouse的预聚合引擎外加物化视图来做
+        # todo:订单之后写个专门的clickhouse订单表,clickhouse 一小时同步一次
         if user_id in super_auth():
             op_channel = ''
             op_game = ''
@@ -639,50 +639,61 @@ class OrderH5InfoSpecial(BaseHandler):
                 data = self.get_order_info_download(user_id, start, end)
                 self.write_download(str(int(time.time())), data)
             else:
+                data = self.get_order_info_download(user_id, start, end)
+
                 self.write_json(data=data)
 
     def get_order_info_download(self, user_id, start, end):
         if user_id not in super_auth():
             return []
 
-        db = MysqlUtils()
-        op1 = f"and CONVERT(from_unixtime(a.create_time),char(10))>='{start}' " if start else ''
-        op2 = f"and CONVERT(from_unixtime(a.create_time),char(10))<='{end}' " if end else ''
+        ck = CkUtils()
+        du = DateUtils()
+        end = du.getLastDays(end, -1) if end else None  # end 往后面一天
+        start = None if not start else int(datetime.strptime(start, '%Y-%m-%d').timestamp())
+        end = None if not end else int(datetime.strptime(end, '%Y-%m-%d').timestamp())
+
+        op1 = f" and create_time>={start} " if start else ''
+        op2 = f" and create_time<={end} " if end else ''
 
         sql = f'''
-      select row_number() over() as id,a.order_id ,h.pitcher,
-            if(a.agent_id =21,'客服渠道',if(a.agent_id=0,'自然流量',q.user_nicename)) as agent_name,
-            if(a.agent_id =21,'客服渠道',if(a.agent_id=0,'自然流量',c.wx_name)) as channel,
-            if(a.create_time is not null ,CONVERT(from_unixtime(a.create_time),char(20)),null) order_time,
-            if(d.create_time is not null,CONVERT(from_unixtime(d.create_time),char(20)),null) user_create_time,
+      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,
+             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,
             d.id as mem_id,e.name as game ,a.amount ,a.real_amount ,g.server_name ,f.os as system_os,
-            CONVERT (g.role_name USING utf8) as role_name,a.payway ,a.status status ,a.mg_mem_id as user_id
-            from db_mp.h_pay a
+            g.role_name as role_name,a.payway ,a.status status ,a.mg_mem_id as user_id
+            from (select * from GameDataSum.h_pay_sum where 1=1 {op1} {op2} ) a
             left join
             (select b.agent_id as agent_id,b.advertiser_conf_id  from 
                     (select agent_id,max(update_time) as update_time  
-                    from db_mp.mp_conf_agent mmc 
+                    from GameDataSum.mp_conf_agent_sum mmc 
                     group by agent_id ) a
-                    left join db_mp.mp_conf_agent b on  a.agent_id=b.agent_id 
+                    left join GameDataSum.mp_conf_agent_sum b on  a.agent_id=b.agent_id 
                     and a.update_time = b.update_time) b on  a.agent_id =b.agent_id 
-            left join db_mp.mp_mp_conf c on b.advertiser_conf_id = c.id 
-            left join db_mp.h_member d on a.mem_id = d.id
-            left join db_mp.h_game e on a.app_id =e.id 
-      left join db_mp.h_game e2 on d.app_id =e2.id 
-            left join db_mp.h_pay_ext f on a.id = f.pay_id 
-            left join db_mp.h_mg_role g 
+            left join GameDataSum.mp_mp_conf_sum c on b.advertiser_conf_id = c.id
+            left join (select * from GameDataSum.h_member_sum where 1=1 {op1} {op2} ) d
+                        on a.mem_id = d.id
+            left join GameDataSum.h_game_sum e on a.app_id =e.id 
+            left join GameDataSum.h_game_sum e2 on d.app_id =e2.id 
+            left join GameDataSum.h_pay_ext_sum f on a.id = f.pay_id 
+            left join  (select * from GameDataSum.h_mg_role_sum where 1=1 {op1} {op2} ) 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 db_mp.h_user q on a.agent_id =q.id 
+            left join CostSourceData.advertiser_vx h on c.wx_name = h.name
+            left join GameDataSum.h_user_sum q on a.agent_id =q.id 
             where
-            a.app_id not in(6,13,23)
-            and a.agent_id =0
-            and d.app_id in(6,13,23)
-       {op1} {op2}
-      and a.status =2
+             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')
+            and d.app_id not in('sdk_one_6','sdk_one_13','sdk_one_23',
+            				'sdk_two_6','sdk_two_13','sdk_two_23')
+            and a.status =2
             '''
-
-        data = db.dm.getData_json(sql)
+        print(sql)
+        data = ck.execute(sql)
         return data