2
0

GameDataController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Facade\TableName;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\helper\NumConfig;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\DB;
  8. class GameDataController extends Controller
  9. {
  10. public function makeGameid(Request $request){
  11. $userid=DB::connection('write')->table('QPAccountsDB.dbo.GameIdentifier')->select("UserID")->orderByDesc("UserID")->first()->UserID;
  12. for($i=0;$i<1000000;$i++){
  13. $gameid= mt_rand(10893227,20893227);
  14. // echo "<br/>";
  15. if(!DB::connection('write')->table('QPAccountsDB.dbo.GameIdentifier')->where('GameID' , $gameid)->exists()){
  16. $userid++;
  17. DB::connection('write')->table('QPAccountsDB.dbo.GameIdentifier')->updateOrInsert(['UserID'=>$userid,'GameID' => $gameid]);
  18. }
  19. }
  20. }
  21. //实时在线
  22. public function userOnlineView(Request $request)
  23. {
  24. $start_date = $request->start_date ?? date('Y-m-d');
  25. $end_date = $request->end_date ?? date('Y-m-d');
  26. $game_name = DB::connection('read')->table('QPPlatformDB.dbo.GameKindItem')
  27. ->whereIn('GameID', config('games.openKGame'))
  28. ->pluck('KindName as GameName', 'GameID');//单选框数据
  29. return view('admin.game_data.useronline', ['start_date' => $start_date, 'end_date' => $end_date,'game_name' => $game_name]);
  30. }
  31. public function TigerBuyRecord(Request $request)
  32. {
  33. $start_time = $request->start_time ?: '';
  34. $end_time = $request->end_time ?: '';
  35. $start_time = str_replace('T', ' ', $start_time ?? "");
  36. $end_time = str_replace('T', ' ', $end_time ?? "");
  37. $GameID = $request->GameID ?: '';
  38. $Type = $request->Type ?: 0;
  39. $SortID = $request->SortID ?: -1;
  40. $where[] = ['KindID', 5006];
  41. $sortArr = ['-1' => '全部','1' => '初级场','2' => '中级场','3' => '高级场'];
  42. $typeArr = [0 => '全部',1 => '免费',2 => '买入'];
  43. !empty($start_time) && $where[] = ['CreateTime', '>=', $start_time];
  44. !empty($end_time) && $where[] = ['CreateTime', '<=', $end_time];
  45. !empty($GameID) && $where[] = ['GameID', $GameID];
  46. !empty($Type) && $where[] = ['Type', $Type];
  47. ($SortID>=0) && $where[] = ['SortID', $SortID];
  48. $list = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs as ri')
  49. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ri.UserID', 'ai.UserID')
  50. ->where($where)
  51. ->selectRaw('ri.*,ai.GameID,ai.NickName,Channel')
  52. ->orderByDesc('CreateTime')
  53. ->paginate(10);
  54. foreach ($where as $k => $v){
  55. if($v[0] == 'GameID'){
  56. unset($where[$k]);
  57. break;
  58. }
  59. }
  60. $sumData = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs')
  61. ->where($where)
  62. ->selectRaw('sum(ChangeScore) sumwin,sum(BuyScore) sumbuy')
  63. ->first();
  64. foreach ($list as $value) {
  65. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  66. $value->BuyBase = number_float($value->BuyBase / NumConfig::NUM_VALUE);
  67. $value->BuyScore = $value->BuyScore;
  68. }
  69. $gameName = '金老虎全屏';
  70. $action = '/admin/game_data/TigerBuyRecord';
  71. $data = compact('list', 'Type', 'start_time', 'end_time', 'GameID', 'SortID','typeArr','sortArr','sumData','gameName','action');
  72. return view('admin.game_data.gate_record', $data);
  73. }
  74. public function OxBuyRecord(Request $request)
  75. {
  76. $start_time = $request->start_time ?: '';
  77. $end_time = $request->end_time ?: '';
  78. $start_time = str_replace('T', ' ', $start_time ?? "");
  79. $end_time = str_replace('T', ' ', $end_time ?? "");
  80. $GameID = $request->GameID ?: '';
  81. $Type = $request->Type ?: 0;
  82. $SortID = $request->SortID ?: -1;
  83. $where[] = ['KindID', 5007];
  84. $sortArr = ['-1' => '全部','1' => '初级场','2' => '中级场','3' => '高级场'];
  85. $typeArr = [0 => '全部',1 => '免费',2 => '买入'];
  86. !empty($start_time) && $where[] = ['CreateTime', '>=', $start_time];
  87. !empty($end_time) && $where[] = ['CreateTime', '<=', $end_time];
  88. !empty($GameID) && $where[] = ['GameID', $GameID];
  89. !empty($Type) && $where[] = ['Type', $Type];
  90. ($SortID>=0) && $where[] = ['SortID', $SortID];
  91. $list = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs as ri')
  92. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ri.UserID', 'ai.UserID')
  93. ->where($where)
  94. ->selectRaw('ri.*,ai.GameID,ai.NickName,Channel')
  95. ->orderByDesc('CreateTime')
  96. ->paginate(10);
  97. foreach ($where as $k => $v){
  98. if($v[0] == 'GameID'){
  99. unset($where[$k]);
  100. break;
  101. }
  102. }
  103. $sumData = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs')
  104. ->where($where)
  105. ->selectRaw('sum(ChangeScore) sumwin,sum(BuyScore) sumbuy')
  106. ->first();
  107. foreach ($list as $value) {
  108. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  109. $value->BuyBase = number_float($value->BuyBase / NumConfig::NUM_VALUE);
  110. $value->BuyScore = $value->BuyScore;
  111. }
  112. $gameName = '金牛全屏';
  113. $action = '/admin/game_data/OxBuyRecord';
  114. $data = compact('list', 'Type', 'start_time', 'end_time', 'GameID', 'SortID','typeArr','sortArr','sumData','gameName','action');
  115. return view('admin.game_data.gate_record', $data);
  116. }
  117. public function RabbitBuyRecord(Request $request)
  118. {
  119. $start_time = $request->start_time ?: '';
  120. $end_time = $request->end_time ?: '';
  121. $start_time = str_replace('T', ' ', $start_time ?? "");
  122. $end_time = str_replace('T', ' ', $end_time ?? "");
  123. $GameID = $request->GameID ?: '';
  124. $Type = $request->Type ?: 0;
  125. $SortID = $request->SortID ?: -1;
  126. $where[] = ['KindID', 5008];
  127. $sortArr = ['-1' => '全部','1' => '初级场','2' => '中级场','3' => '高级场'];
  128. $typeArr = [0 => '全部',1 => '免费',2 => '买入'];
  129. !empty($start_time) && $where[] = ['CreateTime', '>=', $start_time];
  130. !empty($end_time) && $where[] = ['CreateTime', '<=', $end_time];
  131. !empty($GameID) && $where[] = ['GameID', $GameID];
  132. !empty($Type) && $where[] = ['Type', $Type];
  133. ($SortID>=0) && $where[] = ['SortID', $SortID];
  134. $list = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs as ri')
  135. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ri.UserID', 'ai.UserID')
  136. ->where($where)
  137. ->selectRaw('ri.*,ai.GameID,ai.NickName,Channel')
  138. ->orderByDesc('CreateTime')
  139. ->paginate(10);
  140. foreach ($where as $k => $v){
  141. if($v[0] == 'GameID'){
  142. unset($where[$k]);
  143. break;
  144. }
  145. }
  146. $sumData = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs')
  147. ->where($where)
  148. ->selectRaw('sum(ChangeScore) sumwin,sum(BuyScore) sumbuy')
  149. ->first();
  150. foreach ($list as $value) {
  151. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  152. $value->BuyBase = number_float($value->BuyBase / NumConfig::NUM_VALUE);
  153. $value->BuyScore = $value->BuyScore;
  154. }
  155. $gameName = '金牛全屏';
  156. $action = '/admin/game_data/RabbitBuyRecord';
  157. $data = compact('list', 'Type', 'start_time', 'end_time', 'GameID', 'SortID','typeArr','sortArr','sumData','gameName','action');
  158. return view('admin.game_data.gate_record', $data);
  159. }
  160. /**
  161. * 用户保护日志
  162. * 数据来源:QPRecordDB.dbo.RecordProtectLogs
  163. * 关联:AccountsInfo(GameID / RegisterDate / LastLogonDate)、GameKindItem(KindName)
  164. */
  165. public function protectLogs(Request $request)
  166. {
  167. $gameID = (int)($request->get('GameID') ?: 0);
  168. $vip = $request->get('vip', ''); // ''=全部, '1'=付费保护, '0'=非付费
  169. $start_date = $request->get('start_date', '');
  170. $end_date = $request->get('end_date', '');
  171. $query = DB::connection('read')
  172. ->table('QPRecordDB.dbo.RecordProtectLogs as rpl')
  173. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'rpl.UserID', '=', 'ai.UserID')
  174. ->leftJoin('QPPlatformDB.dbo.GameKindItem as gk', 'rpl.GameCode', '=', 'gk.KindID');
  175. // 会员ID筛选(GameID)
  176. if ($gameID) {
  177. $query->where('ai.GameID', $gameID);
  178. }
  179. // 付费保护筛选
  180. if ($vip !== '' && $vip !== null) {
  181. $query->where('rpl.VIP', (int)$vip);
  182. }
  183. // 日期筛选(按保护时间 CreateTime)
  184. if (!empty($start_date)) {
  185. $query->where('rpl.CreateTime', '>=', $start_date . ' 00:00:00');
  186. }
  187. if (!empty($end_date)) {
  188. $query->where('rpl.CreateTime', '<=', $end_date . ' 23:59:59');
  189. }
  190. $list = $query
  191. ->selectRaw('rpl.*, ai.GameID, ai.RegisterDate, ai.LastLogonDate, gk.KindName')
  192. ->orderByDesc('rpl.CreateTime')
  193. ->paginate(20);
  194. // 金额除以 100
  195. foreach ($list as $item) {
  196. $item->WinAmount = number_float($item->WinAmount / NumConfig::NUM_VALUE);
  197. }
  198. // VIP 选项
  199. $vipOptions = [
  200. '' => '全部',
  201. '1' => '付费保护',
  202. '0' => '非付费保护',
  203. ];
  204. return view('admin.game_data.protect_logs', [
  205. 'list' => $list,
  206. 'gameID' => $gameID ?: '',
  207. 'vip' => (string)$vip,
  208. 'vipOptions' => $vipOptions,
  209. 'start_date' => $start_date,
  210. 'end_date' => $end_date,
  211. ]);
  212. }
  213. public function NewOlympusBuyRecord(Request $request)
  214. {
  215. $start_time = $request->start_time ?: '';
  216. $end_time = $request->end_time ?: '';
  217. $start_time = str_replace('T', ' ', $start_time ?? "");
  218. $end_time = str_replace('T', ' ', $end_time ?? "");
  219. $GameID = $request->GameID ?: '';
  220. $Type = $request->Type ?: 0;
  221. $SortID = $request->SortID ?: -1;
  222. $where[] = ['KindID', 6001];
  223. $sortArr = ['-1' => '全部','1' => '初级场','2' => '中级场','3' => '高级场'];
  224. $typeArr = [0 => '全部',1 => '免费',2 => '买入'];
  225. !empty($start_time) && $where[] = ['CreateTime', '>=', $start_time];
  226. !empty($end_time) && $where[] = ['CreateTime', '<=', $end_time];
  227. !empty($GameID) && $where[] = ['GameID', $GameID];
  228. !empty($Type) && $where[] = ['Type', $Type];
  229. ($SortID>=0) && $where[] = ['SortID', $SortID];
  230. $list = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs as ri')
  231. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ri.UserID', 'ai.UserID')
  232. ->where($where)
  233. ->selectRaw('ri.*,ai.GameID,ai.NickName,Channel')
  234. ->orderByDesc('CreateTime')
  235. ->paginate(10);
  236. foreach ($where as $k => $v){
  237. if($v[0] == 'GameID'){
  238. unset($where[$k]);
  239. break;
  240. }
  241. }
  242. $sumData = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs')
  243. ->where($where)
  244. ->selectRaw('sum(ChangeScore) sumwin,sum(BuyScore) sumbuy')
  245. ->first();
  246. foreach ($list as $value) {
  247. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  248. $value->BuyBase = number_float($value->BuyBase / NumConfig::NUM_VALUE);
  249. $value->BuyScore = $value->BuyScore;
  250. }
  251. $gameName = '新宙斯全屏';
  252. $action = '/admin/game_data/NewolyBuyRecord';
  253. $data = compact('list', 'Type', 'start_time', 'end_time', 'GameID', 'SortID','typeArr','sortArr','sumData','gameName','action');
  254. return view('admin.game_data.gate_record', $data);
  255. }
  256. public function AztecBuyRecord(Request $request)
  257. {
  258. $start_time = $request->start_time ?: '';
  259. $end_time = $request->end_time ?: '';
  260. $start_time = str_replace('T', ' ', $start_time ?? "");
  261. $end_time = str_replace('T', ' ', $end_time ?? "");
  262. $GameID = $request->GameID ?: '';
  263. $Type = $request->Type ?: 0;
  264. $SortID = $request->SortID ?: -1;
  265. $where[] = ['KindID', 5004];
  266. $sortArr = ['-1' => '全部','1' => '初级场','2' => '中级场','3' => '高级场'];
  267. $typeArr = [0 => '全部',1 => '免费',2 => '买入'];
  268. !empty($start_time) && $where[] = ['CreateTime', '>=', $start_time];
  269. !empty($end_time) && $where[] = ['CreateTime', '<=', $end_time];
  270. !empty($GameID) && $where[] = ['GameID', $GameID];
  271. !empty($Type) && $where[] = ['Type', $Type];
  272. ($SortID>=0) && $where[] = ['SortID', $SortID];
  273. $list = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs as ri')
  274. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ri.UserID', 'ai.UserID')
  275. ->where($where)
  276. ->selectRaw('ri.*,ai.GameID,ai.NickName,Channel')
  277. ->orderByDesc('CreateTime')
  278. ->paginate(10);
  279. foreach ($where as $k => $v){
  280. if($v[0] == 'GameID'){
  281. unset($where[$k]);
  282. break;
  283. }
  284. }
  285. $sumData = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs')
  286. ->where($where)
  287. ->selectRaw('sum(ChangeScore) sumwin,sum(BuyScore) sumbuy')
  288. ->first();
  289. foreach ($list as $value) {
  290. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  291. $value->BuyBase = number_float($value->BuyBase / NumConfig::NUM_VALUE);
  292. $value->BuyScore = $value->BuyScore;
  293. }
  294. $gameName = 'Aztec全屏';
  295. $action = '/admin/game_data/AztecBuyRecord';
  296. $data = compact('list', 'Type', 'start_time', 'end_time', 'GameID', 'SortID','typeArr','sortArr','sumData','gameName','action');
  297. return view('admin.game_data.gate_record', $data);
  298. }
  299. public function fishBuyRecord(Request $request)
  300. {
  301. $start_time = $request->start_time ?: '';
  302. $end_time = $request->end_time ?: '';
  303. $start_time = str_replace('T', ' ', $start_time ?? "");
  304. $end_time = str_replace('T', ' ', $end_time ?? "");
  305. $GameID = $request->GameID ?: '';
  306. $Type = $request->Type ?: 0;
  307. $SortID = $request->SortID ?: -1;
  308. $where[] = ['KindID', 5005];
  309. $sortArr = ['-1' => '全部','1' => '初级场','2' => '中级场','3' => '高级场'];
  310. $typeArr = [0 => '全部',1 => '免费',2 => '买入'];
  311. !empty($start_time) && $where[] = ['CreateTime', '>=', $start_time];
  312. !empty($end_time) && $where[] = ['CreateTime', '<=', $end_time];
  313. !empty($GameID) && $where[] = ['GameID', $GameID];
  314. !empty($Type) && $where[] = ['Type', $Type];
  315. ($SortID>=0) && $where[] = ['SortID', $SortID];
  316. $list = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs as ri')
  317. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ri.UserID', 'ai.UserID')
  318. ->where($where)
  319. ->selectRaw('ri.*,ai.GameID,ai.NickName,Channel')
  320. ->orderByDesc('CreateTime')
  321. ->paginate(10);
  322. foreach ($where as $k => $v){
  323. if($v[0] == 'GameID'){
  324. unset($where[$k]);
  325. break;
  326. }
  327. }
  328. $sumData = DB::connection('write')->table('QPRecordDB.dbo.RecordNewThunderBonueLogs')
  329. ->where($where)
  330. ->selectRaw('sum(ChangeScore) sumwin,sum(BuyScore) sumbuy')
  331. ->first();
  332. foreach ($list as $value) {
  333. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  334. $value->BuyBase = number_float($value->BuyBase / NumConfig::NUM_VALUE);
  335. $value->BuyScore = $value->BuyScore;
  336. }
  337. $gameName = '钓鱼全屏';
  338. $action = '/admin/game_data/fishBuyRecord';
  339. $data = compact('list', 'Type', 'start_time', 'end_time', 'GameID', 'SortID','typeArr','sortArr','sumData','gameName','action');
  340. return view('admin.game_data.gate_record', $data);
  341. }
  342. //实时在线
  343. public function userOnline(Request $request)
  344. {
  345. $game_id = $request->game_id ?? '';
  346. $type = $request->type??0;
  347. $start_date = $request->start_date ?? date('Y-m-d');
  348. if($type == 0 && $start_date == date('Y-m-d')){
  349. $time = time();
  350. $where= [['created', '<=', $time],['created', '>=', $time-86400]];
  351. $data = DB::connection('mysql')->table('game-report')
  352. ->where($where)
  353. ->orderBy('created', 'asc')
  354. ->get();
  355. //$whereY[] = ['ldate', '=', date('Ymd', strtotime($yesterday))];
  356. $whereY= [['created', '<=', $time-86400],['created', '>=', $time-86400*2]];
  357. $ydata = DB::connection('mysql')->table('game-report')
  358. ->where($whereY)
  359. ->orderBy('created', 'asc')
  360. ->get();
  361. }else{
  362. $yesterday = date('Y-m-d',strtotime($start_date)-86400);
  363. $where[] = ['ldate', '=', date('Ymd', strtotime($start_date))];
  364. $data = DB::connection('mysql')->table('game-report')
  365. ->where($where)
  366. ->orderBy('created', 'asc')
  367. ->get();
  368. $whereY[] = ['ldate', '=', date('Ymd', strtotime($yesterday))];
  369. $ydata = DB::connection('mysql')->table('game-report')
  370. ->where($whereY)
  371. ->orderBy('created', 'asc')
  372. ->get();
  373. }
  374. $result = [
  375. ];
  376. foreach ($data as $key => $value) {
  377. $online = json_decode($value->online,true);
  378. $onlineNum = 0;
  379. if(is_array($online)){
  380. foreach ($online as $val){
  381. if($val['KindID'] == $game_id){
  382. $onlineNum = $val['game_count'];
  383. break;
  384. }
  385. $onlineNum +=$val['game_count'];
  386. }
  387. }
  388. $min = date('Hi',$value->created);
  389. $min = 'm_'.$min;
  390. $result['online'][$min] = $onlineNum;//训练币消耗
  391. // $result['online'][$min] = $value->online;//训练币消耗
  392. $result['reg'][$min] = $value->register;//累计场次
  393. $result['active'][$min] = $value->active;//参游人数
  394. $result['recharge'][$min] = $value->recharge/100;//新增数
  395. $result['withdraw'][$min] = $value->withdraw/100;
  396. $result['profit'][$min] = ($value->recharge-$value->withdraw)/100;
  397. $result['created_at'][$min] = date('Y-m-d H:i',$value->created);
  398. $result['yonline'][$min] = 0;
  399. $result['yreg'][$min] = 0;
  400. $result['yactive'][$min] = 0;
  401. $result['yrecharge'][$min] = 0;
  402. $result['ywithdraw'][$min] = 0;
  403. }
  404. unset($value);
  405. foreach ($ydata as $key => $value) {
  406. $min = date('Hi',$value->created);
  407. $min = 'm_'.$min;
  408. if(isset($result['reg'][$min])){
  409. $online = json_decode($value->online,true);
  410. $onlineNum = 0;
  411. if(is_array($online)){
  412. foreach ($online as $val){
  413. if($val['KindID'] == $game_id){
  414. $onlineNum = $val['game_count'];
  415. break;
  416. }
  417. $onlineNum +=$val['game_count'];
  418. }
  419. }
  420. $result['yonline'][$min] = $onlineNum;//训练币消耗
  421. $result['yreg'][$min] = $value->register;//累计场次
  422. $result['yactive'][$min] = $value->active;//参游人数
  423. $result['yrecharge'][$min] = $value->recharge/100;//新增数
  424. $result['ywithdraw'][$min] = $value->withdraw/100;
  425. $result['yprofit'][$min] = ($value->recharge-$value->withdraw)/100;
  426. }
  427. }
  428. $rs = [
  429. 'online' => array_values($result['online']),
  430. 'reg' => array_values($result['reg']),
  431. 'active' => array_values($result['active']),
  432. 'recharge' => array_values($result['recharge']),
  433. 'withdraw' => array_values($result['withdraw']),
  434. 'profit' => array_values($result['profit']),
  435. 'created_at' => array_values($result['created_at']),
  436. 'yonline' => array_values($result['yonline']),
  437. 'yreg' => array_values($result['yreg']),
  438. 'yactive' => array_values($result['yactive']),
  439. 'yrecharge' => array_values($result['yrecharge']),
  440. 'ywithdraw' => array_values($result['ywithdraw']),
  441. 'yprofit' => array_values($result['yprofit']?? []),
  442. ];
  443. return $rs;
  444. }
  445. public function onlineList(Request $request){
  446. $GameID = $request->get('GameID');
  447. $SortID = $request->get('SortID');
  448. $uid = $request->get('uid');
  449. if($uid){
  450. $where = [];
  451. $where[] = ['ai.GameID', $uid];
  452. }else{
  453. $where = [];
  454. !empty($GameID) && $where[] = ['gi.GameID', $GameID];
  455. !empty($SortID) && $where[] = ['gi.SortID', $SortID];
  456. }
  457. $list = DB::connection('read')->table('QPTreasureDB.dbo.GameScoreLocker as gl')
  458. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'gl.UserID', 'ai.UserID')
  459. ->leftJoin('QPPlatformDB.dbo.GameRoomInfo as gi','gl.ServerID','gi.ServerID')
  460. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gsi','gl.UserID','=','gsi.UserID')
  461. ->where($where)
  462. ->selectRaw('ai.GameID,ai.NickName,Channel,gi.ServerName,gi.SortID,gl.CollectDate,gl.UserID,gsi.Score')
  463. // ->orderByDesc('CreateTime')
  464. ->paginate(10);
  465. $games = DB::connection('read')->table(TableName::QPPlatformDB() . 'GameKindItem')
  466. ->whereIn('GameID', config('games.openKGame'))
  467. ->select('KindName', 'GameID')
  468. ->pluck('KindName', 'GameID')
  469. ->toArray();
  470. $type = [
  471. 1 => '初级',
  472. 2 => '中级',
  473. 3 => '高级',
  474. 4 => '超高级'
  475. ];
  476. $data = compact('list', 'GameID', 'SortID','uid','games','type');
  477. return view('admin.game_data.game_online', $data);
  478. }
  479. public function gameRankList(Request $request){
  480. $date = $request->date ?: date('Y-m-d');
  481. $dateFormat = date('Ymd',strtotime($date));
  482. $channels =session('admin_channels');;
  483. $Channel = $request->get('Channel');
  484. $sort = $request->sort??1;
  485. $where = [];
  486. $where[] = ['rd.DateID', $dateFormat];
  487. if(!empty($Channel)) {
  488. $where[] = ['ai.Channel', $Channel];
  489. }
  490. $rank = [1 =>'Win Rank',2 =>'Lost Rank',3 => 'MaxWin Rank',4 => 'Recharge Rank',5 => 'Withdraw Rank'];
  491. $order_sql = '(WinScore + LostScore) DESC';
  492. switch ($sort) {
  493. case '1':
  494. $order_sql = '(WinScore + LostScore) DESC';
  495. break;
  496. case '2':
  497. $order_sql = '(WinScore + LostScore) ASC';
  498. break;
  499. case '3':
  500. $order_sql = 'MaxWinScore DESC';
  501. break;
  502. case '4':
  503. $order_sql = 'Recharge DESC';
  504. break;
  505. case '5':
  506. $order_sql = 'Withdraw DESC';
  507. break;
  508. }
  509. $list = DB::connection('read')->table('QPRecordDB.dbo.RecordUserDataStatisticsNew as rd')
  510. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'rd.UserID', 'ai.UserID')
  511. ->where($where)
  512. ->selectRaw('ai.UserID,ai.GameID,ai.NickName,Channel,ai.LastLogonDate,ai.RegisterDate,Recharge, (WinScore + LostScore) Score,MaxScore,MaxWinScore,Withdraw,MaxDrawBase,Revenue,TotalBet')
  513. ->orderByRaw($order_sql)
  514. ->paginate(20);
  515. $data = compact('list', 'date','rank','sort','Channel','channels');
  516. return view('admin.game_data.rank', $data);
  517. }
  518. public function userDetail(\Illuminate\Http\Request $request)
  519. {
  520. $userId = $request->input('user_id');
  521. $startDate = $request->input('start_date', date('Y-m-d', strtotime('-6 days')));
  522. $endDate = $request->input('end_date', date('Y-m-d'));
  523. $list = [];
  524. if ($userId) {
  525. $list = \DB::connection('read')->table('QPRecordDB.dbo.RecordUserDataStatisticsNew as rd')
  526. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'rd.UserID', 'ai.UserID')
  527. ->where('ai.GameID', $userId)
  528. ->whereBetween('rd.DateID', [
  529. date('Ymd', strtotime($startDate)),
  530. date('Ymd', strtotime($endDate))
  531. ])
  532. ->selectRaw('rd.DateID, ai.UserID, ai.GameID, ai.NickName, Channel, ai.LastLogonDate, ai.RegisterDate, Recharge, (WinScore + LostScore) Score, MaxScore, MaxWinScore, Withdraw, MaxDrawBase, Revenue, TotalBet')
  533. ->orderBy('rd.DateID', 'desc')
  534. ->paginate(20);
  535. }
  536. return view('admin.game_data.user_detail', [
  537. 'list' => $list,
  538. 'user_id' => $userId,
  539. 'start_date' => $startDate,
  540. 'end_date' => $endDate,
  541. ]);
  542. }
  543. public function userTotalList(\Illuminate\Http\Request $request)
  544. {
  545. $rechargeMax = $request->input('recharge_max', 300);
  546. $withdrawMin = $request->input('withdraw_min', 1000);
  547. $list = \DB::connection('read')->table('QPRecordDB.dbo.RecordUserTotalStatistics as ut')
  548. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ut.UserID', '=', 'ai.UserID')
  549. ->where('ut.Recharge', '<=', $rechargeMax)
  550. ->where('ut.Withdraw', '>', $withdrawMin * 100)
  551. ->selectRaw('ai.UserID, ai.GameID, ai.NickName, ai.Channel, ai.LastLogonDate, ai.RegisterDate, (ut.WinScore + ut.LostScore) as TotalScore, ut.WinScore, ut.LostScore, ut.Revenue, ut.Withdraw, ut.Recharge, ut.DrawBase, ut.TotalBet, ut.RechargeTimes')
  552. ->orderByDesc('ai.LastLogonDate')
  553. ->paginate(20);
  554. return view('admin.user_total.list', [
  555. 'list' => $list,
  556. 'recharge_max' => $rechargeMax,
  557. 'withdraw_min' => $withdrawMin,
  558. ]);
  559. }
  560. /**
  561. * 游戏参与情况统计
  562. * 按照注册时间统计不同UserMedal(推荐游戏ID)对应的游戏参与情况
  563. */
  564. public function gameParticipationStatistics(Request $request)
  565. {
  566. // 获取注册时间范围,默认近3天
  567. $startDate = $request->input('start_date', date('Y-m-d', strtotime('-3 days')));
  568. $endDate = $request->input('end_date', date('Y-m-d'));
  569. // 转换为日期时间格式(包含时间)
  570. $startDateTime = $startDate . ' 00:00:00';
  571. $endDateTime = $endDate . ' 23:59:59';
  572. // 1. 统计注册人数(按UserMedal分组)
  573. $registerStats = DB::connection('read')
  574. ->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  575. ->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
  576. ->whereNotNull('ai.UserMedal')
  577. ->where('ai.UserMedal', '!=', '')
  578. ->where('ai.UserMedal', '!=', 0)
  579. ->where('ai.Channel', '!=', 100)
  580. ->selectRaw('
  581. ai.UserMedal as game_id,
  582. COUNT(DISTINCT ai.UserID) as register_count
  583. ')
  584. ->groupBy('ai.UserMedal')
  585. ->get()
  586. ->keyBy('game_id');
  587. // 2. 统计参与游戏的用户数(WinInning + LostInning > 0,按UserMedal分组)
  588. $playedStats = DB::connection('read')
  589. ->table('QPRecordDB.dbo.RecordUserTotalStatistics as ut')
  590. ->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'ut.UserID', '=', 'ai.UserID')
  591. ->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
  592. ->whereNotNull('ai.UserMedal')
  593. ->where('ai.UserMedal', '!=', '')
  594. ->where('ai.UserMedal', '!=', 0)
  595. ->where('ai.Channel', '!=', 100)
  596. ->whereRaw('(ISNULL(ut.WinInning, 0) + ISNULL(ut.LostInning, 0)) > 0')
  597. ->selectRaw('
  598. ai.UserMedal as game_id,
  599. COUNT(DISTINCT ai.UserID) as played_count
  600. ')
  601. ->groupBy('ai.UserMedal')
  602. ->get()
  603. ->keyBy('game_id');
  604. // 3. 统计付费用户数(Recharge > 0,按UserMedal分组)
  605. $paidStats = DB::connection('read')
  606. ->table('QPRecordDB.dbo.RecordUserTotalStatistics as ut')
  607. ->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'ut.UserID', '=', 'ai.UserID')
  608. ->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
  609. ->whereNotNull('ai.UserMedal')
  610. ->where('ai.UserMedal', '!=', '')
  611. ->where('ai.UserMedal', '!=', 0)
  612. ->where('ai.Channel', '!=', 100)
  613. ->where('ut.Recharge', '>', 0)
  614. ->selectRaw('
  615. ai.UserMedal as game_id,
  616. COUNT(DISTINCT ai.UserID) as paid_count
  617. ')
  618. ->groupBy('ai.UserMedal')
  619. ->get()
  620. ->keyBy('game_id');
  621. // 4. 获取所有涉及的游戏ID
  622. $allGameIds = collect([$registerStats, $playedStats, $paidStats])
  623. ->flatMap(function ($stats) {
  624. return $stats->pluck('game_id');
  625. })
  626. ->unique()
  627. ->filter()
  628. ->toArray();
  629. // 5. 获取游戏信息(从MySQL)
  630. $games = [];
  631. if (!empty($allGameIds)) {
  632. $gamesData = DB::connection('mysql')
  633. ->table('webgame.games')
  634. ->whereIn('id', $allGameIds)
  635. ->select('id', 'brand', 'title')
  636. ->get();
  637. foreach ($gamesData as $game) {
  638. $games[$game->id] = $game;
  639. }
  640. }
  641. // 6. 组装统计数据
  642. $statistics = [];
  643. foreach ($allGameIds as $gameId) {
  644. $registerStat = $registerStats->get($gameId);
  645. $registerCount = $registerStat ? (int)$registerStat->register_count : 0;
  646. $playedStat = $playedStats->get($gameId);
  647. $playedCount = $playedStat ? (int)$playedStat->played_count : 0;
  648. $paidStat = $paidStats->get($gameId);
  649. $paidCount = $paidStat ? (int)$paidStat->paid_count : 0;
  650. // 参游率 = 参与游戏人数 / 注册人数
  651. $participationRate = $registerCount > 0 ? round(($playedCount / $registerCount) * 100, 2) : 0;
  652. // 付费率 = 付费人数 / 注册人数
  653. $paidRate = $registerCount > 0 ? round(($paidCount / $registerCount) * 100, 2) : 0;
  654. // 获取游戏名称
  655. $gameName = '未知游戏';
  656. if (isset($games[$gameId])) {
  657. $game = $games[$gameId];
  658. $gameName = $game->brand . ' - ' . $game->title;
  659. }
  660. $statistics[] = [
  661. 'game_id' => $gameId,
  662. 'game_name' => $gameName,
  663. 'register_count' => $registerCount,
  664. 'played_count' => $playedCount,
  665. 'participation_rate' => $participationRate,
  666. 'paid_count' => $paidCount,
  667. 'paid_rate' => $paidRate,
  668. ];
  669. }
  670. // 按注册人数排序(降序)
  671. usort($statistics, function ($a, $b) {
  672. return $b['register_count'] <=> $a['register_count'];
  673. });
  674. return view('admin.game_data.participation_statistics', [
  675. 'statistics' => $statistics,
  676. 'start_date' => $startDate,
  677. 'end_date' => $endDate,
  678. ]);
  679. }
  680. }