GlobalUser.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. <?php
  2. namespace App\Services;
  3. use App\Facade\Redis;
  4. use App\Facade\TableName;
  5. use App\Http\helper\HttpCurl;
  6. use App\Http\helper\NumConfig;
  7. use App\Http\logic\admin\GlobalLogicController;
  8. use App\Http\logic\api\BaseApiLogic;
  9. use App\Models\AccountsInfo;
  10. use App\Models\Control;
  11. use App\Models\Order;
  12. use App\Models\RecordPlatformData;
  13. use App\Models\Withdrawal;
  14. use App\Util;
  15. use Illuminate\Support\Arr;
  16. use Illuminate\Support\Facades\DB;
  17. class GlobalUser extends BaseApiLogic
  18. {
  19. public function onLineUser($index, $count = 10)
  20. {
  21. $admin = session('admin');
  22. $account = $admin->account ?: '';
  23. $password = $admin->password ?: '';
  24. $url = config('transfer.stock')['url'] . 'queryOnlineByPage';
  25. $index = $index > 0 ? ($index - 1) * $count : 0;
  26. $data = [
  27. 'accounts' => $account,
  28. 'passworld' => $password,
  29. 'pos' => $index,
  30. 'count' => $count
  31. ];
  32. $build_query = $url . '?' . http_build_query($data);
  33. $json_decode = (new HttpCurl())->curl_get($build_query);
  34. if (empty($json_decode)) {
  35. $output = [];
  36. } else {
  37. $output = \GuzzleHttp\json_decode($json_decode, true);
  38. }
  39. $data = [];
  40. if (is_array($output)) {
  41. $toArr = explode(',', $output['data'] ?? '');
  42. $data['UserIDs'] = $toArr;
  43. $data['total'] = $output['total'];
  44. }
  45. return $data;
  46. }
  47. public function userlist($gameID, $phoneNum, $spreaderID, $nickName, $startTime, $endTime, $obj, $vip, $excel, $accountsType, $channel, $user_tab, $packgeName, $quickSearch, $score,$MachineID,$startLoginTime='',$endLoginTime='')
  48. {
  49. $quickSearch = explode(',', trim($quickSearch, ','));
  50. $AccountsInfoM = new AccountsInfo();
  51. $StatusValue = DB::connection('read')->table('QPAccountsDB.dbo.SystemStatusInfo')
  52. ->where('StatusName', 'WithDrawPoint')
  53. ->select('StatusValue')
  54. ->first()->StatusValue ?? 0;
  55. $adminChannels=session('admin_channels');
  56. $field = ['ai.GameID', 'ai.UserID', 'ai.SpreaderID', 'ai.NickName', 'ai.MemberOrder', 'ai.Nullity', 'ai.WebLogonTimes', 'ai.LastLogonIP', 'ai.LastLogonDate', 'ai.RegisterIP', 'ai.RegisterDate', 'ai.Channel', 'gi.Score', 'gi.InsureScore', 'gi.MaxScore', 'gi.MaxWinScore'];
  57. $Sql = DB::connection('read')->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  58. ->leftJoin(TableName::QPTreasureDB() . 'GameScoreInfo as gi', 'ai.UserID', 'gi.UserID')
  59. ->where('ai.IsAndroid', 0)
  60. ->select($field);
  61. if(count($adminChannels)<5)$Sql=$Sql->whereIn('ai.Channel', $adminChannels);
  62. $where = [];
  63. if (!empty($gameID))
  64. $where[] = ['ai.GameID', $gameID];
  65. if (!empty($MachineID))
  66. $where[] = ['ai.LastLogonMachine', $MachineID];
  67. if (!empty($nickName))
  68. $where[] = ['ai.NickName', $nickName];
  69. if (!empty($startTime))
  70. $where[] = ['ai.RegisterDate', '>=', $startTime];
  71. if (!empty($endTime))
  72. $where[] = ['ai.RegisterDate', '<=', $endTime];
  73. if (!empty($startLoginTime))
  74. $where[] = ['ai.LastLogonDate', '>=', $startLoginTime];
  75. if (!empty($endLoginTime))
  76. $where[] = ['ai.LastLogonDate', '<=', $endLoginTime];
  77. if (!empty($vip))
  78. $where[] = ['ai.MemberOrder', $vip];
  79. if (!empty($channel))
  80. $where[] = ['ai.Channel', $channel];
  81. if (!empty($packgeName)) {
  82. $Sql = $Sql->join(TableName::QPRecordDB() . 'RecordPackageName as rn', 'ai.UserID')->where('PackgeName', $packgeName);
  83. }
  84. if (!empty($phoneNum)) {
  85. $Sql = $Sql->join(TableName::QPAccountsDB() . 'AccountPhone as ap', 'ai.UserID', 'ap.UserID')
  86. ->where('ap.PhoneNum', $phoneNum);
  87. }
  88. if (!empty($spreaderID)) {
  89. $Sql = $Sql->join(TableName::QPAccountsDB() . 'AccountsInfo as ai1', 'ai1.UserID', 'ai.SpreaderID')
  90. ->where('ai1.GameID', $spreaderID);
  91. }
  92. if (!empty($accountsType)) {
  93. if ($accountsType < 4 && empty($phoneNum)) {
  94. $Sql = $Sql->join(TableName::QPAccountsDB() . 'AccountPhone as ap', 'ai.UserID', 'ap.UserID');
  95. }
  96. switch ($accountsType) {
  97. case 1:
  98. $Sql = $Sql->where('ai.WebLogonTimes', 0)->whereNull('PhoneNum');
  99. break;
  100. case 2:
  101. $Sql = $Sql->where('ai.WebLogonTimes', 1)->whereNull('PhoneNum');
  102. break;
  103. case 3:
  104. $Sql = $Sql->WhereNotNull('PhoneNum');
  105. break;
  106. case 4:
  107. $Sql = $Sql->where('ai.Channel', 100);
  108. break;
  109. }
  110. }
  111. // 快速搜索
  112. if (!empty($quickSearch)) {
  113. // 游戏中
  114. if (in_array(1, $quickSearch)) {
  115. $Sql = $Sql->join(TableName::QPTreasureDB() . 'GameScoreLocker as gsl', 'gsl.UserID', 'ai.UserID')
  116. ->whereRaw('datediff(hh,CollectDate,getdate())<=5');
  117. }
  118. // 未实名
  119. if (in_array(2, $quickSearch)) {
  120. $Sql = $Sql->where('ai.PassPortID', '');
  121. }
  122. // 无手机号
  123. if (in_array(3, $quickSearch)) {
  124. $Sql = $Sql->whereNotExists(function ($query) {
  125. $query->from(TableName::QPAccountsDB() . 'AccountPhone as ap')
  126. ->whereRaw('ap.UserID=ai.UserID and ap.PhoneNum is not null');
  127. });
  128. }
  129. // 同IP
  130. if (in_array(4, $quickSearch)) {
  131. // TODO
  132. }
  133. // 无渠道
  134. if (in_array(5, $quickSearch)) {
  135. $Sql = $Sql->where('ai.Channel', 0);
  136. }
  137. // 未充值
  138. if (in_array(6, $quickSearch)) {
  139. $Sql = $Sql->whereNotExists(function ($query) {
  140. $query->from(TableName::QPRecordDB() . 'RecordUserTotalStatistics AS rts')
  141. ->where('Recharge', '>', 0)
  142. ->whereRaw('ai.UserID=rts.UserID');
  143. });
  144. }
  145. // 无上级
  146. if (in_array(7, $quickSearch)) {
  147. $Sql = $Sql->whereExists(function ($query) {
  148. $query->from(TableName::QPAccountsDB() . 'AccountsInfo AS ai1')
  149. ->where('SpreaderID', 0)
  150. ->whereRaw('ai.UserID=ai1.UserID');
  151. });
  152. }
  153. // 封号中
  154. if (in_array(8, $quickSearch)) {
  155. $Sql = $Sql->where('Nullity', 1);
  156. }
  157. // 官方账号
  158. if (in_array(9, $quickSearch)) {
  159. $Sql = $Sql->whereNotExists(function ($query) {
  160. $query->from(TableName::QPAccountsDB() . 'IDWhiteUser AS iu')
  161. ->whereRaw('ai.UserID=iu.UserID');
  162. });
  163. }
  164. }
  165. if (!empty($score)) {
  166. $orderBy = "Score $score";
  167. } else {
  168. $orderBy = 'ai.RegisterDate desc';
  169. }
  170. $list = $Sql->where($where)->orderByRaw($orderBy)->paginate(10);
  171. // 取出用户ID
  172. $UserIDs = [];
  173. foreach ($list as $value) {
  174. $UserIDs[] = $value->UserID;
  175. }
  176. // 用户上级ID
  177. $spreaderIDs = $AccountsInfoM->accountSpreaderID($UserIDs);
  178. // 输赢
  179. $winLost = $AccountsInfoM->accountWinLost($UserIDs);
  180. // 今日充值-- 今日提现-- 今日彩金 -- 总输赢
  181. $today = $AccountsInfoM->accountTodayStatistics($UserIDs);
  182. // 全部充值 -- 提现 -- 彩金 -- 总输赢 -- 总得提现手续费
  183. $total = $AccountsInfoM->accountTotalStatistics($UserIDs);
  184. // 游戏是否在线
  185. $userOnLine = DB::connection('read')->table(TableName::QPTreasureDB() . 'GameScoreLocker as gsl')
  186. ->whereIn('UserID', $UserIDs)
  187. ->join(TableName::QPPlatformDB() . 'GameRoomInfo as gri', 'gsl.ServerID', 'gri.ServerID')
  188. ->whereRaw('datediff(hh,CollectDate,getdate())<=5')
  189. ->select('ServerName', 'UserID')
  190. ->pluck('ServerName', 'UserID')->toArray();
  191. // 用户手机号
  192. $PhoneNums = $AccountsInfoM->accountPhone($UserIDs);
  193. foreach ($list as &$value) {
  194. $value->spreaderID = isset($spreaderIDs[$value->UserID]) ? $spreaderIDs[$value->UserID] : '';
  195. $value->winLost = isset($winLost[$value->UserID]) ? $winLost[$value->UserID] : '';
  196. $value->ServerName = isset($userOnLine[$value->UserID]) ? $userOnLine[$value->UserID] : '';
  197. $value->PhoneNum = isset($PhoneNums[$value->UserID]) ? $PhoneNums[$value->UserID] : '';
  198. $value->Nullity = $value->Nullity == 0 ? '正常' : '封禁';
  199. $value->Score = $value->Score / NumConfig::NUM_VALUE;
  200. $value->InsureScore = $value->InsureScore / NumConfig::NUM_VALUE;
  201. $value->MaxScore = $value->MaxScore / NumConfig::NUM_VALUE;
  202. $value->MaxWinScore = $value->MaxWinScore / NumConfig::NUM_VALUE;
  203. // 可提现额度
  204. $value->CashAble = $AccountsInfoM->CashAble($value->UserID, $value->Score, $StatusValue);
  205. foreach ($today as $val) {
  206. if ($val->UserID == $value->UserID) {
  207. $value->todayWithdraw = $val->Withdraw / NumConfig::NUM_VALUE;
  208. $value->todayScore = $val->Score / NumConfig::NUM_VALUE;
  209. $value->todayRecharge = $val->Recharge;
  210. $value->todayHandsel = $val->Handsel / NumConfig::NUM_VALUE;
  211. }
  212. }
  213. foreach ($total as $val) {
  214. if ($val->UserID == $value->UserID) {
  215. $value->totalWithdraw = $val->Withdraw / NumConfig::NUM_VALUE;
  216. $value->totalScore = $val->Score / NumConfig::NUM_VALUE;
  217. $value->totalRecharge = $val->Recharge;
  218. $value->totalHandsel = $val->Handsel / NumConfig::NUM_VALUE;
  219. }
  220. }
  221. }
  222. return $list;
  223. }
  224. public function userNewList($gameID, $startTime, $endTime, $lstartTime, $lendTime, $channel, $minRecharge, $maxRecharge,$excel)
  225. {
  226. $field = ['ai.GameID','ai.UserID', 'ai.NickName','gi.Score', 'ai.Nullity', 'ai.LastLogonDate', 'ai.RegisterDate', 'ai.Channel', 'ap.PhoneNum','Recharge','Withdraw','LostScore','WinScore'];
  227. $Sql = DB::connection('read')->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  228. ->leftJoin(TableName::QPTreasureDB() . 'GameScoreInfo as gi', 'ai.UserID', 'gi.UserID')
  229. ->leftJoin(TableName::QPAccountsDB() . 'AccountPhone as ap', 'ai.UserID', 'ap.UserID')
  230. ->leftJoin(TableName::QPRecordDB().'RecordUserTotalStatistics as rut','ai.UserID', 'rut.UserID')
  231. ->where('ai.IsAndroid', 0)
  232. ->select($field);
  233. // return DB::connection('read')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  234. // ->selectRaw('Recharge,Withdraw,Handsel,(WinScore + LostScore) Score,ServiceFee,UserID,Revenue')
  235. // ->whereIn('UserID', $UserIDs)
  236. // ->get();
  237. $where = [];
  238. if (!empty($gameID))
  239. $where[] = ['ai.GameID', $gameID];
  240. if (!empty($gameID))
  241. $where[] = ['ai.GameID', $gameID];
  242. if (!empty($nickName))
  243. $where[] = ['ai.NickName', $nickName];
  244. if (!empty($startTime))
  245. $where[] = ['ai.RegisterDate', '>=', $startTime];
  246. if (!empty($endTime))
  247. $where[] = ['ai.RegisterDate', '<=', $endTime];
  248. if (!empty($lstartTime))
  249. $where[] = ['ai.LastLogonDate', '>=', $lstartTime];
  250. if (!empty($lendTime))
  251. $where[] = ['ai.LastLogonDate', '<=', $lendTime];
  252. if (!empty($minRecharge))
  253. $where[] = ['rut.Recharge', '>=', $minRecharge];
  254. if (!empty($maxRecharge))
  255. $where[] = ['rut.Recharge', '<=', $maxRecharge];
  256. if (!empty($channel))
  257. $where[] = ['ai.Channel', $channel];
  258. $orderBy = 'ai.UserID desc';
  259. if($excel){
  260. $list = $Sql->where($where)->orderByRaw($orderBy)->limit(300)->get();
  261. $list = json_decode(json_encode($list),true);
  262. //var_dump($list);
  263. //exit();
  264. foreach ($list as &$value) {
  265. $value['Nullity'] = $value['Nullity'] == 0 ? '正常' : '封禁';
  266. $value['Score'] = $value['Score'] / NumConfig::NUM_VALUE;
  267. $value['Withdraw'] = $value['Withdraw'] / NumConfig::NUM_VALUE;
  268. $value['totalScore'] = intval($value['WinScore']+ $value['LostScore'])/NumConfig::NUM_VALUE;
  269. unset($value['WinScore']);
  270. unset($value['LostScore']);
  271. }
  272. //dd($list);
  273. $title = ['UserID', '玩家ID', '昵称','余额', '状态', '离线时间', '注册时间', '玩家渠道', '手机号', '充值', '提现', '输赢'];
  274. // $cellData = json_decode(json_encode($list), true);
  275. downloadExcel($list, $title, '用户列表');
  276. // exit();
  277. }
  278. $list = $Sql->where($where)->orderByRaw($orderBy)->paginate(10);
  279. foreach ($list as &$value) {
  280. $value->Nullity = $value->Nullity == 0 ? '正常' : '封禁';
  281. $value->Score = $value->Score / NumConfig::NUM_VALUE;
  282. $value->totalScore = ($value->WinScore+$value->LostScore)/NumConfig::NUM_VALUE;
  283. $value->Withdraw = $value->Withdraw / NumConfig::NUM_VALUE;
  284. }
  285. return $list;
  286. }
  287. public function dk_userlist($GameID, $SpreaderID, $NickName, $start_time, $end_time, $user_label, $is_line, $game_room, $UserScoreControl, $ScoreSort, $amountSort, $sort_tx, $sort_date, $ChangeScore_sort, $Channel, $label_sort, $ServerNameSort)
  288. {
  289. $AccountsInfoM = new AccountsInfo();
  290. $StatusValue = DB::connection('read')->table('QPAccountsDB.dbo.SystemStatusInfo')
  291. ->where('StatusName', 'WithDrawPoint')
  292. ->select('StatusValue')
  293. ->first()->StatusValue ?? 0;
  294. $where = [];
  295. $field = ['ai.GameID', 'ai.UserID', 'ai.SpreaderID', 'ai.NickName', 'ai.MemberOrder', 'ai.Nullity', 'ai.WebLogonTimes', 'ai.LastLogonIP', 'ai.LastLogonDate', 'ai.RegisterIP', 'ai.RegisterDate', 'ai.Channel', 'gi.Score'];
  296. $Sql = DB::connection('read')->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  297. ->where('ai.IsAndroid', 0)
  298. ->leftJoin(TableName::QPTreasureDB() . 'GameScoreInfo as gi', 'ai.UserID', 'gi.UserID')
  299. ->select($field);
  300. if (!empty($GameID))
  301. $where[] = ['ai.GameID', $GameID];
  302. if (!empty($NickName))
  303. $where[] = ['ai.NickName', $NickName];
  304. if (!empty($Channel) || $Channel === '0')
  305. $where[] = ['ai.Channel', '=', $Channel];
  306. if (!empty($start_time))
  307. $where[] = ['ai.RegisterDate', '>=', $start_time];
  308. if (!empty($end_time))
  309. $where[] = ['ai.RegisterDate', '<=', $end_time];
  310. if (!empty($channel))
  311. $where[] = ['ai.Channel', $channel];
  312. if (!empty($user_label))
  313. $Sql = $Sql->join(TableName::QPAccountsDB() . 'AccountLabelDanControlLabel as al', 'ai.UserID', 'al.UserID')
  314. ->where('type', $user_label);
  315. // 充值
  316. if (!empty($amountSort)) {
  317. $Sql = $Sql->join(TableName::QPAccountsDB() . 'YN_VIPAccount as vip', 'ai.UserID', 'vip.UserID')->orderByRaw("vip.Recharge $amountSort");
  318. }
  319. // 提现
  320. if (!empty($sort_tx)) {
  321. $Sql = $Sql->leftJoin(TableName::QPAccountsDB() . 'UserTabData as ud', 'ai.UserID', 'ud.UserID')->orderByRaw("TakeMoney $sort_tx");
  322. }
  323. if (!empty($ChangeScore_sort)) {
  324. $Sql = $Sql->leftJoin(TableName::QPRecordDB() . 'RecordUserTotalStatistics as rds', 'rds.UserID', 'ai.UserID')->orderByRaw("(WinScore + LostScore) $ChangeScore_sort");
  325. }
  326. // 受控制用户
  327. switch ($UserScoreControl) {
  328. case 1: // 控制
  329. $Sql = $Sql->whereExists(function ($query) {
  330. $query->from(TableName::QPTreasureDB() . 'UserScoreControl as usc')
  331. ->whereRaw('usc.UserID=ai.UserID');
  332. });
  333. break;
  334. case 2: // 不受控制
  335. $Sql = $Sql->whereNotExists(function ($query) {
  336. $query->from(TableName::QPTreasureDB() . 'UserScoreControl as usc')
  337. ->whereRaw('usc.UserID=ai.UserID');
  338. });
  339. break;
  340. case 3: // 自动控制 + 控制中
  341. $Sql = $Sql->whereExists(function ($query) {
  342. $query->from(TableName::QPTreasureDB() . 'UserScoreControl as usc')
  343. ->whereRaw('usc.UserID=ai.UserID');
  344. })->whereExists(function ($query) {
  345. $query->from(TableName::QPRecordDB() . 'RecordRechargeControl as rc')
  346. ->whereRaw('ai.UserID=rc.UserID and rc.State>0');
  347. });
  348. break;
  349. case 4:
  350. $Sql = $Sql->leftJoin('QPRecordDB.dbo.RecordRechargeControl as rc', 'ai.UserID', 'rc.UserID')
  351. ->Where('rc.State', '>', 0)->whereNull('usc.UserID');
  352. break;
  353. }
  354. if ($is_line == 1 || !empty($game_room)) { // 在线
  355. if (empty($game_room)) {
  356. $Sql = $Sql->whereExists(function ($query) {
  357. $query->from(TableName::QPTreasureDB() . 'GameScoreLocker as gsl')
  358. ->whereRaw('gsl.UserID=ai.UserID and datediff(hh,gsl.CollectDate,getdate())<=5');
  359. });
  360. } else {
  361. $Sql = $Sql->whereExists(function ($query) use ($game_room) {
  362. $query->from(TableName::QPTreasureDB() . 'GameScoreLocker as gsl')
  363. ->whereRaw("gsl.UserID=ai.UserID and datediff(hh,gsl.CollectDate,getdate())<=5 and ServerID=$game_room");
  364. });
  365. }
  366. } elseif ($is_line == 2) { // 离线
  367. $Sql = $Sql->whereNotExists(function ($query) {
  368. $query->from(TableName::QPTreasureDB() . 'GameScoreLocker as gsl')
  369. ->whereRaw('gsl.UserID=ai.UserID');
  370. });
  371. }
  372. if (!empty($spreaderID)) {
  373. $Sql = $Sql->join(TableName::QPAccountsDB() . 'AccountsInfo as ai1', 'ai1.UserID', 'ai.SpreaderID')
  374. ->where('ai1.GameID', $spreaderID);
  375. }
  376. // 金币排序
  377. if (!empty($ScoreSort))
  378. $Sql = $Sql->orderBy('Score', $ScoreSort);
  379. // 日期
  380. if (!empty($sort_date)) {
  381. $Sql = $Sql->orderBy('ai.RegisterDate', $sort_date);
  382. } else {
  383. $Sql = $Sql->orderBy('ai.RegisterDate', 'desc');
  384. }
  385. if (!empty($label_sort)) {
  386. $Sql = $Sql->orderBy('IDColor', $label_sort);
  387. }
  388. $list = $Sql->where($where)->paginate(10);
  389. // 取出用户ID
  390. $UserIDs = [];
  391. foreach ($list as $value) {
  392. $UserIDs[] = $value->UserID;
  393. }
  394. // 用户上级ID
  395. $spreaderIDs = $AccountsInfoM->accountSpreaderID($UserIDs);
  396. // 输赢
  397. $winLost = $AccountsInfoM->accountWinLost($UserIDs);
  398. // 今日充值-- 今日提现-- 今日彩金 -- 总输赢
  399. $today = $AccountsInfoM->accountTodayStatistics($UserIDs);
  400. // 全部充值 -- 提现 -- 彩金 -- 总输赢 -- 总得提现手续费
  401. $total = $AccountsInfoM->accountTotalStatistics($UserIDs);
  402. // 游戏是否在线
  403. $userOnLine = $AccountsInfoM->accountOnLine($UserIDs);
  404. // 用户手机号
  405. $PhoneNums = $AccountsInfoM->accountPhone($UserIDs);
  406. // 用户标签
  407. $AccountLabel = $AccountsInfoM->accountLabel($UserIDs);
  408. // 登录IP
  409. $LoginIP = $AccountsInfoM->LoginIP($UserIDs);
  410. // 备注
  411. $Remarks = $AccountsInfoM->remarks($UserIDs);
  412. // 未领邮件
  413. $mailData = $AccountsInfoM->mail($UserIDs);
  414. // 受控标签
  415. $controlLabel = $AccountsInfoM->controlLabel($UserIDs);
  416. // 单控
  417. $UserScoreControls = DB::table(TableName::QPTreasureDB() . 'UserScoreControl')
  418. ->whereIn('UserID', $UserIDs)
  419. ->select(['ControlRadian', 'ControlScore', 'EffectiveScore', 'UserID'])
  420. ->get();
  421. $redis = \Illuminate\Support\Facades\Redis::connection();
  422. $controlModel = new Control();
  423. $onLinUser = [];
  424. foreach ($userOnLine as $val) {
  425. $onLinUser[$val->UserID] = $val->KindID;
  426. }
  427. foreach ($list as &$value) {
  428. $value->spreaderID = isset($spreaderIDs[$value->UserID]) ? $spreaderIDs[$value->UserID] : '';
  429. $value->winLost = isset($winLost[$value->UserID]) ? $winLost[$value->UserID] : '';
  430. $value->PhoneNum = isset($PhoneNums[$value->UserID]) ? $PhoneNums[$value->UserID] : '';
  431. $value->Nullity = $value->Nullity == 0 ? '正常' : '封禁';
  432. $value->Score = $value->Score / NumConfig::NUM_VALUE;
  433. $value->notReceived = isset($mailData[$value->UserID]) ? number_float($mailData[$value->UserID] / NumConfig::NUM_VALUE) : 0;
  434. $value->RecordRechargeControl = isset($controlLabel[$value->UserID]) ? 1 : 0;
  435. $value->LoginIpCount = isset($LoginIP[$value->UserID]) ? $LoginIP[$value->UserID] : 0;
  436. $value->Remarks = isset($Remarks[$value->UserID]) ? $Remarks[$value->UserID] : '';
  437. // 可提现额度
  438. $value->CashAble = $AccountsInfoM->CashAble($value->UserID, $value->Score, $StatusValue);
  439. $value->control_record = $controlModel->getControlState($value->UserID, $onLinUser);
  440. foreach ($UserScoreControls as $val) {
  441. if ($val->UserID == $value->UserID) {
  442. $value->EffectiveScore = number_float($val->EffectiveScore / NumConfig::NUM_VALUE);
  443. $value->ControlScore = number_float($val->ControlScore / NumConfig::NUM_VALUE);
  444. $value->ControlRadian = $val->ControlRadian ?: number_float($val->ControlRadian);
  445. }
  446. }
  447. foreach ($userOnLine as $val) {
  448. if ($val->UserID == $value->UserID) {
  449. $value->ServerName = $val->ServerName;
  450. // 捕鱼控制
  451. if ($val->KindID == 2003) {
  452. $info = $redis->hmGet("userControl_{$value->UserID}", ['controlLevel', 'controlTarget', 'curControlValue']);
  453. $info['controlTarget'] /= NumConfig::NUM_VALUE;
  454. $info['curControlValue'] /= NumConfig::NUM_VALUE;
  455. // 控制分数
  456. if (!empty($info['controlLevel'])) {
  457. $value->fishControl = '捕鱼:控制等级:' . $info['controlLevel'] . ';控制分数:' . $info['controlTarget'] . ';生效分数:' . $info['curControlValue'];
  458. }
  459. }
  460. }
  461. }
  462. foreach ($today as $val) {
  463. if ($val->UserID == $value->UserID) {
  464. $value->todayWithdraw = $val->Withdraw / NumConfig::NUM_VALUE;
  465. $value->todayScore = $val->Score / NumConfig::NUM_VALUE;
  466. $value->todayRecharge = $val->Recharge;
  467. $value->todayHandsel = $val->Handsel / NumConfig::NUM_VALUE;
  468. }
  469. }
  470. foreach ($total as $val) {
  471. if ($val->UserID == $value->UserID) {
  472. $value->totalWithdraw = $val->Withdraw / NumConfig::NUM_VALUE;
  473. $value->totalScore = $val->Score / NumConfig::NUM_VALUE;
  474. $value->totalRecharge = $val->Recharge;
  475. $value->totalHandsel = $val->Handsel / NumConfig::NUM_VALUE;
  476. }
  477. }
  478. foreach ($AccountLabel as $val) {
  479. if ($val->UserID == $value->UserID) {
  480. $value->IDColor = $val->IDColor;
  481. $value->user_label = $AccountsInfoM->labelType($val->type);
  482. }
  483. }
  484. }
  485. return $list;
  486. }
  487. // 全局报表 - 用户相关
  488. public function accounts()
  489. {
  490. $AccountsInfoModel = new AccountsInfo();
  491. $WithdrawalModel = new Withdrawal();
  492. $GlobalLogic = new GlobalLogicController();
  493. // 用户支付信息
  494. $accountsPayInfo = Order::pay_sum();
  495. $paySum = $accountsPayInfo->Recharge ?? 0;
  496. $payUserCount = $accountsPayInfo->payCount;
  497. // 用户所有提现
  498. $withdraw = $WithdrawalModel->totalWithdraw()->Withdraw / NumConfig::NUM_VALUE ?? 0;
  499. // 累计提现回收金额
  500. $withDrawRecovery = $WithdrawalModel->WithDrawRecovery();
  501. // 休眠用户
  502. $dormancyUser = $AccountsInfoModel->dormancy_user();
  503. // 流失用户
  504. $lsUser = $AccountsInfoModel->ls_user();
  505. // 总注册用户
  506. $register = $AccountsInfoModel->user_count();
  507. // 签到总奖励
  508. $totalSignIn = $AccountsInfoModel->accountSignIn();
  509. // 周卡购买报表
  510. // $weeklyCard = $GlobalLogic->WeeklyCard();
  511. return compact('paySum', 'payUserCount', 'withdraw', 'withDrawRecovery', 'dormancyUser', 'lsUser', 'register','totalSignIn');
  512. }
  513. // 全局报表 - 游戏相关
  514. // 全局报表 - 游戏相关
  515. public function games($StartDataID, $EndDataID)
  516. {
  517. $redis = \Illuminate\Support\Facades\Redis::connection();
  518. $gameRtp =$redis->get("SomeConfigSpecial");
  519. $gameRtp = json_decode($gameRtp,true);
  520. // 流水、输赢、彩金
  521. $gameInfo = DB::connection('read')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  522. // ->selectRaw('sum(TotalBet) as flowing_water,Isnull(sum(Revenue),0) as Revenue,IsNull((sum(LostScore) + sum(WinScore)),0) Score,Isnull(SUM(Handsel),0) as ChangeScore')
  523. ->selectRaw('sum(TotalBet) as flowing_water_new,IsNull((abs(sum(LostScore)) + sum(WinScore)),0) flowing_water,Isnull(sum(Revenue),0) as Revenue,IsNull((sum(LostScore) + sum(WinScore)),0) Score,Isnull(SUM(Handsel),0) as ChangeScore')
  524. ->first();
  525. foreach ($gameInfo as &$value) {
  526. $value = number_float($value / NumConfig::NUM_VALUE);
  527. }
  528. unset($value);
  529. // 房间库存
  530. $roomStock = GameRoomInfo::RoomStock(config('games.openKGame'));
  531. // 游戏房间数据--汇总
  532. // $gameRoomInfo = DB::connection('read')->table(TableName::QPRecordDB() . 'RecordServerDataStatistics')
  533. // ->where('DateID', '>=', $StartDataID)
  534. // ->where('DateID', '<=', $EndDataID)
  535. //// ->selectRaw('sum(TotalBet) as flowing_water,Isnull(sum(Revenue),0) as Revenue,Isnull((sum(WinScore) + sum(LostScore)),0) as win_lose')
  536. // ->selectRaw('sum(TotalBet) as flowing_water_new,Isnull((sum(WinScore) + abs(sum(LostScore))),0) as flowing_water,Isnull(sum(Revenue),0) as Revenue,Isnull((sum(WinScore) + sum(LostScore)),0) as win_lose')
  537. // ->first();
  538. $gameRoomInfo=DB::table('QPRecordDB.dbo.RecordGameRoomDayInfo')
  539. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  540. ->where('SortID','-1')
  541. ->selectRaw('sum(TotalBet) as flowing_water_new,sum(PayTotalBet) as pay_flowing_water_new,sum(GameTurnOver) as flowing_water,sum(PayGameTurnOver) as pay_flowing_water,sum(GameRevenue) as Revenue,sum(PayGameRevenue) as pay_Revenue')
  542. ->first();
  543. $gameRoomInfo2=DB::table('QPPlatformDB.dbo.RoomStockDay')
  544. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  545. ->selectRaw('sum(Winlost) as win_lose,sum(PayWinlost) as pay_win_lose')->first();
  546. $gameRoomInfo->win_lose=$gameRoomInfo2->win_lose;
  547. $gameRoomInfo->pay_win_lose=$gameRoomInfo2->pay_win_lose;
  548. $gameRoomInfo->free_flowing_water = $gameRoomInfo->flowing_water_new-$gameRoomInfo->pay_flowing_water_new;
  549. $gameRoomInfo->free_win_lose = $gameRoomInfo->win_lose-$gameRoomInfo->pay_win_lose;
  550. // 游戏人数
  551. $totalGameCount = DB::table(TableName::QPRecordDB() . 'RecordUserGameDayCount')
  552. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  553. ->distinct()
  554. ->count('UserID');
  555. // 游戏人数
  556. $pay_totalGameCount = DB::table(TableName::QPRecordDB() . 'RecordUserGameDayCount as ru')
  557. ->join('QPAccountsDB.dbo.YN_VIPAccount as v', 'ru.UserID', '=', 'v.UserID')
  558. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  559. ->distinct()
  560. ->count('ru.UserID');
  561. foreach ($gameRoomInfo as &$value) {
  562. $value = number_float($value / NumConfig::NUM_VALUE);
  563. }
  564. unset($value);
  565. $gameRoomInfo->Rtp = @$gameRtp['g0'];
  566. if (!empty($gameRoomInfo)) {
  567. // 平台输赢 = 输赢 + 税收
  568. // $gameRoomInfo->win_lose = $gameRoomInfo->win_lose;
  569. }
  570. // 游戏房间数据 -- 列表
  571. // $gameList = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo as gi')
  572. // ->leftJoin('QPRecordDB.dbo.RecordServerDataStatistics as rds', 'rds.ServerID', 'gi.ServerID')
  573. // ->leftJoin('QPRecordDB.dbo.RecordUserGameDayCount as rgc', function ($query) {
  574. // $query->on('rgc.GameID', 'rds.ServerID')->on('rds.DateID', 'rgc.DateID');
  575. // })
  576. // ->whereBetween('rds.DateID', [$StartDataID, $EndDataID])
  577. // ->select('gi.GameID', 'gi.ServerName', 'gi.ServerID')
  578. // ->selectRaw('Isnull((sum(WinScore) + abs(sum(LostScore))),0) as flowing_water,Isnull(sum(rds.Revenue),0) as Revenue,Isnull((sum(WinScore) + sum(LostScore)),0) as win_lose')
  579. // ->selectRaw('WinScore,LostScore,Revenue,WinUserCount,LostUserCount,gi.GameID,gi.ServerName,gi.ServerID')
  580. // ->get();
  581. $gameList = DB::table(TableName::QPRecordDB() . 'RecordGameRoomDayInfo as ri')
  582. ->where('ri.SortID', '>', 0)
  583. ->whereBetween('ri.DateID', [$StartDataID, $EndDataID])
  584. ->leftJoin(TableName::QPPlatformDB() . 'RoomStockDay as rs', function ($query) {
  585. $query->on('ri.GameID', 'rs.GameID')->on('ri.SortID', 'rs.SortID')->on('ri.DateID', 'rs.DateID');
  586. })
  587. ->select('GamePlayer as Cnt', 'PayGamePlayer as pay_Cnt', 'GameRevenue as Revenue', 'PayGameRevenue as pay_Revenue', 'GameTurnOver as flowing_water', 'TotalBet as flowing_water_new','PayTotalBet as pay_flowing_water_new', 'Winlost as win_lose', 'PayWinlost as pay_win_lose', 'ri.GameID', 'ri.SortID','ri.DateID')
  588. ->get();
  589. // 游戏输赢 + 控制输赢
  590. $RoomControlStockDay = DB::table(TableName::QPPlatformDB().'RoomControlStockDay')
  591. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  592. ->get();
  593. $gameServerNames = DB::table(TableName::QPPlatformDB() . 'RoomConfig')->get();
  594. $chu = $zhong = $gao = 0;
  595. $chu_n = $zhong_n = $gao_n = 0;
  596. // dd($gameList);
  597. $gamesorts=[];
  598. $revenueGames = config('games.revenueGames');
  599. // dd($gameRtp);
  600. foreach ($gameList as &$value) {
  601. $value->ServerName = '';
  602. $value->flowing_water = is_null($value->flowing_water) ? 0 : number_float($value->flowing_water / NumConfig::NUM_VALUE);
  603. $value->flowing_water_new = is_null($value->flowing_water_new) ? 0 : number_float($value->flowing_water_new / NumConfig::NUM_VALUE);
  604. // $value->Revenue = is_null($value->Revenue) ? 0 : number_float($value->Revenue / NumConfig::NUM_VALUE);
  605. $value->pay_flowing_water_new = is_null($value->pay_flowing_water_new) ? 0 : number_float($value->pay_flowing_water_new / NumConfig::NUM_VALUE);
  606. // $value->pay_Revenue = is_null($value->pay_Revenue) ? 0 : number_float($value->pay_Revenue / NumConfig::NUM_VALUE);
  607. $value->free_flowing_water = $value->flowing_water_new-$value->pay_flowing_water_new;
  608. //玩家不扣税的游戏不累计到统计里
  609. // if(!in_array($value->GameID,$revenueGames)){
  610. // $gameRoomInfo->win_lose = $gameRoomInfo->win_lose-$value->Revenue;
  611. // $gameRoomInfo->pay_win_lose = $gameRoomInfo->pay_win_lose-$value->pay_Revenue;
  612. // $gameRoomInfo->Revenue = $gameRoomInfo->Revenue-$value->Revenue; //真是税收收入
  613. // $gameRoomInfo->pay_Revenue = $gameRoomInfo->pay_Revenue-$value->pay_Revenue; //真是税收收入
  614. // }
  615. $value->win_lose = is_null($value->win_lose) ? 0 : number_float($value->win_lose / NumConfig::NUM_VALUE);
  616. $value->pay_win_lose = is_null($value->pay_win_lose) ? 0 : number_float($value->pay_win_lose / NumConfig::NUM_VALUE);
  617. $value->free_win_lose = $value->win_lose-$value->pay_win_lose;
  618. foreach ($gameServerNames as $serverName) {
  619. if ($value->GameID == $serverName->GameID && $value->SortID == $serverName->SortID) {
  620. $value->ServerName = $serverName->RoomName;
  621. }
  622. }
  623. // 游戏输赢 = 控制输赢 + 库存输赢
  624. foreach ($RoomControlStockDay as $val){
  625. if ($value->GameID == $val->GameID && $value->SortID == $val->SortID && $value->DateID == $val->DateID) {
  626. $value->win_lose = is_null($val->Winlost) ? $value->win_lose : $value->win_lose + ($val->Winlost / NumConfig::NUM_VALUE);
  627. }
  628. }
  629. if(is_array($gameRtp)){
  630. $value->Rtp = @$gameRtp['g'.$value->GameID]??'';
  631. }
  632. // if($value->SortID == 1){
  633. // $chu += $value->flowing_water;
  634. // $chu_n += $value->flowing_water_new;
  635. // }
  636. // if($value->SortID == 2){
  637. // $zhong += $value->flowing_water;
  638. // $zhong_n += $value->flowing_water_new;
  639. // }
  640. // if($value->SortID == 3){
  641. // $gao += $value->flowing_water;
  642. // $gao_n += $value->flowing_water_new;
  643. // }
  644. if(!isset($gamesorts[$value->GameID.'-'.$value->SortID])) {
  645. $gamesorts[$value->GameID.'-'.$value->SortID]=(object)['Cnt'=>0,'Revenue'=>0,'pay_Cnt'=>0,'pay_Revenue'=>0,'flowing_water'=>0,'free_win_lose' => 0,'free_flowing_water' => 0,'win_lose'=>0,'flowing_water_new'=>0,'pay_win_lose'=>0,'pay_flowing_water_new'=>0,'GameID'=>$value->GameID,'SortID'=>$value->SortID,'DateID'=>$value->DateID,'ServerName'=>$value->ServerName];
  646. }
  647. $oldvalue = &$gamesorts[$value->GameID.'-'.$value->SortID];
  648. $oldvalue->Cnt += $value->Cnt;
  649. // $oldvalue->Revenue += $value->Revenue;
  650. $oldvalue->flowing_water += $value->flowing_water;
  651. $oldvalue->flowing_water_new += $value->flowing_water_new;
  652. $oldvalue->win_lose += $value->win_lose;
  653. $oldvalue->pay_Cnt += $value->pay_Cnt;
  654. $oldvalue->pay_Revenue += $value->pay_Revenue;
  655. $oldvalue->pay_flowing_water_new += $value->pay_flowing_water_new;
  656. $oldvalue->pay_win_lose += $value->pay_win_lose;
  657. $oldvalue->free_win_lose += $value->free_win_lose;
  658. $oldvalue->free_flowing_water += $value->free_flowing_water;
  659. $oldvalue->Rtp = $value->Rtp;
  660. }
  661. $gameList=array_values($gamesorts);
  662. $gameList=Util::arraySort($gameList,'flowing_water_new',SORT_DESC);
  663. if(@$_REQUEST['nienie']){
  664. dd($gameList,$gameRoomInfo);
  665. }
  666. if($chu==0)$chu=1;
  667. $zhongRate = (ceil($zhong/$chu*100)/100);
  668. $gaoRate = (ceil($gao/$chu*100)/100);
  669. $total = 1+$zhongRate+$gaoRate;
  670. $zhongRate_n = (ceil($zhong/$chu*100)/100);
  671. $gaoRate_n = (ceil($gao/$chu*100)/100);
  672. $total_n = 1+$zhongRate+$gaoRate;
  673. $rateString = "1:$zhongRate:$gaoRate=$total";
  674. $rateString_n = "1:$zhongRate_n:$gaoRate_n=$total_n";
  675. unset($value);
  676. return compact('gameInfo', 'gameRoomInfo', 'gameList', 'roomStock', 'totalGameCount','pay_totalGameCount','rateString','rateString_n');
  677. }
  678. // 全局报表 - 彩金相关
  679. public function winnings($startTime, $endTime)
  680. {
  681. $startTime = date("Y-m-d 00:00:00", strtotime($startTime));
  682. $endTime = date("Y-m-d 23:59:59", strtotime($endTime));
  683. $ScoreType = [21, 33, 36, 44, 45, 51, 52, 53, 59, 70];
  684. // 21、绑定手机赠送 33、注册赠送 36、推广赚金(彩金) 42、邮件附件(充值彩金) 45、充值彩金 51、首充礼包(彩金) 52、邮件附件(群发彩金) 53、推广赚金(佣金)
  685. $winnings = DB::connection('read')->table(TableName::QPRecordDB() . 'RecordUserScoreChange')
  686. ->where('UpdateTime', '>=', $startTime)
  687. ->where('UpdateTime', '<=', $endTime)
  688. ->whereIn('Reason', $ScoreType)
  689. ->selectRaw('Isnull(SUM(ChangeScore),0) as Score,Reason')
  690. ->groupBy('Reason')
  691. ->pluck('Score', 'Reason')->toArray();
  692. foreach ($winnings as &$val) {
  693. $val = number_float($val / NumConfig::NUM_VALUE);
  694. }
  695. unset($val);
  696. // 彩金总和
  697. $winningsSum = array_sum($winnings);
  698. // 推广总奖励
  699. $totalReward = DB::connection('read')->table(TableName::QPAccountsDB() . 'SystemAgentReward')->select('TotalReward')->first()->TotalReward / NumConfig::NUM_VALUE;
  700. // 签到
  701. $signIn = DB::connection('read')->table(TableName::QPRecordDB() . 'RecordSignIn')
  702. ->where('SignInDate', '>=', $startTime)
  703. ->where('SignInDate', '<=', $endTime)
  704. ->selectRaw('IsNull(sum(RewardScore),0) RewardScore')
  705. ->first()->RewardScore / 100 ?? 0;
  706. return compact('winnings', 'winningsSum', 'totalReward', 'signIn');
  707. }
  708. }