|
@@ -1,5 +1,5 @@
|
|
|
from handlers.HandlerBase import BaseHandler
|
|
|
-import time
|
|
|
+import time, json
|
|
|
from model.DataBaseUtils import *
|
|
|
from model.CommonUtils import *
|
|
|
from model import UserAuthUtils
|
|
@@ -319,3 +319,117 @@ class OrderInfo(BaseHandler):
|
|
|
where pitcher ='金康'
|
|
|
group by id
|
|
|
'''
|
|
|
+
|
|
|
+
|
|
|
+class OrderH5Info(BaseHandler):
|
|
|
+
|
|
|
+ def post(self):
|
|
|
+
|
|
|
+ if not self._au:
|
|
|
+ self.write_fail(msg='auth error')
|
|
|
+ else:
|
|
|
+ args = self.get_args()
|
|
|
+ user_id = args.get('user_id')
|
|
|
+
|
|
|
+ # role 表
|
|
|
+ start = args.get("start", self.thisday)
|
|
|
+ end = args.get("end")
|
|
|
+
|
|
|
+ data = self.get_order_info(user_id, start, end)
|
|
|
+ if args.get("download"):
|
|
|
+ data, total, total_data = self.get_order_info(user_id, start, end)
|
|
|
+ self.write_download(str(int(time.time())), data)
|
|
|
+ else:
|
|
|
+ self.write_json(data=data)
|
|
|
+
|
|
|
+ def get_order_info(self, user_id, start, end):
|
|
|
+ if user_id not in super_auth():
|
|
|
+ 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 ''
|
|
|
+
|
|
|
+ sql = f'''
|
|
|
+ select DATE_FORMAT(a.dt,'%Y-%m-%d'),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,
|
|
|
+ a.sum_amount as channel_amount,
|
|
|
+ a.human_counts as channel_human_count
|
|
|
+ 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,0))) 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,0)))/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,a.app_id,c_app_id
|
|
|
+
|
|
|
+ '''
|
|
|
+ df_source = db.dm.get_data_list(sql)
|
|
|
+ game_info = {}
|
|
|
+ for _ in df_source:
|
|
|
+ print(_)
|
|
|
+ _[2] = float(_[2])
|
|
|
+ _[3] = float(_[3])
|
|
|
+ _[4] = float(_[4])
|
|
|
+ _[7] = float(_[7])
|
|
|
+ _[10] = float(_[10])
|
|
|
+ h_game = (_[0], _[1], _[2], _[3], _[4], _[5], _[6], _[7])
|
|
|
+ if h_game in game_info.keys():
|
|
|
+ game_info[h_game].append(_)
|
|
|
+ else:
|
|
|
+ game_info[h_game] = [_]
|
|
|
+
|
|
|
+ res_game_info = []
|
|
|
+ for k, v in game_info.items():
|
|
|
+ print(k, v)
|
|
|
+ channel_game_list_natural = []
|
|
|
+ channel_game_list_unnatural = []
|
|
|
+ for _ in v:
|
|
|
+ if _[9]:
|
|
|
+ channel_game_list_natural.append({'channel_game_name': _[8],
|
|
|
+ 'channel_game_amount': _[10],
|
|
|
+ 'channel_game_human_count': _[11]})
|
|
|
+ else:
|
|
|
+ channel_game_list_unnatural.append({'channel_game_name': _[8],
|
|
|
+ 'channel_game_amount': _[10],
|
|
|
+ 'channel_game_human_count': _[11]})
|
|
|
+ tmp = {'dt': k[0], 'game_name': k[1], 'sum_amount': k[2], 'natural_amount': k[3],
|
|
|
+ 'natural_amount_rate': k[4], 'human_count': k[5], 'natural_human_count': k[6],
|
|
|
+ 'natural_human_count_rate': k[7], 'channel_game_natural_list': channel_game_list_natural,
|
|
|
+ 'channel_game_unnatural_list': channel_game_list_unnatural
|
|
|
+ }
|
|
|
+ res_game_info.append(tmp)
|
|
|
+ return res_game_info
|