CardController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Models\Order;
  7. use Excel;
  8. use Illuminate\Support\Carbon;
  9. class CardController extends Controller
  10. {
  11. //房卡数据统计
  12. public function statisticsList(Request $request)
  13. {
  14. $excel = $request->get('excel');
  15. $end_time = $request->input('end_time');
  16. $start_time = $request->input('start_time');
  17. $where = [];
  18. if(empty($start_time)){
  19. $start_time = date('Y-m-d',strtotime("$end_time -9day"));
  20. $where[] = ['mydate','>=',$start_time];
  21. }else{
  22. $where[] = ['mydate','>=',$start_time];
  23. }
  24. if(empty($end_time)){
  25. $where[] = ['mydate','<=',date('Y-m-d')];
  26. $end_time = date('Y-m-d');
  27. }else{
  28. $where[] = ['mydate','<=',$end_time];
  29. }
  30. if($excel){
  31. $cellData = DB::table('QPRecordDB.dbo.RecordCardCost')
  32. ->select('mydate','mydate as week','LoginCount','createtimes','costcard','RegisterCount')->where($where)->orderBy('mydate','desc')->get()->toArray();
  33. $title = ['时间','星期','活跃用户','房卡局数','房卡消耗量','新增用户数','充值用户数','新增充值用户数','房卡充值率','充值金额','订单数','ARPU','ARPPU'];
  34. foreach ($cellData as $key => &$value) {
  35. $week = array("日","一","二","三","四","五","六");
  36. $value->week = $week[date('w',strtotime($value->week))];
  37. }
  38. $cellData = json_decode(json_encode($cellData),true);
  39. downloadExcel($cellData,$title,'房卡数据统计');
  40. }else{
  41. $list = DB::table('QPRecordDB.dbo.RecordCardCost')->where($where)->orderBy('mydate','desc')->paginate(10);
  42. foreach ($list as $key => &$value) {
  43. $week = array("日","一","二","三","四","五","六");
  44. $value->week = $week[date('w',strtotime($value->mydate))];
  45. }
  46. return view('admin.card.statistics_list',['list'=>$list,'end_time'=>$end_time,'start_time'=>$start_time]);
  47. }
  48. }
  49. //亲友圈查询
  50. public function friendsList(Request $request)
  51. {
  52. $nick_name = $request->input('nick_name');
  53. $show_id = $request->input('show_id');
  54. $name = $request->input('name');
  55. $game_id = $request->input('game_id');
  56. $excel = $request->get('excel');
  57. $where = [];
  58. !empty($nick_name) ? $where[] = ['pyq1.NickName','like','%'.$nick_name.'%'] : '';
  59. !empty($name) ? $where[] = ['pyq1.Name','like','%'.$name.'%'] : '';
  60. !empty($show_id) ? $where[] = ['pyq1.ShowID','=',$show_id] : '';
  61. !empty($game_id) ? $where[] = ['ai.GameID','=',$game_id] : '';
  62. if($excel){
  63. $cellData = DB::table('QPAccountsDB.dbo.PyqInfo1 as pyq1')
  64. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai','pyq1.UserID','=','ai.UserID')
  65. ->leftJoin('QPAccountsDB.dbo.PyqInfo as pyq','pyq1.ShowID','=','pyq.ShowID')
  66. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gsi','pyq1.UserID','=','gsi.UserID')
  67. ->select('pyq1.CreateDate','pyq1.NickName','pyq1.ShowID','pyq.CurCount as count','pyq1.Name','pyq1.GameName','ai.GameID','pyq1.WxAccount','pyq1.Mobile','pyq1.NumberLimit','gsi.InsureScore')
  68. ->where($where)
  69. ->where(['pyq1.IsDelete'=>0,'Status'=>3])
  70. ->groupBy('pyq1.CreateDate','pyq1.ShowID','pyq1.NickName','pyq1.GameName','pyq1.WxAccount','pyq1.Mobile','pyq1.Name','pyq1.NumberLimit','ai.GameID','gsi.InsureScore','pyq.CurCount')
  71. ->orderBy('pyq1.CreateDate','desc')
  72. ->get();
  73. foreach ($cellData as $key => &$value) {
  74. $value->count = $value->count.'/'.$value->NumberLimit;
  75. unset($value->NumberLimit);
  76. }
  77. $title = ['成立时间','亲友圈昵称','亲友圈ID','成员数','推广员姓名','推广员戏昵称','推广员游戏ID','微信号','手机号','房卡库存'];
  78. $cellData = json_decode(json_encode($cellData),true);
  79. downloadExcel($cellData,$title,'亲友圈列表');
  80. }else{
  81. $list = DB::table('QPAccountsDB.dbo.PyqInfo1 as pyq1')
  82. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai','pyq1.UserID','=','ai.UserID')
  83. ->leftJoin('QPAccountsDB.dbo.PyqInfo as pyq','pyq1.ShowID','=','pyq.ShowID')
  84. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gsi','pyq1.UserID','=','gsi.UserID')
  85. ->select('pyq1.CreateDate','pyq1.NickName','pyq1.ShowID','pyq.ID','pyq.CurCount as count','pyq1.Name','pyq1.GameName','ai.GameID','pyq1.UserID','pyq1.WxAccount','pyq1.Mobile','pyq1.NumberLimit','gsi.InsureScore')
  86. ->where($where)
  87. ->where(['pyq1.IsDelete'=>0,'Status'=>3])
  88. ->groupBy('pyq1.CreateDate','pyq1.ShowID','pyq.ID','pyq1.UserID','pyq1.NickName','pyq1.GameName','pyq1.WxAccount','pyq1.Mobile','pyq1.Name','pyq1.NumberLimit','ai.GameID','gsi.InsureScore','pyq.CurCount')
  89. ->orderBy('pyq1.CreateDate','desc')
  90. ->paginate(10);
  91. return view('admin.card.friends_list',['list'=>$list,'nick_name'=>$nick_name,'show_id'=>$show_id,'name'=>$name,'game_id'=>$game_id,]);
  92. }
  93. }
  94. //成员信息
  95. public function membersList(Request $request,$id)
  96. {
  97. $list = DB::table('QPAccountsDB.dbo.PyqMemberInfo as pmi')
  98. ->leftJoin('QPAccountsDB.dbo.PyqInfo as pyq','pmi.ID','=','pyq.ID')
  99. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai','pmi.MemberID','=','ai.UserID')
  100. ->select('ai.UserID','pyq.ShowID','pyq.NickName as PyqName','ai.GameID','ai.NickName','pmi.JoinDate')
  101. ->where('pmi.ID',$id)
  102. ->groupBy('ai.UserID','pyq.ShowID','pyq.NickName','ai.GameID','ai.NickName','pmi.JoinDate')
  103. ->paginate(10);
  104. foreach ($list as $key => &$value) {
  105. $where = [];
  106. $value->UpdateTime = '';
  107. $value->UpdateTime = DB::table('QPRecordDB.dbo.YN_RecordPlayerNum')
  108. ->where('UserID',$value->UserID)
  109. ->where('GameType',8)
  110. ->orderBy('UpdateTime','desc')
  111. ->value('UpdateTime');
  112. $where[] = ['TabelMember','like',"%*".$value->UserID."*%"];
  113. $value->PlayCount = DB::table('QPAccountsDB.dbo.PyqRecordLog')
  114. ->where($where)
  115. ->count();
  116. }
  117. return view('admin.card.members_list',['list'=>$list,'id'=>$id]);
  118. }
  119. //亲友圈数据
  120. public function friendsDetail(Request $request)
  121. {
  122. $start_time = $request->input('start_time') ?? date('Y-m-d');
  123. $end_time = $request->input('end_time') ?? date('Y-m-d');
  124. $where_end_time = date('Y-m-d',strtotime("$end_time +1 day"));
  125. $kind_id = $request->input('kind_id') ?? 0;
  126. $show_id = $request->input('show_id') ?? 0;
  127. $game_id = $request->input('game_id') ?? 0;
  128. $excel = $request->get('excel');
  129. if($excel){
  130. $list = DB::select("
  131. SET NOCOUNT ON
  132. use QPAccountsDB
  133. DECLARE @BeginTime datetime
  134. DECLARE @EndTime datetime
  135. DECLARE @KindId INT
  136. DECLARE @QuanId INT
  137. DECLARE @GameId INT
  138. set @BeginTime = '$start_time'
  139. set @EndTime = '$where_end_time'
  140. set @KindId = $kind_id
  141. set @GameId = $game_id
  142. set @QuanId = $show_id
  143. create table #infos(date varchar(10),ShowID int,ID int,NickName nvarchar(32),CurCount int,countU int,roomcard int,Jushu int)
  144. DECLARE @temptime datetime
  145. SET @temptime = convert(varchar(10), @BeginTime, 120)+' 00:00:00'
  146. while @temptime < @EndTime
  147. begin
  148. INSERT into #infos(date,ShowID,ID,NickName,CurCount,countU,roomcard,Jushu)
  149. select convert(varchar(10), @temptime, 120) as date, a.ShowID,a.ID, a.NickName,a.CurCount,c.countU,sum(e.RoomCard) as roomcard,
  150. sum(e.LowerStandard+e.UpStandard) as Jushu
  151. from QPAccountsDB.dbo.PyqInfo a,(select b.PyqID,COUNT(b.UserID) as countU from (
  152. select PyqID,UserID,SUM(PlayNum) as AllPlayNum from QPAccountsDB.dbo.YN_PyqRecordPlayLogSum
  153. where UpdateTime >= @temptime and UpdateTime <= DATEADD(DD,1,@temptime)
  154. group by PyqID,UserID) b
  155. where AllPlayNum >= 0
  156. group by b.PyqID) c,YN_PyqRecordLogSum e
  157. where a.ID = c.PyqID
  158. and a.ID = e.PyqID
  159. and e.UpdateTime >= @temptime and e.UpdateTime <= DATEADD(DD,1,@temptime)
  160. group by a.ShowID,a.NickName,a.CurCount,c.countU,a.ID
  161. SET @temptime = DATEADD(DD,1,@temptime)
  162. end
  163. if @KindId >0
  164. begin
  165. DELETE FROM #infos where ID not in(SELECT PyqID FROM QPAccountsDB.dbo.YN_PyqRankList where @KindId = KindID)
  166. end
  167. if @GameId > 0
  168. begin
  169. DECLARE @UserId INT
  170. SELECT @UserId =UserID FROM QPAccountsDB.dbo.AccountsInfo where GameID = @GameId
  171. print(@UserId)
  172. DELETE FROM #infos where ID in(SELECT ID FROM PyqInfo where UserID != @UserId )
  173. end
  174. if @QuanId > 0
  175. begin
  176. DELETE FROM #infos where ShowID not in(@QuanId)
  177. end
  178. select date,ShowID,NickName,countU,Jushu,roomcard from #infos
  179. drop table #infos");
  180. $title = ['时间','亲友圈ID','亲友圈昵称','活跃用户','游戏局数','房卡消耗'];
  181. $list = json_decode(json_encode($list),true);
  182. downloadExcel($list,$title,'亲友圈列表');
  183. }else{
  184. $list = DB::select("
  185. SET NOCOUNT ON
  186. use QPAccountsDB
  187. DECLARE @BeginTime datetime
  188. DECLARE @EndTime datetime
  189. DECLARE @KindId INT
  190. DECLARE @QuanId INT
  191. DECLARE @GameId INT
  192. set @BeginTime = '$start_time'
  193. set @EndTime = '$where_end_time'
  194. set @KindId = $kind_id
  195. set @GameId = $game_id
  196. set @QuanId = $show_id
  197. create table #infos(date varchar(10),ShowID int,ID int,NickName nvarchar(32),CurCount int,countU int,roomcard int,Jushu int)
  198. DECLARE @temptime datetime
  199. SET @temptime = convert(varchar(10), @BeginTime, 120)+' 00:00:00'
  200. while @temptime < @EndTime
  201. begin
  202. INSERT into #infos(date,ShowID,ID,NickName,CurCount,countU,roomcard,Jushu)
  203. select convert(varchar(10), @temptime, 120) as date, a.ShowID,a.ID, a.NickName,a.CurCount,c.countU,sum(e.RoomCard) as roomcard,
  204. sum(e.LowerStandard+e.UpStandard) as Jushu
  205. from QPAccountsDB.dbo.PyqInfo a,(select b.PyqID,COUNT(b.UserID) as countU from (
  206. select PyqID,UserID,SUM(PlayNum) as AllPlayNum from QPAccountsDB.dbo.YN_PyqRecordPlayLogSum
  207. where UpdateTime >= @temptime and UpdateTime <= DATEADD(DD,1,@temptime)
  208. group by PyqID,UserID) b
  209. where AllPlayNum >= 0
  210. group by b.PyqID) c,YN_PyqRecordLogSum e
  211. where a.ID = c.PyqID
  212. and a.ID = e.PyqID
  213. and e.UpdateTime >= @temptime and e.UpdateTime <= DATEADD(DD,1,@temptime)
  214. group by a.ShowID,a.NickName,a.CurCount,c.countU,a.ID
  215. SET @temptime = DATEADD(DD,1,@temptime)
  216. end
  217. if @KindId >0
  218. begin
  219. DELETE FROM #infos where ID not in(SELECT PyqID FROM QPAccountsDB.dbo.YN_PyqRankList where @KindId = KindID)
  220. end
  221. if @GameId > 0
  222. begin
  223. DECLARE @UserId INT
  224. SELECT @UserId =UserID FROM QPAccountsDB.dbo.AccountsInfo where GameID = @GameId
  225. print(@UserId)
  226. DELETE FROM #infos where ID in(SELECT ID FROM PyqInfo where UserID != @UserId )
  227. end
  228. if @QuanId > 0
  229. begin
  230. DELETE FROM #infos where ShowID not in(@QuanId)
  231. end
  232. select * from #infos
  233. drop table #infos");
  234. $game_name = DB::table('QPPlatformDB.dbo.GameGameItem as ggi')
  235. ->leftJoin('QPPlatformDB.dbo.GameRoomInfo as gri','ggi.GameID','=','gri.GameID')
  236. ->where('gri.ServerType',8)
  237. ->pluck('ggi.GameName','ggi.GameID');//单选框数据
  238. return view('admin.card.friends_detail',['list'=>$list,'show_id'=>$show_id,'kind_id'=>$kind_id,'game_id'=>$game_id,'game_name'=>$game_name,'start_time'=>$start_time,'end_time'=>$end_time]);
  239. }
  240. }
  241. //游戏记录查询
  242. public function gameRecordList(Request $request)
  243. {
  244. $record_id = $request->input('record_id');
  245. $kind_id = $request->input('kind_id');
  246. $game_id = $request->input('game_id');
  247. $end_time = $request->input('end_time');
  248. $start_time = $request->input('start_time');
  249. $end_time = !empty($end_time) ? $end_time: date('Y-m-d');
  250. $start_time = !empty($start_time) ? $start_time : date('Y-m-d',strtotime('-7 days'));
  251. // $where[] = ['pgr.Pyq','=',1];
  252. $where[] = ['prl.CreateDate','>=',$start_time];
  253. $where[] = ['prl.CreateDate','<=',date('Y-m-d',strtotime("$end_time +1day"))];
  254. !empty($record_id) ? $where[] = ['prl.RecordID','=',$record_id] : '';
  255. !empty($kind_id) ? $where[] = ['prl.KindID','=',$kind_id] : '';
  256. if(!empty($game_id)){
  257. $user_id = DB::table('QPAccountsDB.dbo.AccountsInfo')->where('GameID',$game_id)->value('UserID');
  258. $where[] = ['prl.TabelMember','like','%*'.$user_id.'*%'];
  259. }
  260. $game_name = DB::table('QPPlatformDB.dbo.GameGameItem as ggi')
  261. ->leftJoin('QPPlatformDB.dbo.GameRoomInfo as gri','ggi.GameID','=','gri.GameID')
  262. ->where('gri.ServerType',8)
  263. ->pluck('ggi.GameName','ggi.GameID');//单选框数据
  264. $list = DB::table('QPAccountsDB.dbo.PyqRecordLog as prl')
  265. ->leftJoin('QPTreasureDB.dbo.PrivateGameRecordUserRecordID as pgr','prl.RecordID','=','pgr.RecordID')
  266. ->leftJoin('QPPlatformDB.dbo.GameKindItem as ki','prl.KindID','=','ki.KindID')
  267. ->select('prl.RecordID','prl.CreateDate','ki.KindName','prl.MemberScore','prl.TabelMember','prl.NickNames')
  268. ->where($where)
  269. ->groupBy('prl.RecordID','prl.CreateDate','ki.KindName','prl.MemberScore','prl.TabelMember','prl.NickNames')
  270. ->orderBy('prl.CreateDate','desc')
  271. ->paginate(10);
  272. foreach ($list as $key => &$value) {
  273. $names = [];
  274. $count = substr($value->NickNames,0,2);
  275. $name = substr(mb_convert_encoding($value->NickNames, 'gbk', 'utf-8'),2);
  276. for ($i=0; $i < $count ; $i++) {
  277. $lenth = substr($name,0,3);
  278. $nick_name = substr($name,3,(int)$lenth);
  279. $name = str_replace($lenth.$nick_name,'', $name);
  280. $names[] = mb_convert_encoding($nick_name, 'utf-8', 'gbk');
  281. }
  282. $value->score = explode('*', trim($value->MemberScore,'*'));
  283. $user_ids = explode('*', trim($value->TabelMember,'*'));
  284. $game_ids = [];
  285. foreach ($user_ids as $k => $v) {
  286. $game_ids[] = DB::table('QPAccountsDB.dbo.AccountsInfo')->where('UserID',$v)->value('GameID');
  287. }
  288. $value->GameID = $game_ids;
  289. $value->name = $names;
  290. }
  291. return view('admin.card.game_record_list',['list'=>$list,'record_id'=>$record_id,'kind_id'=>$kind_id,'game_name'=>$game_name,'game_id'=>$game_id,'start_time'=>$start_time,'end_time'=>$end_time]);
  292. }
  293. //玩家输赢记录
  294. public function gameResultList(Request $request)
  295. {
  296. $excel = $request->input('excel');
  297. $game_id = $request->input('game_id');
  298. $kind_id = $request->input('kind_id');
  299. $sort = $request->input('sort');
  300. $start_time = $request->input('start_time');
  301. $end_time = $request->input('end_time');
  302. $end_time = !empty($end_time) ? $end_time: date('Y-m-d');
  303. $start_time = !empty($start_time) ? $start_time : date('Y-m-d',strtotime('-7 days'));
  304. $where[] = ['usd.PyqID','=',0];
  305. $where[] = ['usd.ServerType','=',8];
  306. $where[] = ['usd.UpdateTime','>=',$start_time];
  307. $where[] = ['usd.UpdateTime','<=',$end_time];
  308. !empty($game_id) ? $where[] = ['ai.GameID','=',$game_id] : '';
  309. !empty($kind_id) ? $where[] = ['usd.KindID','=',$kind_id] : '';
  310. !empty($sort) ? $order = 'usd.Score asc' : $order = 'usd.Score desc';
  311. $game_name = DB::table('QPPlatformDB.dbo.GameGameItem as ggi')
  312. ->leftJoin('QPPlatformDB.dbo.GameRoomInfo as gri','ggi.GameID','=','gri.GameID')
  313. ->where('gri.ServerType',8)
  314. ->pluck('ggi.GameName','ggi.GameID');//单选框数据
  315. if($excel){
  316. $list = DB::table('QPPlatformDB.dbo.YN_UserStockDay as usd')
  317. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai','usd.UserID','=','ai.UserID')
  318. ->leftJoin('QPPlatformDB.dbo.GameGameItem as ggi','usd.KindID','=','ggi.GameID')
  319. ->select('usd.UpdateTime','ai.GameID','ai.NickName','ggi.GameName','usd.Score')
  320. ->where($where)
  321. ->orderByRaw($order)
  322. ->get();
  323. $title = ['时间','用户游戏ID','昵称','游戏名称','输赢分数'];
  324. $cellData = json_decode(json_encode($list),true);
  325. downloadExcel($cellData,$title,'玩家输赢记录'.date('YmdHis'));
  326. }else{
  327. $list = DB::table('QPPlatformDB.dbo.YN_UserStockDay as usd')
  328. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai','usd.UserID','=','ai.UserID')
  329. ->leftJoin('QPPlatformDB.dbo.GameGameItem as ggi','usd.KindID','=','ggi.GameID')
  330. ->select('usd.UpdateTime','ai.GameID','usd.UserID','ai.NickName','usd.KindID','ggi.GameName','usd.Score')
  331. ->where($where)
  332. ->orderByRaw($order)
  333. ->groupBy('usd.UpdateTime','usd.UserID','ai.GameID','ai.NickName','usd.KindID','ggi.GameName','usd.Score')
  334. ->paginate(10);
  335. foreach ($list as $key => &$value) {
  336. $where1 = [];
  337. $where1[] = ['TabelMember','like','%*'.$value->UserID.'*%'];
  338. $where1[] = ['KindID','=',$value->KindID];
  339. $value->count = DB::table('QPAccountsDB.dbo.PyqRecordLog')
  340. ->selectRaw('count(*) as count')
  341. ->where($where1)
  342. ->whereRaw("DATEDIFF(DD,CreateDate,'$value->UpdateTime') = 0")
  343. ->value('count');
  344. }
  345. return view('admin.card.game_result_list',['list'=>$list,'game_id'=>$game_id,'kind_id'=>$kind_id,'game_name'=>$game_name,'start_time'=>$start_time,'end_time'=>$end_time]);
  346. }
  347. }
  348. //游戏输赢总排行
  349. public function allScoreList(Request $request)
  350. {
  351. $excel = $request->input('excel');
  352. $start_time = $request->input('start_time');
  353. $end_time = $request->input('end_time');
  354. $where[] = ['usd.PyqID','=',0];
  355. $where[] = ['usd.ServerType','=',8];
  356. if(empty($start_time)){
  357. $start_time = date('Y-m-d',strtotime("$end_time -9day"));
  358. }
  359. $where[] = ['usd.UpdateTime','>=',$start_time];
  360. if(empty($end_time)){
  361. $end_time = date('Y-m-d');
  362. }
  363. $where[] = ['usd.UpdateTime','<=',$end_time];
  364. if($excel){
  365. $list = DB::table('QPPlatformDB.dbo.YN_UserStockDay as usd')
  366. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai','usd.UserID','=','ai.UserID')
  367. ->leftJoin('QPPlatformDB.dbo.GameGameItem as ggi','usd.KindID','=','ggi.GameID')
  368. ->select('ai.GameID','ai.NickName','ggi.GameName',DB::Raw('sum(usd.Score) as AllScore'))
  369. ->where($where)
  370. ->groupBy('ai.GameID','ggi.GameName','ai.NickName')
  371. ->orderBy(DB::Raw('sum(usd.Score)'),'desc')
  372. ->get();
  373. $title = ['用户游戏ID','昵称','游戏名称','输赢分数'];
  374. $cellData = json_decode(json_encode($list),true);
  375. downloadExcel($cellData,$title,'玩家输赢记录'.date('YmdHis'));
  376. }else{
  377. $list = DB::table('QPPlatformDB.dbo.YN_UserStockDay as usd')
  378. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai','usd.UserID','=','ai.UserID')
  379. ->leftJoin('QPPlatformDB.dbo.GameGameItem as ggi','usd.KindID','=','ggi.GameID')
  380. ->select('ai.GameID','usd.UserID','ai.NickName','ggi.GameName',DB::Raw('sum(usd.Score) as AllScore'))
  381. ->where($where)
  382. ->groupBy('ai.GameID','usd.UserID','ggi.GameName','ai.NickName')
  383. ->orderBy(DB::Raw('sum(usd.Score)'),'desc')
  384. ->paginate(10);
  385. return view('admin.card.allscore_list',['list'=>$list,'start_time'=>$start_time,'end_time'=>$end_time]);
  386. }
  387. }
  388. //游戏日志
  389. public function gameLogList(Request $request)
  390. {
  391. $excel = $request->get('excel');
  392. $end_time = $request->input('end_time');
  393. $start_time = $request->input('start_time');
  394. $kind_id = $request->input('kind_id');
  395. $where[] = ['GameType','=',8];
  396. if(empty($start_time)){
  397. $cost_where[] = ['RecordDate','>=',date('Y-m-d',strtotime('-1 week'))];
  398. $where[] = ['UpdateTime','>=',date('Y-m-d',strtotime('-1 week'))];
  399. $start_time = date('Y-m-d',strtotime('-1 week'));
  400. }else{
  401. $where[] = ['UpdateTime','>=',$start_time];
  402. }
  403. if(empty($end_time)){
  404. $cost_where[] = ['RecordDate','<=',date('Y-m-d',strtotime('+1 days'))];
  405. $where[] = ['UpdateTime','<=',date('Y-m-d',strtotime('+1 days'))];
  406. $end_time = date('Y-m-d');
  407. }else{
  408. $where[] = ['UpdateTime','<=',date('Y-m-d',strtotime("$end_time +1 days"))];
  409. }
  410. if($kind_id){
  411. $where[] = ['rp.KindID','=',$kind_id];
  412. }
  413. $kind_ids = DB::table('QPRecordDB.dbo.YN_RecordPlayerNum as rp')
  414. ->leftJoin('QPPlatformDB.dbo.GameGameItem as g','rp.KindID','=','g.GameID')
  415. ->distinct()
  416. ->select('KindID','GameName')
  417. ->where('GameType',8)
  418. ->get();
  419. if($excel){
  420. $list = DB::table('QPRecordDB.dbo.YN_RecordPlayerNum as rp')
  421. ->leftJoin('QPPlatformDB.dbo.GameGameItem as g','rp.KindID','=','g.GameID')
  422. ->selectRaw('CONVERT(varchar(100), UpdateTime, 23) as date, g.GameName, COUNT(*) as count, SUM(PlayCount) as PlayCount, SUM(Experience) as time')
  423. ->where($where)
  424. ->groupBy(DB::raw('CONVERT(varchar(100), UpdateTime, 23),rp.KindID, g.GameName'))
  425. ->orderBy(DB::raw('CONVERT(varchar(100), UpdateTime, 23)'),'desc')
  426. ->orderBy('PlayCount','desc')
  427. ->get();
  428. foreach ($list as $key => &$value) {
  429. $value->time = round($value->time/$value->count/60,0);
  430. $value->PlayCount = round($value->PlayCount/28,0);
  431. }
  432. $title = ['时间','游戏名称','参游人数','开桌数','平均在线时长'];
  433. $cellData = json_decode(json_encode($list),true);
  434. downloadExcel($cellData,$title,'玩家输赢记录'.date('YmdHis'));
  435. }else{
  436. $list = DB::table('QPRecordDB.dbo.YN_RecordPlayerNum as rp')
  437. ->leftJoin('QPPlatformDB.dbo.GameGameItem as g','rp.KindID','=','g.GameID')
  438. ->selectRaw('CONVERT(varchar(100), UpdateTime, 23) as date, g.GameName, COUNT(*) as count, SUM(PlayCount) as PlayCount, SUM(Experience) as time')
  439. ->where($where)
  440. ->groupBy(DB::raw('CONVERT(varchar(100), UpdateTime, 23),rp.KindID, g.GameName'))
  441. ->orderBy(DB::raw('CONVERT(varchar(100), UpdateTime, 23)'),'desc')
  442. ->orderBy('PlayCount','desc')
  443. ->paginate(10);
  444. // $cost_card = DB::table('QPRecordDB.dbo.RecordCardCostDetail')
  445. // ->selectRaw('KindID,CONVERT(varchar(100), RecordDate, 23) as date,SUM(CostCard) as cost')
  446. // ->where($cost_where)
  447. // ->whereIn('KindID',$kind_ids)
  448. // ->groupBy(DB::raw('CONVERT(varchar(100), RecordDate, 23), KindID'))
  449. // ->orderBy(DB::raw('CONVERT(varchar(100), RecordDate, 23)'),'desc')
  450. // ->get();
  451. // print_r($kind_ids);exit;
  452. return view('admin.card.game_log',['list'=>$list,'start_time'=>$start_time,'end_time'=>$end_time,'kind_id'=>$kind_id,'kind_ids'=>$kind_ids]);
  453. }
  454. }
  455. //批量转账页
  456. public function giveCardView(Request $request)
  457. {
  458. return view('admin.card.give');
  459. }
  460. //批量转账
  461. public function giveCard(Request $request)
  462. {
  463. if($request->has('text')){
  464. $text = json_decode($request->text,true);
  465. $time = Carbon::now();
  466. $admin = $request->session()->get('admin');
  467. foreach ($text as $key => $value) {
  468. if(!is_int($value[0]) || !is_int($value[1])){
  469. return $this->json(500, "数据格式错误");
  470. }
  471. $record = [];
  472. $record['GameID'] = $value[0];
  473. $record['Amount'] = $value[1];
  474. $record['Reason'] = $value[2];
  475. $record['CreatedAt'] = $time;
  476. $record['Admin'] = $admin->nickname;
  477. $record_insert[] = $record;
  478. $user_id = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')->where('GameID',$value[0])->value('UserID');
  479. if(!$user_id){
  480. return $this->json(500, "用户ID错误:$value[0]");
  481. }
  482. $mail = [
  483. 'MailType' => 2,
  484. 'MailStatus' => 1,
  485. 'UserID' => $user_id,
  486. 'CreateTime' => $time,
  487. 'TitleString' => $value[3],
  488. 'TextString' => $value[4],
  489. 'BonusString' => "10000,".$value[1],
  490. 'FromAgentID' => $admin->id,
  491. ];
  492. $mail_insert[] = $mail;
  493. }
  494. $result = DB::table('QPRecordDB.dbo.GiveCardRecord')
  495. ->insert($record_insert);
  496. $result = DB::table('QPAccountsDB.dbo.PrivateMail')->insert($mail_insert);
  497. if($result){
  498. return $this->json(200, "处理成功");
  499. }else{
  500. return $this->json(500, "提交失败");
  501. }
  502. }
  503. $list = [];
  504. $list = $this->addexcel($request);
  505. unset($list[0]);
  506. if(!$list){
  507. return view('admin.card.give');
  508. }
  509. $str = json_encode($list);
  510. return view('admin.card.add',['list'=>$list,'str'=>$str]);
  511. }
  512. //批量转账记录
  513. public function giveCardRecordView(Request $request)
  514. {
  515. $start_time = $request->input('start_time') ?? date('Y-m-d');
  516. $end_time = $request->input('end_time') ?? date('Y-m-d');
  517. $game_id = $request->input('game_id');
  518. $reason = $request->input('reason');
  519. $where[] = ['CreatedAt','>=',$start_time];
  520. $where[] = ['CreatedAt','<=',date('Y-m-d',strtotime("$end_time +1 days"))];
  521. if($game_id){
  522. $where[] = ['GameID','=',$game_id];
  523. }
  524. if($reason){
  525. $where[] = ['Reason','like','%'.$reason.'%'];
  526. }
  527. $list = DB::connection('write')->table('QPRecordDB.dbo.GiveCardRecord')
  528. ->where($where)
  529. ->orderBy('ID','desc')
  530. ->paginate(15);
  531. return view('admin.card.give_record',['list'=>$list,'start_time'=>$start_time,'end_time'=>$end_time,'game_id'=>$game_id,'reason'=>$reason]);
  532. }
  533. }