2
0

WinLoseRankController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 WinLoseRankController extends Controller
  9. {
  10. public function index(Request $req)
  11. {
  12. $condition = ['DateID' => date('Ymd'), ['v.Recharge', '>', 0]];
  13. $q = DB::table('QPRecordDB.dbo.RecordUserDataStatisticsNew as ruds');
  14. // 排序逻辑
  15. if ($req->input('sortBy')) {
  16. $sortBy = $req->input('sortBy');
  17. $sortType = $req->input('sortType', 'asc');
  18. if ($sortBy == 'rtp') {
  19. $sort = 'CASE WHEN ruds.TotalBet > 0 THEN (ruds.TotalBet + (ruds.WinScore + ruds.LostScore))*1.0/ruds.TotalBet ELSE 0 END ' . $sortType;
  20. $q->orderByRaw($sort);
  21. } elseif ($sortBy == 'winlose') {
  22. $sort = '(ruds.WinScore + ruds.LostScore) ' . $sortType;
  23. $q->orderByRaw($sort);
  24. }
  25. }
  26. $q->select([
  27. 'ruds.UserID',
  28. 'ruds.WinScore',
  29. 'ruds.LostScore',
  30. 'ruds.TotalBet',
  31. DB::raw('CASE WHEN ruds.TotalBet > 0 THEN (ruds.TotalBet + (ruds.WinScore + ruds.LostScore))*1.0/ruds.TotalBet ELSE 0 END as rtp'),
  32. DB::raw('0 as sameRW'),
  33. DB::raw('-1 as KindID'), DB::raw('0 as TotalRecharge'), DB::raw('0 as TotalWithdraw'),
  34. DB::raw('\'\' as EmailAddress'), DB::raw('\'\' as PhoneNum'), DB::raw('0 as GameID'),
  35. ])
  36. ->leftJoin('QPAccountsDB.dbo.YN_VIPAccount as v', 'v.UserID', '=', 'ruds.UserID')
  37. ->where($condition);
  38. // 在线状态筛选
  39. $onlineStatus = $req->input('online_status');
  40. if ($onlineStatus == 1) {
  41. // 在线:有记录
  42. $q->leftJoin('QPTreasureDB.dbo.GameScoreLocker as gsl', 'gsl.UserID', '=', 'ruds.UserID')
  43. ->whereNotNull('gsl.UserID');
  44. } elseif ($onlineStatus == 2) {
  45. // 离线:无记录
  46. $q->leftJoin('QPTreasureDB.dbo.GameScoreLocker as gsl', 'gsl.UserID', '=', 'ruds.UserID')
  47. ->whereNull('gsl.UserID');
  48. }
  49. $page = $q->paginate(15);
  50. if ($page->count() > 0) {
  51. $uids = array_column($page->items(), 'UserID');
  52. $lockers = DB::table('QPTreasureDB.dbo.GameScoreLocker')->whereIn('UserID', $uids)
  53. ->pluck('KindID', 'UserID')->toArray();
  54. $phones = DB::table('QPAccountsDB.dbo.AccountPhone as ap')->whereIn('UserID', $uids)
  55. ->pluck('PhoneNum', 'UserID')->toArray();
  56. foreach ($page->items() as $key => $item) {
  57. $item->PhoneNum = $phones[$item->UserID] ?? '';
  58. }
  59. $GameIDs = DB::table('QPAccountsDB.dbo.AccountsInfo as ai')->whereIn('UserID', $uids)
  60. ->pluck('GameID', 'UserID')->toArray();
  61. foreach ($page->items() as $key => $item) {
  62. $item->GameID = $GameIDs[$item->UserID] ?? '';
  63. }
  64. $emails = DB::table('QPAccountsDB.dbo.AccountWithdrawInfo as awi')->whereIn('UserID', $uids)
  65. ->pluck('EmailAddress', 'UserID')->toArray();
  66. foreach ($page->items() as $key => $item) {
  67. $item->EmailAddress = $emails[$item->UserID] ?? '';
  68. }
  69. // 身上的钱
  70. $gameScores = DB::table('QPTreasureDB.dbo.GameScoreInfo')
  71. ->lock('with(nolock)')
  72. ->whereIn('UserID', $uids)
  73. ->pluck('Score', 'UserID')->toArray();
  74. // 待审核提现
  75. $orderWtihdraws = DB::table('QPAccountsDB.dbo.OrderWithDraw')
  76. ->lock('with(nolock)')
  77. ->whereIn('UserID', $uids)
  78. ->where('State', 1)
  79. ->selectRaw('SUM(WithDraw) as WithDraw, UserID')
  80. ->groupBy('UserID')
  81. ->pluck('WithDraw', 'UserID')->toArray();
  82. $totals = DB::table('QPRecordDB.dbo.RecordUserTotalStatistics as ruts')->whereIn('UserID', $uids)
  83. ->get()->toArray();
  84. foreach ($page->items() as $key => $item) {
  85. $item->Score = $gameScores[$item->UserID] ?? 0;
  86. $item->WithDrawWaitAudit = $orderWtihdraws[$item->UserID] ?? 0;
  87. foreach ($totals as $total) {
  88. if ($item->UserID == $total->UserID) {
  89. $item->TotalRecharge = $total->Recharge;
  90. $item->TotalWithdraw = $total->Withdraw;
  91. }
  92. }
  93. }
  94. //关联用户信息
  95. $phones = array_filter(array_column($page->items(), 'PhoneNum'));
  96. $emails = array_filter(array_column($page->items(), 'EmailAddress'));
  97. $phoneRWs = [];
  98. if (count($phones) > 0) {
  99. $phoneUids = DB::table('QPAccountsDB.dbo.AccountPhone')->whereIn('PhoneNum', $phones)
  100. ->get()->toArray();
  101. if (count($phoneUids) > 0) {
  102. $res = DB::table('QPRecordDB.dbo.RecordUserTotalStatistics')
  103. ->whereIn('UserID', array_column($phoneUids, 'UserID'))
  104. ->get();
  105. foreach ($res as $row) {
  106. foreach ($phoneUids as $ap) {
  107. if ($ap->UserID == $row->UserID) {
  108. $phone = $ap->PhoneNum;
  109. if (!isset($phoneRWs[$phone])) {
  110. $phoneRWs[$phone] = [];
  111. }
  112. $phoneRWs[$phone][$row->UserID] = $row->Recharge - $row->Withdraw / NumConfig::NUM_VALUE;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. $emailRWs = [];
  119. if (count($emails) > 0) {
  120. $emailUids = DB::table('QPAccountsDB.dbo.AccountWithdrawInfo')
  121. ->whereIn('EmailAddress', $emails)
  122. ->get()->toArray();
  123. if (count($emailUids) > 0) {
  124. $res = DB::table('QPRecordDB.dbo.RecordUserTotalStatistics')
  125. ->whereIn('UserID', array_column($emailUids, 'UserID'))
  126. ->get();
  127. foreach ($res as $row) {
  128. foreach ($emailUids as $awi) {
  129. if ($awi->UserID == $row->UserID) {
  130. $email = $awi->EmailAddress;
  131. if (!isset($emailRWs[$email])) {
  132. $emailRWs[$email] = [];
  133. }
  134. $emailRWs[$email][$row->UserID] = $row->Recharge - $row->Withdraw / NumConfig::NUM_VALUE;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. foreach ($page as $k => $v) {
  141. $uidRws = [];
  142. if ($v->EmailAddress) {
  143. foreach ($emailRWs[$v->EmailAddress] ?? [] as $uid => $value) {
  144. $uidRws[$uid] = $value;
  145. }
  146. }
  147. if ($v->PhoneNum) {
  148. foreach ($phoneRWs[$v->PhoneNum] ?? [] as $uid => $value) {
  149. $uidRws[$uid] = $value;
  150. }
  151. }
  152. $page[$k]->sameRW = array_sum($uidRws);
  153. $page[$k]->KindID = $lockers[$v->UserID] ?? -1;
  154. }
  155. }
  156. $gameServerNames = DB::table(TableName::QPPlatformDB() . 'RoomConfig')
  157. ->pluck('RoomName', 'GameID')->toArray();
  158. return view('admin.win_lose_rank.index', ['list' => $page, 'gameServerNames' => $gameServerNames, 'request' => $req]);
  159. }
  160. }