GlobalUser.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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.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->MaxScore = $value->MaxScore / NumConfig::NUM_VALUE;
  201. $value->MaxWinScore = $value->MaxWinScore / NumConfig::NUM_VALUE;
  202. // 可提现额度
  203. $value->CashAble = $AccountsInfoM->CashAble($value->UserID, $value->Score, $StatusValue);
  204. foreach ($today as $val) {
  205. if ($val->UserID == $value->UserID) {
  206. $value->todayWithdraw = $val->Withdraw / NumConfig::NUM_VALUE;
  207. $value->todayScore = $val->Score / NumConfig::NUM_VALUE;
  208. $value->todayRecharge = $val->Recharge;
  209. $value->todayHandsel = $val->Handsel / NumConfig::NUM_VALUE;
  210. }
  211. }
  212. foreach ($total as $val) {
  213. if ($val->UserID == $value->UserID) {
  214. $value->totalWithdraw = $val->Withdraw / NumConfig::NUM_VALUE;
  215. $value->totalScore = $val->Score / NumConfig::NUM_VALUE;
  216. $value->totalRecharge = $val->Recharge;
  217. $value->totalHandsel = $val->Handsel / NumConfig::NUM_VALUE;
  218. }
  219. }
  220. }
  221. return $list;
  222. }
  223. public function userNewList($gameID, $startTime, $endTime, $lstartTime, $lendTime, $channel, $minRecharge, $maxRecharge,$excel)
  224. {
  225. $field = ['ai.GameID','ai.UserID', 'ai.NickName','gi.Score', 'ai.Nullity', 'ai.LastLogonDate', 'ai.RegisterDate', 'ai.Channel', 'ap.PhoneNum','Recharge','Withdraw','LostScore','WinScore'];
  226. $Sql = DB::connection('read')->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  227. ->leftJoin(TableName::QPTreasureDB() . 'GameScoreInfo as gi', 'ai.UserID', 'gi.UserID')
  228. ->leftJoin(TableName::QPAccountsDB() . 'AccountPhone as ap', 'ai.UserID', 'ap.UserID')
  229. ->leftJoin(TableName::QPRecordDB().'RecordUserTotalStatistics as rut','ai.UserID', 'rut.UserID')
  230. ->where('ai.IsAndroid', 0)
  231. ->select($field);
  232. // return DB::connection('read')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  233. // ->selectRaw('Recharge,Withdraw,Handsel,(WinScore + LostScore) Score,ServiceFee,UserID,Revenue')
  234. // ->whereIn('UserID', $UserIDs)
  235. // ->get();
  236. $where = [];
  237. if (!empty($gameID))
  238. $where[] = ['ai.GameID', $gameID];
  239. if (!empty($gameID))
  240. $where[] = ['ai.GameID', $gameID];
  241. if (!empty($nickName))
  242. $where[] = ['ai.NickName', $nickName];
  243. if (!empty($startTime))
  244. $where[] = ['ai.RegisterDate', '>=', $startTime];
  245. if (!empty($endTime))
  246. $where[] = ['ai.RegisterDate', '<=', $endTime];
  247. if (!empty($lstartTime))
  248. $where[] = ['ai.LastLogonDate', '>=', $lstartTime];
  249. if (!empty($lendTime))
  250. $where[] = ['ai.LastLogonDate', '<=', $lendTime];
  251. if (!empty($minRecharge))
  252. $where[] = ['rut.Recharge', '>=', $minRecharge];
  253. if (!empty($maxRecharge))
  254. $where[] = ['rut.Recharge', '<=', $maxRecharge];
  255. if (!empty($channel))
  256. $where[] = ['ai.Channel', $channel];
  257. $orderBy = 'ai.UserID desc';
  258. if($excel){
  259. $list = $Sql->where($where)->orderByRaw($orderBy)->limit(300)->get();
  260. $list = json_decode(json_encode($list),true);
  261. //var_dump($list);
  262. //exit();
  263. foreach ($list as &$value) {
  264. $value['Nullity'] = $value['Nullity'] == 0 ? '正常' : '封禁';
  265. $value['Score'] = $value['Score'] / NumConfig::NUM_VALUE;
  266. $value['Withdraw'] = $value['Withdraw'] / NumConfig::NUM_VALUE;
  267. $value['totalScore'] = intval($value['WinScore']+ $value['LostScore'])/NumConfig::NUM_VALUE;
  268. unset($value['WinScore']);
  269. unset($value['LostScore']);
  270. }
  271. //dd($list);
  272. $title = ['UserID', '玩家ID', '昵称','余额', '状态', '离线时间', '注册时间', '玩家渠道', '手机号', '充值', '提现', '输赢'];
  273. // $cellData = json_decode(json_encode($list), true);
  274. downloadExcel($list, $title, '用户列表');
  275. // exit();
  276. }
  277. $list = $Sql->where($where)->orderByRaw($orderBy)->paginate(10);
  278. foreach ($list as &$value) {
  279. $value->Nullity = $value->Nullity == 0 ? '正常' : '封禁';
  280. $value->Score = $value->Score / NumConfig::NUM_VALUE;
  281. $value->totalScore = ($value->WinScore+$value->LostScore)/NumConfig::NUM_VALUE;
  282. $value->Withdraw = $value->Withdraw / NumConfig::NUM_VALUE;
  283. }
  284. return $list;
  285. }
  286. 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)
  287. {
  288. $AccountsInfoM = new AccountsInfo();
  289. $StatusValue = DB::connection('read')->table('QPAccountsDB.dbo.SystemStatusInfo')
  290. ->where('StatusName', 'WithDrawPoint')
  291. ->select('StatusValue')
  292. ->first()->StatusValue ?? 0;
  293. $where = [];
  294. $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'];
  295. $Sql = DB::connection('read')->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  296. ->where('ai.IsAndroid', 0)
  297. ->leftJoin(TableName::QPTreasureDB() . 'GameScoreInfo as gi', 'ai.UserID', 'gi.UserID')
  298. ->select($field);
  299. if (!empty($GameID))
  300. $where[] = ['ai.GameID', $GameID];
  301. if (!empty($NickName))
  302. $where[] = ['ai.NickName', $NickName];
  303. if (!empty($Channel) || $Channel === '0')
  304. $where[] = ['ai.Channel', '=', $Channel];
  305. if (!empty($start_time))
  306. $where[] = ['ai.RegisterDate', '>=', $start_time];
  307. if (!empty($end_time))
  308. $where[] = ['ai.RegisterDate', '<=', $end_time];
  309. if (!empty($channel))
  310. $where[] = ['ai.Channel', $channel];
  311. if (!empty($user_label))
  312. $Sql = $Sql->join(TableName::QPAccountsDB() . 'AccountLabelDanControlLabel as al', 'ai.UserID', 'al.UserID')
  313. ->where('type', $user_label);
  314. // 充值
  315. if (!empty($amountSort)) {
  316. $Sql = $Sql->join(TableName::QPAccountsDB() . 'YN_VIPAccount as vip', 'ai.UserID', 'vip.UserID')->orderByRaw("vip.Recharge $amountSort");
  317. }
  318. // 提现
  319. if (!empty($sort_tx)) {
  320. $Sql = $Sql->leftJoin(TableName::QPAccountsDB() . 'UserTabData as ud', 'ai.UserID', 'ud.UserID')->orderByRaw("TakeMoney $sort_tx");
  321. }
  322. if (!empty($ChangeScore_sort)) {
  323. $Sql = $Sql->leftJoin(TableName::QPRecordDB() . 'RecordUserTotalStatistics as rds', 'rds.UserID', 'ai.UserID')->orderByRaw("(WinScore + LostScore) $ChangeScore_sort");
  324. }
  325. // 受控制用户
  326. switch ($UserScoreControl) {
  327. case 1: // 控制
  328. $Sql = $Sql->whereExists(function ($query) {
  329. $query->from(TableName::QPTreasureDB() . 'UserScoreControl as usc')
  330. ->whereRaw('usc.UserID=ai.UserID');
  331. });
  332. break;
  333. case 2: // 不受控制
  334. $Sql = $Sql->whereNotExists(function ($query) {
  335. $query->from(TableName::QPTreasureDB() . 'UserScoreControl as usc')
  336. ->whereRaw('usc.UserID=ai.UserID');
  337. });
  338. break;
  339. case 3: // 自动控制 + 控制中
  340. $Sql = $Sql->whereExists(function ($query) {
  341. $query->from(TableName::QPTreasureDB() . 'UserScoreControl as usc')
  342. ->whereRaw('usc.UserID=ai.UserID');
  343. })->whereExists(function ($query) {
  344. $query->from(TableName::QPRecordDB() . 'RecordRechargeControl as rc')
  345. ->whereRaw('ai.UserID=rc.UserID and rc.State>0');
  346. });
  347. break;
  348. case 4:
  349. $Sql = $Sql->leftJoin('QPRecordDB.dbo.RecordRechargeControl as rc', 'ai.UserID', 'rc.UserID')
  350. ->Where('rc.State', '>', 0)->whereNull('usc.UserID');
  351. break;
  352. }
  353. if ($is_line == 1 || !empty($game_room)) { // 在线
  354. if (empty($game_room)) {
  355. $Sql = $Sql->whereExists(function ($query) {
  356. $query->from(TableName::QPTreasureDB() . 'GameScoreLocker as gsl')
  357. ->whereRaw('gsl.UserID=ai.UserID and datediff(hh,gsl.CollectDate,getdate())<=5');
  358. });
  359. } else {
  360. $Sql = $Sql->whereExists(function ($query) use ($game_room) {
  361. $query->from(TableName::QPTreasureDB() . 'GameScoreLocker as gsl')
  362. ->whereRaw("gsl.UserID=ai.UserID and datediff(hh,gsl.CollectDate,getdate())<=5 and ServerID=$game_room");
  363. });
  364. }
  365. } elseif ($is_line == 2) { // 离线
  366. $Sql = $Sql->whereNotExists(function ($query) {
  367. $query->from(TableName::QPTreasureDB() . 'GameScoreLocker as gsl')
  368. ->whereRaw('gsl.UserID=ai.UserID');
  369. });
  370. }
  371. if (!empty($spreaderID)) {
  372. $Sql = $Sql->join(TableName::QPAccountsDB() . 'AccountsInfo as ai1', 'ai1.UserID', 'ai.SpreaderID')
  373. ->where('ai1.GameID', $spreaderID);
  374. }
  375. // 金币排序
  376. if (!empty($ScoreSort))
  377. $Sql = $Sql->orderBy('Score', $ScoreSort);
  378. // 日期
  379. if (!empty($sort_date)) {
  380. $Sql = $Sql->orderBy('ai.RegisterDate', $sort_date);
  381. } else {
  382. $Sql = $Sql->orderBy('ai.RegisterDate', 'desc');
  383. }
  384. if (!empty($label_sort)) {
  385. $Sql = $Sql->orderBy('IDColor', $label_sort);
  386. }
  387. $list = $Sql->where($where)->paginate(10);
  388. // 取出用户ID
  389. $UserIDs = [];
  390. foreach ($list as $value) {
  391. $UserIDs[] = $value->UserID;
  392. }
  393. // 用户上级ID
  394. $spreaderIDs = $AccountsInfoM->accountSpreaderID($UserIDs);
  395. // 输赢
  396. $winLost = $AccountsInfoM->accountWinLost($UserIDs);
  397. // 今日充值-- 今日提现-- 今日彩金 -- 总输赢
  398. $today = $AccountsInfoM->accountTodayStatistics($UserIDs);
  399. // 全部充值 -- 提现 -- 彩金 -- 总输赢 -- 总得提现手续费
  400. $total = $AccountsInfoM->accountTotalStatistics($UserIDs);
  401. // 游戏是否在线
  402. $userOnLine = $AccountsInfoM->accountOnLine($UserIDs);
  403. // 用户手机号
  404. $PhoneNums = $AccountsInfoM->accountPhone($UserIDs);
  405. // 用户标签
  406. $AccountLabel = $AccountsInfoM->accountLabel($UserIDs);
  407. // 登录IP
  408. $LoginIP = $AccountsInfoM->LoginIP($UserIDs);
  409. // 备注
  410. $Remarks = $AccountsInfoM->remarks($UserIDs);
  411. // 未领邮件
  412. $mailData = $AccountsInfoM->mail($UserIDs);
  413. // 受控标签
  414. $controlLabel = $AccountsInfoM->controlLabel($UserIDs);
  415. // 单控
  416. $UserScoreControls = DB::table(TableName::QPTreasureDB() . 'UserScoreControl')
  417. ->whereIn('UserID', $UserIDs)
  418. ->select(['ControlRadian', 'ControlScore', 'EffectiveScore', 'UserID'])
  419. ->get();
  420. $redis = \Illuminate\Support\Facades\Redis::connection();
  421. $controlModel = new Control();
  422. $onLinUser = [];
  423. foreach ($userOnLine as $val) {
  424. $onLinUser[$val->UserID] = $val->KindID;
  425. }
  426. foreach ($list as &$value) {
  427. $value->spreaderID = isset($spreaderIDs[$value->UserID]) ? $spreaderIDs[$value->UserID] : '';
  428. $value->winLost = isset($winLost[$value->UserID]) ? $winLost[$value->UserID] : '';
  429. $value->PhoneNum = isset($PhoneNums[$value->UserID]) ? $PhoneNums[$value->UserID] : '';
  430. $value->Nullity = $value->Nullity == 0 ? '正常' : '封禁';
  431. $value->Score = $value->Score / NumConfig::NUM_VALUE;
  432. $value->notReceived = isset($mailData[$value->UserID]) ? number_float($mailData[$value->UserID] / NumConfig::NUM_VALUE) : 0;
  433. $value->RecordRechargeControl = isset($controlLabel[$value->UserID]) ? 1 : 0;
  434. $value->LoginIpCount = isset($LoginIP[$value->UserID]) ? $LoginIP[$value->UserID] : 0;
  435. $value->Remarks = isset($Remarks[$value->UserID]) ? $Remarks[$value->UserID] : '';
  436. // 可提现额度
  437. $value->CashAble = $AccountsInfoM->CashAble($value->UserID, $value->Score, $StatusValue);
  438. $value->control_record = $controlModel->getControlState($value->UserID, $onLinUser);
  439. foreach ($UserScoreControls as $val) {
  440. if ($val->UserID == $value->UserID) {
  441. $value->EffectiveScore = number_float($val->EffectiveScore / NumConfig::NUM_VALUE);
  442. $value->ControlScore = number_float($val->ControlScore / NumConfig::NUM_VALUE);
  443. $value->ControlRadian = $val->ControlRadian ?: number_float($val->ControlRadian);
  444. }
  445. }
  446. foreach ($userOnLine as $val) {
  447. if ($val->UserID == $value->UserID) {
  448. $value->ServerName = $val->ServerName;
  449. // 捕鱼控制
  450. if ($val->KindID == 2003) {
  451. $info = $redis->hmGet("userControl_{$value->UserID}", ['controlLevel', 'controlTarget', 'curControlValue']);
  452. $info['controlTarget'] /= NumConfig::NUM_VALUE;
  453. $info['curControlValue'] /= NumConfig::NUM_VALUE;
  454. // 控制分数
  455. if (!empty($info['controlLevel'])) {
  456. $value->fishControl = '捕鱼:控制等级:' . $info['controlLevel'] . ';控制分数:' . $info['controlTarget'] . ';生效分数:' . $info['curControlValue'];
  457. }
  458. }
  459. }
  460. }
  461. foreach ($today as $val) {
  462. if ($val->UserID == $value->UserID) {
  463. $value->todayWithdraw = $val->Withdraw / NumConfig::NUM_VALUE;
  464. $value->todayScore = $val->Score / NumConfig::NUM_VALUE;
  465. $value->todayRecharge = $val->Recharge;
  466. $value->todayHandsel = $val->Handsel / NumConfig::NUM_VALUE;
  467. }
  468. }
  469. foreach ($total as $val) {
  470. if ($val->UserID == $value->UserID) {
  471. $value->totalWithdraw = $val->Withdraw / NumConfig::NUM_VALUE;
  472. $value->totalScore = $val->Score / NumConfig::NUM_VALUE;
  473. $value->totalRecharge = $val->Recharge;
  474. $value->totalHandsel = $val->Handsel / NumConfig::NUM_VALUE;
  475. }
  476. }
  477. foreach ($AccountLabel as $val) {
  478. if ($val->UserID == $value->UserID) {
  479. $value->IDColor = $val->IDColor;
  480. $value->user_label = $AccountsInfoM->labelType($val->type);
  481. }
  482. }
  483. }
  484. return $list;
  485. }
  486. // 全局报表 - 用户相关
  487. public function accounts()
  488. {
  489. $AccountsInfoModel = new AccountsInfo();
  490. $WithdrawalModel = new Withdrawal();
  491. $GlobalLogic = new GlobalLogicController();
  492. // 用户支付信息
  493. $accountsPayInfo = Order::pay_sum();
  494. $paySum = $accountsPayInfo->Recharge ?? 0;
  495. $payUserCount = $accountsPayInfo->payCount;
  496. // 用户所有提现
  497. $withdraw = $WithdrawalModel->totalWithdraw()->Withdraw / NumConfig::NUM_VALUE ?? 0;
  498. // 累计提现回收金额
  499. $withDrawRecovery = $WithdrawalModel->WithDrawRecovery();
  500. // 休眠用户
  501. $dormancyUser = $AccountsInfoModel->dormancy_user();
  502. // 流失用户
  503. $lsUser = $AccountsInfoModel->ls_user();
  504. // 总注册用户
  505. $register = $AccountsInfoModel->user_count();
  506. // 签到总奖励
  507. $totalSignIn = $AccountsInfoModel->accountSignIn();
  508. // 周卡购买报表
  509. $weeklyCard = $GlobalLogic->WeeklyCard();
  510. return compact('paySum', 'payUserCount', 'withdraw', 'withDrawRecovery', 'dormancyUser', 'lsUser', 'register', 'totalSignIn', 'weeklyCard');
  511. }
  512. // 全局报表 - 游戏相关
  513. // 全局报表 - 游戏相关
  514. public function games($StartDataID, $EndDataID)
  515. {
  516. // 流水、输赢、彩金
  517. $gameInfo = DB::connection('read')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  518. // ->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')
  519. ->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')
  520. ->first();
  521. foreach ($gameInfo as &$value) {
  522. $value = number_float($value / NumConfig::NUM_VALUE);
  523. }
  524. unset($value);
  525. // 房间库存
  526. $roomStock = GameRoomInfo::RoomStock(config('games.openKGame'));
  527. // 游戏房间数据--汇总
  528. // $gameRoomInfo = DB::connection('read')->table(TableName::QPRecordDB() . 'RecordServerDataStatistics')
  529. // ->where('DateID', '>=', $StartDataID)
  530. // ->where('DateID', '<=', $EndDataID)
  531. //// ->selectRaw('sum(TotalBet) as flowing_water,Isnull(sum(Revenue),0) as Revenue,Isnull((sum(WinScore) + sum(LostScore)),0) as win_lose')
  532. // ->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')
  533. // ->first();
  534. $gameRoomInfo=DB::table('QPRecordDB.dbo.RecordGameRoomDayInfo')
  535. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  536. ->where('SortID','-1')
  537. ->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')
  538. ->first();
  539. $gameRoomInfo2=DB::table('QPPlatformDB.dbo.RoomStockDay')
  540. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  541. ->selectRaw('sum(Winlost) as win_lose,sum(PayWinlost) as pay_win_lose')->first();
  542. $gameRoomInfo->win_lose=$gameRoomInfo2->win_lose;
  543. $gameRoomInfo->pay_win_lose=$gameRoomInfo2->pay_win_lose;
  544. // 游戏人数
  545. $totalGameCount = DB::table(TableName::QPRecordDB() . 'RecordUserGameDayCount')
  546. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  547. ->distinct()
  548. ->count('UserID');
  549. // 游戏人数
  550. $pay_totalGameCount = DB::table(TableName::QPRecordDB() . 'RecordUserGameDayCount as ru')
  551. ->join('QPAccountsDB.dbo.YN_VIPAccount as v', 'ru.UserID', '=', 'v.UserID')
  552. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  553. ->distinct()
  554. ->count('ru.UserID');
  555. foreach ($gameRoomInfo as &$value) {
  556. $value = number_float($value / NumConfig::NUM_VALUE);
  557. }
  558. unset($value);
  559. if (!empty($gameRoomInfo)) {
  560. // 平台输赢 = 输赢 + 税收
  561. $gameRoomInfo->win_lose = $gameRoomInfo->win_lose + $gameRoomInfo->Revenue;
  562. }
  563. // 游戏房间数据 -- 列表
  564. // $gameList = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo as gi')
  565. // ->leftJoin('QPRecordDB.dbo.RecordServerDataStatistics as rds', 'rds.ServerID', 'gi.ServerID')
  566. // ->leftJoin('QPRecordDB.dbo.RecordUserGameDayCount as rgc', function ($query) {
  567. // $query->on('rgc.GameID', 'rds.ServerID')->on('rds.DateID', 'rgc.DateID');
  568. // })
  569. // ->whereBetween('rds.DateID', [$StartDataID, $EndDataID])
  570. // ->select('gi.GameID', 'gi.ServerName', 'gi.ServerID')
  571. // ->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')
  572. // ->selectRaw('WinScore,LostScore,Revenue,WinUserCount,LostUserCount,gi.GameID,gi.ServerName,gi.ServerID')
  573. // ->get();
  574. $gameList = DB::table(TableName::QPRecordDB() . 'RecordGameRoomDayInfo as ri')
  575. ->where('ri.SortID', '>', 0)
  576. ->whereBetween('ri.DateID', [$StartDataID, $EndDataID])
  577. ->leftJoin(TableName::QPPlatformDB() . 'RoomStockDay as rs', function ($query) {
  578. $query->on('ri.GameID', 'rs.GameID')->on('ri.SortID', 'rs.SortID')->on('ri.DateID', 'rs.DateID');
  579. })
  580. ->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')
  581. ->get();
  582. // 游戏输赢 + 控制输赢
  583. $RoomControlStockDay = DB::table(TableName::QPPlatformDB().'RoomControlStockDay')
  584. ->whereBetween('DateID', [$StartDataID, $EndDataID])
  585. ->get();
  586. $gameServerNames = DB::table(TableName::QPPlatformDB() . 'RoomConfig')->get();
  587. $chu = $zhong = $gao = 0;
  588. $chu_n = $zhong_n = $gao_n = 0;
  589. // dd($gameList);
  590. $gamesorts=[];
  591. $revenueGames = config('games.revenueGames');
  592. foreach ($gameList as &$value) {
  593. $value->ServerName = '';
  594. $value->flowing_water = is_null($value->flowing_water) ? 0 : number_float($value->flowing_water / NumConfig::NUM_VALUE);
  595. $value->flowing_water_new = is_null($value->flowing_water_new) ? 0 : number_float($value->flowing_water_new / NumConfig::NUM_VALUE);
  596. $value->Revenue = is_null($value->Revenue) ? 0 : number_float($value->Revenue / NumConfig::NUM_VALUE);
  597. $value->pay_flowing_water_new = is_null($value->pay_flowing_water_new) ? 0 : number_float($value->pay_flowing_water_new / NumConfig::NUM_VALUE);
  598. $value->pay_Revenue = is_null($value->pay_Revenue) ? 0 : number_float($value->pay_Revenue / NumConfig::NUM_VALUE);
  599. //玩家不扣税的游戏不累计到统计里
  600. if(!in_array($value->GameID,$revenueGames)){
  601. $gameRoomInfo->win_lose = $gameRoomInfo->win_lose-$value->Revenue;
  602. $gameRoomInfo->pay_win_lose = $gameRoomInfo->pay_win_lose-$value->pay_Revenue;
  603. $gameRoomInfo->Revenue = $gameRoomInfo->Revenue-$value->Revenue; //真是税收收入
  604. $gameRoomInfo->pay_Revenue = $gameRoomInfo->pay_Revenue-$value->pay_Revenue; //真是税收收入
  605. }
  606. $value->win_lose = is_null($value->win_lose) ? 0 : number_float($value->win_lose / NumConfig::NUM_VALUE);
  607. $value->pay_win_lose = is_null($value->pay_win_lose) ? 0 : number_float($value->pay_win_lose / NumConfig::NUM_VALUE);
  608. foreach ($gameServerNames as $serverName) {
  609. if ($value->GameID == $serverName->GameID && $value->SortID == $serverName->SortID) {
  610. $value->ServerName = $serverName->RoomName;
  611. }
  612. }
  613. // 游戏输赢 = 控制输赢 + 库存输赢
  614. foreach ($RoomControlStockDay as $val){
  615. if ($value->GameID == $val->GameID && $value->SortID == $val->SortID && $value->DateID == $val->DateID) {
  616. $value->win_lose = is_null($val->Winlost) ? $value->win_lose : $value->win_lose + ($val->Winlost / NumConfig::NUM_VALUE);
  617. }
  618. }
  619. if($value->SortID == 1){
  620. $chu += $value->flowing_water;
  621. $chu_n += $value->flowing_water_new;
  622. }
  623. if($value->SortID == 2){
  624. $zhong += $value->flowing_water;
  625. $zhong_n += $value->flowing_water_new;
  626. }
  627. if($value->SortID == 3){
  628. $gao += $value->flowing_water;
  629. $gao_n += $value->flowing_water_new;
  630. }
  631. if(!isset($gamesorts[$value->GameID.'-'.$value->SortID])) {
  632. $gamesorts[$value->GameID.'-'.$value->SortID]=(object)['Cnt'=>0,'Revenue'=>0,'pay_Cnt'=>0,'pay_Revenue'=>0,'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];
  633. }
  634. $oldvalue = &$gamesorts[$value->GameID.'-'.$value->SortID];
  635. $oldvalue->Cnt += $value->Cnt;
  636. $oldvalue->Revenue += $value->Revenue;
  637. $oldvalue->flowing_water += $value->flowing_water;
  638. $oldvalue->flowing_water_new += $value->flowing_water_new;
  639. $oldvalue->win_lose += $value->win_lose;
  640. $oldvalue->pay_Cnt += $value->pay_Cnt;
  641. $oldvalue->pay_Revenue += $value->pay_Revenue;
  642. $oldvalue->pay_flowing_water_new += $value->pay_flowing_water_new;
  643. $oldvalue->pay_win_lose += $value->pay_win_lose;
  644. }
  645. $gameList=array_values($gamesorts);
  646. $gameList=Util::arraySort($gameList,'flowing_water_new',SORT_DESC);
  647. if($chu==0)$chu=1;
  648. $zhongRate = (ceil($zhong/$chu*100)/100);
  649. $gaoRate = (ceil($gao/$chu*100)/100);
  650. $total = 1+$zhongRate+$gaoRate;
  651. $zhongRate_n = (ceil($zhong/$chu*100)/100);
  652. $gaoRate_n = (ceil($gao/$chu*100)/100);
  653. $total_n = 1+$zhongRate+$gaoRate;
  654. $rateString = "1:$zhongRate:$gaoRate=$total";
  655. $rateString_n = "1:$zhongRate_n:$gaoRate_n=$total_n";
  656. unset($value);
  657. return compact('gameInfo', 'gameRoomInfo', 'gameList', 'roomStock', 'totalGameCount','pay_totalGameCount','rateString','rateString_n');
  658. }
  659. // 全局报表 - 彩金相关
  660. public function winnings($startTime, $endTime)
  661. {
  662. $startTime = date("Y-m-d 00:00:00", strtotime($startTime));
  663. $endTime = date("Y-m-d 23:59:59", strtotime($endTime));
  664. $ScoreType = [21, 33, 36, 44, 45, 51, 52, 53, 59, 70];
  665. // 21、绑定手机赠送 33、注册赠送 36、推广赚金(彩金) 42、邮件附件(充值彩金) 45、充值彩金 51、首充礼包(彩金) 52、邮件附件(群发彩金) 53、推广赚金(佣金)
  666. $winnings = DB::connection('read')->table(TableName::QPRecordDB() . 'RecordUserScoreChange')
  667. ->where('UpdateTime', '>=', $startTime)
  668. ->where('UpdateTime', '<=', $endTime)
  669. ->whereIn('Reason', $ScoreType)
  670. ->selectRaw('Isnull(SUM(ChangeScore),0) as Score,Reason')
  671. ->groupBy('Reason')
  672. ->pluck('Score', 'Reason')->toArray();
  673. foreach ($winnings as &$val) {
  674. $val = number_float($val / NumConfig::NUM_VALUE);
  675. }
  676. unset($val);
  677. // 彩金总和
  678. $winningsSum = array_sum($winnings);
  679. // 推广总奖励
  680. $totalReward = DB::connection('read')->table(TableName::QPAccountsDB() . 'SystemAgentReward')->select('TotalReward')->first()->TotalReward / NumConfig::NUM_VALUE;
  681. // 签到
  682. $signIn = DB::connection('read')->table(TableName::QPRecordDB() . 'RecordSignIn')
  683. ->where('SignInDate', '>=', $startTime)
  684. ->where('SignInDate', '<=', $endTime)
  685. ->selectRaw('IsNull(sum(RewardScore),0) RewardScore')
  686. ->first()->RewardScore / 100 ?? 0;
  687. return compact('winnings', 'winningsSum', 'totalReward', 'signIn');
  688. }
  689. }