소스 검색

MOD:自然量订单

cxyu 3 년 전
부모
커밋
22118cac44
1개의 변경된 파일56개의 추가작업 그리고 49개의 파일을 삭제
  1. 56 49
      handlers/OrderHandler.py

+ 56 - 49
handlers/OrderHandler.py

@@ -419,63 +419,70 @@ class OrderH5Info(BaseHandler):
                 self.write_json(data=data)
 
     def get_order_info(self, user_id, start, end):
+
+        ck = CkUtils()
+        du = DateUtils()
+
+
         if user_id not in super_auth():
             return []
-        # todo: sql中使用min有问题,因为有重复数据
-        db = MysqlUtils()
-        op1 = f"and toDate(FROM_UNIXTIME(a.create_time))>='{start}' " if start else ''
-        op2 = f"and toDate(FROM_UNIXTIME(a.create_time))<='{end}' " if end else ''
+        # todo: 定时跑数据汇总也还没有写好,写好
+
+        # 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'''
       select a.dt,a.h5_game_name,
-    b.sum_amount as sum_amount,
-    b.natural_amount as natural_amount,
-    b.amount_rate as amount_rate,
-    b.human_count as human_count,
-    b.natural_human_count as natural_human_count,
-    b.human_count_rate as human_count_rate,
-    a.channel_game_name as channel_game_name,
-    a.is_natural as is_natural,
-    toFloat64(a.sum_amount) as channel_amount, 
-    toFloat64(a.human_counts) as channel_human_count
-    from 
-        (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 GameDataSum.h_pay_sum a
-            LEFT  join GameDataSum.h_game_sum b on a.app_id = b.id
-            left join GameDataSum.h_member_sum 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
-            {op1} {op2}
-            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 GameDataSum.h_pay_sum a
-            left join GameDataSum.h_member_sum c on a.mem_id = c.id 
-            where a.app_id in (select id from GameDataSum.h_game_sum 
-                    where classify =5) 
-             {op1} {op2}
-              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
+            b.sum_amount as sum_amount,
+            b.natural_amount as natural_amount,
+            b.amount_rate as amount_rate,
+            b.human_count as human_count,
+            b.natural_human_count as natural_human_count,
+            b.human_count_rate as human_count_rate,
+            a.channel_game_name as channel_game_name,
+            a.is_natural as is_natural,
+            toFloat64(a.sum_amount) as channel_amount, 
+            toFloat64(a.human_counts) as channel_human_count
+            from 
+            (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
     
             '''
         print(sql)
-        ck = CkUtils()
         df_source = ck.execute(sql)
         game_info = {}
         for _ in df_source: