cxyu 3 سال پیش
والد
کامیت
22d6b16bf2
1فایلهای تغییر یافته به همراه76 افزوده شده و 54 حذف شده
  1. 76 54
      handlers/OrderHandler.py

+ 76 - 54
handlers/OrderHandler.py

@@ -411,11 +411,11 @@ class OrderH5Info(BaseHandler):
             start = args.get("start", self.thisday)
             start = args.get("start", self.thisday)
             end = args.get("end")
             end = args.get("end")
 
 
-            data = self.get_order_info(user_id, start, end)
             if args.get("download"):
             if args.get("download"):
                 data = self.get_order_info_download(user_id, start, end)
                 data = self.get_order_info_download(user_id, start, end)
                 self.write_download(str(int(time.time())), data)
                 self.write_download(str(int(time.time())), data)
             else:
             else:
+                data = self.get_order_info(user_id, start, end)
                 self.write_json(data=data)
                 self.write_json(data=data)
 
 
     def get_order_info(self, user_id, start, end):
     def get_order_info(self, user_id, start, end):
@@ -423,18 +423,17 @@ class OrderH5Info(BaseHandler):
         ck = CkUtils()
         ck = CkUtils()
         du = DateUtils()
         du = DateUtils()
 
 
-
         if user_id not in super_auth():
         if user_id not in super_auth():
             return []
             return []
         # todo: 定时跑数据汇总也还没有写好,写好
         # todo: 定时跑数据汇总也还没有写好,写好
 
 
         # start end 转变为Unix_time
         # start end 转变为Unix_time
-        end = du.getLastDays(end,-1) if end else None #end 往后面一天
+        end = du.getLastDays(end, -1) if end else None  # end 往后面一天
         start = None if not start else int(datetime.strptime(start, '%Y-%m-%d').timestamp())
         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())
         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 ''
+        op1 = f" and create_time>={start} " if start else ''
+        op2 = f" and create_time<={end} " if end else ''
 
 
         sql = f'''
         sql = f'''
       select a.dt,a.h5_game_name,
       select a.dt,a.h5_game_name,
@@ -543,60 +542,83 @@ class OrderH5Info(BaseHandler):
         if user_id not in super_auth():
         if user_id not in super_auth():
             return []
             return []
 
 
-        db = MysqlUtils()
-        op1 = f"and date(FROM_UNIXTIME(a.create_time))>='{start}' " if start else ''
-        op2 = f"and date(FROM_UNIXTIME(a.create_time))<='{end}' " if end else ''
+        ck = CkUtils()
+        du = DateUtils()
+        # start end 转变为Unix_time
+        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'''
         sql = f'''
-      select DATE_FORMAT(a.dt,'%Y-%m-%d') 日期,
-      a.h5_game_name 游戏名称H5,
-    b.sum_amount as 今日总充值,
-    b.natural_amount as H5自然量充值,
-    b.amount_rate as 充值额比例,
-    b.human_count as 今日总充值人数,
-    b.natural_human_count H5自然量人数,
-    b.human_count_rate as 用户比例,
-    a.channel_game_name as 游戏名称小程序,
-    a.is_natural as 小程序的量是否为自然量,
-    a.sum_amount as 小程序导入用户充值, 
-    a.human_counts as 小程序导入人数
+      select a.dt dt, --日期
+      a.h5_game_name h5_game_name, --游戏名称H5,
+    b.sum_amount sum_amount_today,--as 今日总充值,
+    b.natural_amount natural_amount,-- as H5自然量充值,
+    b.amount_rate amount_rate, -- as 充值额比例,
+    b.human_count human_count, -- as 今日总充值人数,
+    b.natural_human_count natural_human_count, -- H5自然量人数,
+    b.human_count_rate human_count_rate, -- as 用户比例,
+    a.channel_game_name channel_game_name,  -- as 游戏名称小程序,
+    a.is_natural is_natural, -- as 小程序的量是否为自然量,
+    a.sum_amount sum_amount_small_app, -- as 小程序导入用户充值, 
+    a.human_counts human_counts -- as 小程序导入人数
     from 
     from 
-        (select date(FROM_UNIXTIME(a.create_time)) dt,a.app_id as app_id ,
-            b.name as h5_game_name,
-            c.app_id as c_app_id,d.name as channel_game_name,if(c.agent_id=0,1,0) as is_natural ,
-            sum(amount) as sum_amount,count(DISTINCT(a.mem_id)) as human_counts
-            from db_mp.h_pay a
-            LEFT  join db_mp.h_game b on a.app_id = b.id
-            left join db_mp.h_member c on a.mem_id = c.id 
-            LEFT  join db_mp.h_game d on c.app_id = d.id
-            where a.app_id in (select id from db_mp.h_game 
-                    where classify =5)
-            and a.app_id != c.app_id 
-            and a.status = 2
-            {op1} {op2}
-            group by date(FROM_UNIXTIME(a.create_time)),a.app_id ,
-            c.app_id ,d.name,if(c.agent_id=0,1,0) ) as a
-    left join
-        (select date(FROM_UNIXTIME(a.create_time)) as dt,a.app_id ,
-            sum(a.amount) sum_amount, 
-            sum(if(a.app_id=c.app_id,a.amount,0)) natural_amount,
-            count(DISTINCT(a.mem_id)) as human_count,
-            count(DISTINCT(if(a.app_id=c.app_id,a.mem_id,null))) natural_human_count,
-            ROUND(if(sum(a.amount)>0,sum(if(a.app_id=c.app_id,a.amount,0)) /sum(a.amount),0) ,2) amount_rate,
-            ROUND( if(count(DISTINCT(a.mem_id))>0,count(DISTINCT(if(a.app_id=c.app_id,a.mem_id,null)))/count(DISTINCT(a.mem_id)),0),2) human_count_rate
-            from db_mp.h_pay a
-            left join db_mp.h_member c on a.mem_id = c.id 
-            where a.app_id in (select id from db_mp.h_game 
-                    where classify =5) 
-             {op1} {op2}
-              and a.status=2
-            group by  date(FROM_UNIXTIME(a.create_time)),a.app_id ) b
-     on a.dt=b.dt and a.app_id = b.app_id
-    order by a.dt desc,a.app_id,c_app_id
+       (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 ,
+                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
+                left join (select * from GameDataSum.h_member_sum where 1=1  {op1} {op2} ) c on a.mem_id = c.id 
+                LEFT  join GameDataSum.h_game_sum d on c.app_id = d.id
+                where a.app_id in (select id from GameDataSum.h_game_sum 
+                        where classify =5)
+                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
+            left join
+            (select toDate(FROM_UNIXTIME(a.create_time)) as dt,a.app_id ,
+                sum(a.amount) sum_amount, 
+                sum(if(a.app_id=c.app_id,a.amount,0)) natural_amount,
+                count(DISTINCT(a.mem_id)) as human_count,
+                count(DISTINCT(if(a.app_id=c.app_id,a.mem_id,null))) natural_human_count,
+                ROUND(if(sum(a.amount)>0,sum(if(a.app_id=c.app_id,a.amount,0)) /sum(a.amount),0) ,2) amount_rate,
+                ROUND( if(count(DISTINCT(a.mem_id))>0,count(DISTINCT(if(a.app_id=c.app_id,a.mem_id,null)))/count(DISTINCT(a.mem_id)),0),2) human_count_rate
+                from (select * from GameDataSum.h_pay_sum where 1=1 {op1} {op2} ) a
+                left join (select * from GameDataSum.h_member_sum where 1=1  {op1} {op2}  ) c on a.mem_id = c.id 
+                where a.app_id in (select id from GameDataSum.h_game_sum 
+                        where classify =5) 
+                  and a.status=2
+                group by  toDate(FROM_UNIXTIME(a.create_time)),a.app_id ) b
+            on a.dt=b.dt and a.app_id = b.app_id
+        order by a.dt desc,a.app_id,c_app_id
     
     
             '''
             '''
-        data = db.dm.getData_json(sql)
-        return data
+        print(sql)
+        data = ck.execute(sql)
+
+        data_res = []
+        for _ in data:
+            tmp = {}
+            tmp['日期'] = _[0]
+            tmp['游戏名称H5'] = _[1]
+            tmp['今日总充值'] = _[2]
+            tmp['H5自然量充值'] = _[3]
+            tmp['充值额比例'] = _[4]
+            tmp['今日总充值人数'] = _[5]
+            tmp['H5自然量人数'] = _[6]
+            tmp['用户比例'] = _[7]
+            tmp['游戏名称小程序'] = _[8]
+            tmp['小程序的量是否为自然量'] = _[9]
+            tmp['小程序导入用户充值'] = _[10]
+            tmp['小程序导入人数'] = _[11]
+            data_res.append(tmp)
+        return data_res
 
 
 
 
 class OrderH5InfoSpecial(BaseHandler):
 class OrderH5InfoSpecial(BaseHandler):