GlobalUser.php 38 KB

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