GlobalLogicController.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. <?php
  2. namespace App\Http\logic\admin;
  3. use App\Facade\TableName;
  4. use App\Game\AgentUser;
  5. use App\Game\GameCard;
  6. use App\Game\GlobalUserInfo;
  7. use App\Http\helper\Helper;
  8. use App\Http\helper\NumConfig;
  9. use App\Models\Account\UserBlacklist;
  10. use App\Models\AccountsInfo;
  11. use App\Models\AccountsSource;
  12. use App\Models\Control;
  13. use App\Models\Cpf;
  14. use App\Models\Order;
  15. use App\Services\Extensions;
  16. use App\Services\GameRoomInfo;
  17. use App\Services\GamesCount;
  18. use App\Services\StoredProcedure;
  19. use Illuminate\Http\Request;
  20. use Illuminate\Pagination\Paginator;
  21. use Illuminate\Support\Facades\DB;
  22. use Illuminate\Support\Facades\Redis;
  23. class GlobalLogicController extends BaseLogicController
  24. {
  25. // 定义税收值
  26. protected $Revenue = 100;
  27. // 单控系统
  28. public function dk($start_time, $end_time, $date)
  29. {
  30. // 今日流水,今日税收
  31. $todayGameInfo = DB::connection('read')->table('QPRecordDB.dbo.RecordServerDataStatistics')
  32. ->selectRaw('Isnull((sum(WinScore) + abs(sum(LostScore))),0) as flowing_water,Isnull(sum(Revenue),0) as Revenue')
  33. ->where('DateID', date('Ymd'))
  34. ->first();
  35. //今日税收
  36. $data['Revenue'] = isset($todayGameInfo->Revenue) ? number_float($todayGameInfo->Revenue / NumConfig::NUM_VALUE) : 0;
  37. //今日流水
  38. $data['flowing_water'] = isset($todayGameInfo->flowing_water) ? number_float(($todayGameInfo->flowing_water + $todayGameInfo->Revenue) / NumConfig::NUM_VALUE) : 0;
  39. //今日总充值金额
  40. $data['pay_sum'] = Order::today_pay()->today_pay_sum / NumConfig::NUM_VALUE ?? 0;
  41. // 今日总提现
  42. $data['today_withdrawal'] = DB::connection('read')->table("QPAccountsDB.dbo.OrderWithDraw as od")
  43. ->join('QPAccountsDB.dbo.AccountsRecord as ar', 'od.RecordID', 'ar.RecordID')
  44. ->whereDate('update_at', date('Y-m-d'))
  45. ->where('State', 2)
  46. ->selectRaw('IsNull((sum(WithDraw) + sum(ServiceFee)),0) WithDraw')
  47. ->first()->WithDraw / NumConfig::NUM_VALUE ?? 0;
  48. //今日彩金
  49. $data['cellData'] = DB::connection('read')->table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
  50. ->selectRaw('Isnull(SUM(Handsel),0) as Handsel')
  51. ->where('DateID', date('Ymd'))
  52. ->first()->Handsel / NumConfig::NUM_VALUE ?? 0;
  53. // 今日杀率 => 被控制输的用户在总活跃用户中的占比
  54. // ---- 控制输的总用户
  55. $shu_member = DB::connection('read')->table('QPTreasureDB.dbo.UserScoreControl')
  56. ->where('ControlRadian', '<', 0)
  57. ->count();
  58. // ---- 总活跃用户占比
  59. $huoyue = DB::connection('read')->table('QPAccountsDB.dbo.accountsInfo')
  60. ->whereRaw("DateDiff(dd,LastLogonDate,getdate())<=7")
  61. ->count();
  62. // 今日杀率
  63. $data['shalv'] = number_float($shu_member / $huoyue);
  64. $start_time = str_replace('T', ' ', $start_time);
  65. $end_time = str_replace('T', ' ', $end_time);
  66. switch ($date) {
  67. case 2:
  68. $start_time = date("Y-m-d 00:00:00", strtotime("-1 day"));
  69. $end_time = date("Y-m-d 23:59:59", strtotime("-1 day"));
  70. break;
  71. case 3:
  72. //当前日期
  73. $sdefaultDate = date("Y-m-d 00:00:00");
  74. //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
  75. $first = 1;
  76. //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
  77. $w = date('w', strtotime($sdefaultDate));
  78. $start_time = date('Y-m-d 00:00:00', strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) . ' days'));
  79. $end_time = date('Y-m-d 23:59:59', strtotime("$start_time +6 days"));
  80. break;
  81. case 4:
  82. $start_time = date("Y-m-01 00:00:00");
  83. $end_time = date("Y-m-t 23:59:59");
  84. break;
  85. }
  86. /* 游戏房间数据 */
  87. $gameRoomInfo = DB::connection('read')->table('QPRecordDB.dbo.RecordServerDataStatistics as rds')
  88. ->where('DateID', '>=', date('Ymd', strtotime($start_time)))
  89. ->where('DateID', '<=', date('Ymd', strtotime($end_time)))
  90. ->selectRaw('Isnull((sum(WinScore) + abs(sum(LostScore))),0) as flowing_water,Isnull(sum(Revenue),0) as Revenue,Isnull((sum(WinScore) + abs(sum(LostScore))),0) as win_lose')
  91. ->first();
  92. //平台输赢 目前计算的是机器人输赢
  93. $gameRoomInfo->win_lose = isset($gameRoomInfo->win_lose) ? number_float(-$gameRoomInfo->win_lose / NumConfig::NUM_VALUE) : 0;
  94. //流水
  95. $gameRoomInfo->flowing_water = isset($gameRoomInfo->flowing_water) ? number_float(($gameRoomInfo->flowing_water + $gameRoomInfo->Revenue) / NumConfig::NUM_VALUE) : 0;
  96. //税收
  97. $gameRoomInfo->Revenue = isset($gameRoomInfo->Revenue) ? number_float($gameRoomInfo->Revenue / NumConfig::NUM_VALUE) : 0;
  98. $game_list = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo as gi')
  99. ->leftJoin('QPRecordDB.dbo.RecordServerDataStatistics as rds', 'rds.ServerID', 'gi.ServerID')
  100. ->where('DateID', '>=', date('Ymd', strtotime($start_time)))
  101. ->where('DateID', '<=', date('Ymd', strtotime($end_time)))
  102. ->select('gi.GameID', 'gi.ServerName', 'gi.ServerID')
  103. ->selectRaw('Isnull((sum(WinScore) + abs(sum(LostScore))),0) as flowing_water,Isnull(sum(Revenue),0) as Revenue,Isnull((sum(WinScore) + abs(sum(LostScore))),0) as win_lose')
  104. ->groupBy('gi.GameID', 'gi.ServerName', 'gi.ServerID')
  105. ->get();
  106. foreach ($game_list as &$value) {
  107. $value->Score = number_float(-($value->win_lose / NumConfig::NUM_VALUE)); // 平台输赢
  108. $value->ri_Revenue = number_float($value->Revenue / NumConfig::NUM_VALUE); // 税收
  109. $value->liushui = number_float(($value->flowing_water) / NumConfig::NUM_VALUE); // 流水
  110. }
  111. $start_time = Helper::timeChange($start_time);
  112. $end_time = Helper::timeChange($end_time);
  113. return compact('data', 'game_list', 'gameRoomInfo', 'start_time', 'end_time', 'date');
  114. }
  115. public function sum()
  116. {
  117. // 玩家身上总金额
  118. $totalAmount = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo as ai')
  119. ->join('QPTreasureDB.dbo.GameScoreInfo as gi', 'ai.UserID', 'gi.UserID')
  120. ->leftJoin('QPAccountsDB.dbo.IDWhiteUser as wu', 'ai.UserID', 'wu.UserID')
  121. ->where('IsAndroid', 0)
  122. ->where('Nullity', 0)
  123. ->whereNull('wu.UserID')
  124. ->sum('Score');
  125. // 官方玩家身上总金额
  126. $official = DB::connection('read')->table('QPAccountsDB.dbo.IDWhiteUser as wu')
  127. ->join('QPTreasureDB.dbo.GameScoreInfo as gi', 'wu.UserID', 'gi.UserID')
  128. ->sum('Score');
  129. // 充值用户身上总金额--排除官方用户
  130. $payUser = DB::connection('read')->table('QPAccountsDB.dbo.YN_VIPAccount as vip')
  131. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gi', 'vip.UserID', 'gi.UserID')
  132. ->leftJoin('QPAccountsDB.dbo.IDWhiteUser as wu', 'vip.UserID', 'wu.UserID')
  133. ->whereNull('wu.UserID')
  134. ->selectRaw('sum(Score) as Score')
  135. ->first()->Score;
  136. // Tp群控总库存
  137. $TpRoomStock = GameRoomInfo::RoomStock([1005], [32]);
  138. // Rm群控总库存
  139. $RmRoomStock = GameRoomInfo::RoomStock([2030, 2050], [33, 39]);
  140. // 总库存
  141. $groupControlTotalStock = $TpRoomStock + $RmRoomStock;
  142. // 房间总库存 = 群控库存 + 单控库存 + 新手池库存 + 旧房间库存
  143. $oldStock = -2289781;
  144. $oldStock1 = -2088570;
  145. $roomTotalStock = $groupControlTotalStock + ($oldStock) + ($oldStock1);
  146. return compact('totalAmount', 'official', 'payUser', 'groupControlTotalStock', 'roomTotalStock', 'TpRoomStock', 'RmRoomStock', 'oldStock', 'oldStock1');
  147. }
  148. // 月卡
  149. public function MonthCard()
  150. {
  151. // 白银
  152. $SilverVIP = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard')
  153. ->where('CardID', '1')
  154. ->first();
  155. // 黄金
  156. $GoldVIP = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard')
  157. ->where('CardID', '2')
  158. ->first();
  159. // 钻石
  160. $DiamondVIP = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard')
  161. ->where('CardID', '3')
  162. ->first();
  163. // 累计购买金额
  164. $TotalPrice = $SilverVIP->TotalPrice + $GoldVIP->TotalPrice + $DiamondVIP->TotalPrice;
  165. // 累计领取金额
  166. $TotalReward = $SilverVIP->TotalReward + $GoldVIP->TotalReward + $DiamondVIP->TotalReward;
  167. // 额外赠送金额 --- VIP月卡累计领取金额 - VIP月卡累计购买金额=VIP月卡额外赠送金额。
  168. $givePrice = $TotalReward - $TotalPrice > 0 ? $TotalReward - $TotalPrice : 0;
  169. // 总得付费人数
  170. $totalPay = DB::connection('read')->table('agent.dbo.order')->where('pay_status', 1)->selectRaw('count(distinct(user_id)) count_U')->first()->count_U ?? 0;
  171. // 付费玩家整体月卡购买人数
  172. $monthCardPay = DB::connection('read')->table('QPPlatformDB.dbo.UserMonthCard')
  173. ->selectRaw('count(distinct(UserID)) count_U')
  174. ->first()->count_U ?? 0;
  175. // 付费玩家白银月卡购买人数
  176. $silverPay = DB::connection('read')->table('QPPlatformDB.dbo.UserMonthCard')
  177. ->where('CardID', 1)
  178. ->selectRaw('count(distinct(UserID)) count_U')
  179. ->first()->count_U ?? 0;
  180. // 付费玩家黄金月卡购买人数
  181. $goldPay = DB::table('QPPlatformDB.dbo.UserMonthCard')
  182. ->where('CardID', 2)
  183. ->selectRaw('count(distinct(UserID)) count_U')
  184. ->first()->count_U ?? 0;
  185. // 付费玩家钻石月卡购买人数
  186. $diamondPay = DB::connection('read')->table('QPPlatformDB.dbo.UserMonthCard')
  187. ->where('CardID', 3)
  188. ->selectRaw('count(distinct(UserID)) count_U')
  189. ->first()->count_U ?? 0;
  190. $totalRate = $totalPay > 0 ? number_float(($monthCardPay / $totalPay) * NumConfig::NUM_VALUE) . ' %' : 0;
  191. $silverRate = $totalPay > 0 ? number_float(($silverPay / $totalPay) * NumConfig::NUM_VALUE) . ' %' : 0;
  192. $diamondRate = $totalPay > 0 ? number_float(($diamondPay / $totalPay) * NumConfig::NUM_VALUE) . ' %' : 0;
  193. $goldRate = $totalPay > 0 ? number_float(($goldPay / $totalPay) * NumConfig::NUM_VALUE) . ' %' : 0;
  194. $TotalPrice = number_float($TotalPrice / NumConfig::NUM_VALUE);
  195. $TotalReward = number_float($TotalReward / NumConfig::NUM_VALUE);
  196. $givePrice = number_float($givePrice / NumConfig::NUM_VALUE);
  197. return compact('SilverVIP', 'GoldVIP', 'DiamondVIP', 'TotalPrice', 'TotalReward', 'givePrice', 'totalRate', 'silverRate', 'goldRate', 'diamondRate');
  198. }
  199. public function FirstRechargeGifts()
  200. {
  201. // 白银首充礼包支付金额
  202. $silver = DB::connection('read')
  203. ->table('agent.dbo.order as o')
  204. ->join('QPAccountsDB.dbo.FirstRechargeGifts as frg', 'o.GiftsID', 'frg.GiftsID')
  205. ->where('o.GiftsID', 1)
  206. ->where('o.pay_status', 1)
  207. ->selectRaw('IsNull(sum(amount),0) amount,IsNull(TotalCount,0) TotalCount')
  208. ->groupBy('TotalCount')
  209. ->lock('with(nolock)')
  210. ->first();
  211. // 黄金首充礼包支付金额
  212. $gold = DB::connection('read')
  213. ->table('agent.dbo.order as o')
  214. ->join('QPAccountsDB.dbo.FirstRechargeGifts as frg', 'o.GiftsID', 'frg.GiftsID')
  215. ->where('o.GiftsID', 2)
  216. ->where('o.pay_status', 1)
  217. ->selectRaw('IsNull(sum(amount),0) amount,IsNull(TotalCount,0) TotalCount')
  218. ->groupBy('TotalCount')
  219. ->lock('with(nolock)')
  220. ->first();
  221. // 钻石首充礼包支付金额
  222. $diamonds = DB::connection('read')
  223. ->table('agent.dbo.order as o')
  224. ->join('QPAccountsDB.dbo.FirstRechargeGifts as frg', 'o.GiftsID', 'frg.GiftsID')
  225. ->where('o.GiftsID', 3)
  226. ->where('o.pay_status', 1)
  227. ->selectRaw('IsNull(sum(amount),0) amount,IsNull(TotalCount,0) TotalCount')
  228. ->groupBy('TotalCount')
  229. ->lock('with(nolock)')
  230. ->first();
  231. // 注册日期--开始时间
  232. $date = '2021-07-30 00:00:00';
  233. $silverMemberCount = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')->where('RegisterDate', '>=', $date)->count();
  234. $goldMemberCount = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')->where('RegisterDate', '>=', $date)->count();
  235. $diamondsMemberCount = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')->where('RegisterDate', '>=', $date)->count();
  236. // 白银首充礼包购买率
  237. $silverBuyRate = ($silver && $silverMemberCount > 0) ? number_float(($silver->TotalCount / $silverMemberCount) * NumConfig::NUM_VALUE) . '%' : 0;
  238. // 黄金首充礼包购买率
  239. $goldBuyRate = ($gold && $goldMemberCount > 0) ? number_float(($gold->TotalCount / $goldMemberCount) * NumConfig::NUM_VALUE) . '%' : 0;
  240. // 钻石首充礼包购买率
  241. $diamondsBuyRate = ($diamonds && $diamondsMemberCount > 0) ? number_float(($diamonds->TotalCount / $diamondsMemberCount) * NumConfig::NUM_VALUE) . '%' : 0;
  242. // 首充礼包额外赠送总彩金
  243. $lottery = DB::connection('read')->table('QPRecordDB.dbo.PD_RecordScoreInfo')
  244. ->where('Reason', 51)
  245. ->sum('Score');
  246. $lottery = number_float($lottery / NumConfig::NUM_VALUE);
  247. $waitPay = DB::connection('read')
  248. ->table('agent.dbo.order as o')
  249. ->join('QPAccountsDB.dbo.FirstRechargeGifts as frg', 'o.GiftsID', 'frg.GiftsID')
  250. ->whereNull('o.pay_at')
  251. ->whereIn('o.GiftsID', [1, 2, 3])
  252. ->lock('with(nolock)')
  253. ->count();
  254. $paySuc = DB::connection('read')
  255. ->table('agent.dbo.order as o')
  256. ->join('QPAccountsDB.dbo.FirstRechargeGifts as frg', 'o.GiftsID', 'frg.GiftsID')
  257. ->where('o.pay_status', 1)
  258. ->whereIn('o.GiftsID', [1, 2, 3])
  259. ->lock('with(nolock)')
  260. ->count();
  261. // 所有首充礼包购买成功率
  262. $paySucRate = $waitPay > 0 ? number_float(($paySuc / $waitPay) * NumConfig::NUM_VALUE) . '%' : 0;
  263. if ($silver)
  264. $silver->amount = number_float($silver->amount / NumConfig::NUM_VALUE);
  265. if ($gold)
  266. $gold->amount = number_float($gold->amount / NumConfig::NUM_VALUE);
  267. if ($diamonds)
  268. $diamonds->amount = number_float($diamonds->amount / NumConfig::NUM_VALUE);
  269. return compact('silver', 'gold', 'diamonds', 'silverBuyRate', 'goldBuyRate', 'diamondsBuyRate', 'lottery', 'paySucRate');
  270. }
  271. public function WeeklyCard()
  272. {
  273. // 未支付
  274. $totalWaitPay = DB::connection('read')
  275. ->table('agent.dbo.order as o')
  276. ->where('o.pay_status', 0)
  277. ->whereIn('o.GiftsID', [104, 105, 106, 107])
  278. ->selectRaw('IsNull(sum(amount),0) amount')
  279. ->lock('with(nolock)')
  280. ->first();
  281. // 周卡VIP1
  282. $weekVIP1 = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard')
  283. ->where('CardID', '4')
  284. ->select('Price', 'TotalPrice', 'TotalCount', 'TotalReward')
  285. ->first();
  286. // 周卡VIP2
  287. $weekVIP2 = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard')
  288. ->where('CardID', '5')
  289. ->select('Price', 'TotalPrice', 'TotalCount', 'TotalReward')
  290. ->first();
  291. // 周卡VIP3
  292. $weekVIP3 = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard')
  293. ->where('CardID', '6')
  294. ->select('Price', 'TotalPrice', 'TotalCount', 'TotalReward')
  295. ->first();
  296. // 周卡VIP4
  297. $weekVIP4 = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard')
  298. ->where('CardID', '7')
  299. ->select('Price', 'TotalPrice', 'TotalCount', 'TotalReward')
  300. ->first();
  301. // 累计购买金额
  302. $TotalPrice = $weekVIP1->TotalPrice + $weekVIP2->TotalPrice + $weekVIP3->TotalPrice + $weekVIP4->TotalPrice;
  303. // 累计领取金额
  304. $TotalReward = $weekVIP1->TotalReward + $weekVIP2->TotalReward + $weekVIP3->TotalReward + $weekVIP4->TotalReward;
  305. // 额外赠送金额 --- VIP月卡累计领取金额 - VIP月卡累计购买金额=VIP月卡额外赠送金额。
  306. //$givePrice = $TotalReward - $TotalPrice > 0 ? $TotalReward - $TotalPrice : 0;
  307. // 拉起的总单数
  308. $totalNum = DB::connection('read')->table('agent.dbo.order')
  309. ->whereIn('GiftsID', [104, 105, 106, 107])
  310. ->selectRaw('count(id) count,GiftsID')
  311. ->groupBy('GiftsID')
  312. ->pluck('count', 'GiftsID')->toArray();
  313. // 购买率 = 购买成功的单数 / 拉起的单数
  314. $VIP1Rate = isset($totalNum['104']) && $totalNum['104'] ? number_float(($weekVIP1->TotalCount / $totalNum['104']) * NumConfig::NUM_VALUE) . ' %' : 0;
  315. $VIP2Rate = isset($totalNum['105']) && $totalNum['105'] ? number_float(($weekVIP2->TotalCount / $totalNum['105']) * NumConfig::NUM_VALUE) . ' %' : 0;
  316. $VIP3Rate = isset($totalNum['106']) && $totalNum['106'] ? number_float(($weekVIP3->TotalCount / $totalNum['106'])) . ' %' : 0;
  317. $VIP4Rate = isset($totalNum['107']) && $totalNum['107'] ? number_float(($weekVIP4->TotalCount / $totalNum['107'])) . ' %' : 0;
  318. $totalWaitPay = isset($totalWaitPay->amount) ? $totalWaitPay->amount / NumConfig::NUM_VALUE : 0;
  319. $TotalReward = number_float($TotalReward / NumConfig::NUM_VALUE);
  320. return compact('VIP1Rate', 'VIP2Rate', 'VIP3Rate', 'VIP4Rate', 'totalWaitPay', 'TotalPrice', 'TotalReward', 'weekVIP1', 'weekVIP2', 'weekVIP3', 'weekVIP4');
  321. }
  322. // 房间实时数据
  323. public function room($list)
  324. {
  325. /*
  326. $WinUserCount = DB::connection('read')->table('QPRecordDB.dbo.RecordGameInfo')
  327. ->whereDate('CreateTime', date('Y-m-d'))
  328. ->selectRaw('count(distinct(UserID)) as count_u,ServerID')
  329. ->havingRaw('sum(Score) > ?', [0])
  330. ->groupBy('ServerID')
  331. ->pluck('count_u', 'ServerID');
  332. $LostUserCount = DB::connection('read')->table('QPRecordDB.dbo.RecordGameInfo')
  333. ->whereDate('CreateTime', date('Y-m-d'))
  334. ->selectRaw('count(distinct(UserID)) as count_u,ServerID')
  335. ->havingRaw('sum(Score) < ?', [0])
  336. ->groupBy('ServerID')
  337. ->pluck('count_u', 'ServerID');
  338. */
  339. $WinUserCount = DB::connection('read')->table('QPRecordDB.dbo.PD_RecordScoreInfo')
  340. ->selectRaw('count(distinct(UserID)) as count_u,ServerID')
  341. ->where('AtDate', '=', date('Ymd'))
  342. ->where('Score', '>', 0)
  343. ->groupBy('ServerID')
  344. ->pluck('count_u', 'ServerID');
  345. $LostUserCount = DB::connection('read')->table('QPRecordDB.dbo.PD_RecordScoreInfo')
  346. ->selectRaw('count(distinct(UserID)) as count_u,ServerID')
  347. ->where('AtDate', '=', date('Ymd'))
  348. ->where('Score', '<', 0)
  349. ->groupBy('ServerID')
  350. ->pluck('count_u', 'ServerID');
  351. foreach ($list as &$value) {
  352. // 库存
  353. $stock_toarr = explode(';', rtrim($value->RoomStock, ';'));
  354. if (isset($stock_toarr[0]) && !empty($stock_toarr[0])) {
  355. $stock = explode(':', $stock_toarr[0])[1];
  356. } else {
  357. $stock = 0;
  358. }
  359. // 当天房间胜率 --- 胜的局数 / 玩的总局数
  360. $value->winning_probability = $value->TotalInning > 0 ? number_float($value->WinInning / $value->TotalInning) : 0;
  361. $value->stock = $stock / NumConfig::NUM_VALUE;
  362. // 流水
  363. $value->flowing_water = number_float(($value->WinScore + abs($value->LostScore)) / NumConfig::NUM_VALUE);
  364. // 总输赢
  365. $value->win_lose = number_float(($value->WinScore + $value->LostScore) / NumConfig::NUM_VALUE);
  366. // 税收
  367. $value->Revenue = number_float($value->Revenue / NumConfig::NUM_VALUE);
  368. // 当天赢人数
  369. $value->WinUserCount = $WinUserCount[$value->ServerID] ?? 0;
  370. // 当天输人数
  371. $value->LostUserCount = $LostUserCount[$value->ServerID] ?? 0;
  372. }
  373. return $list;
  374. }
  375. public function teenpatti($ServerID)
  376. {
  377. $result = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  378. ->where('ServerID', $ServerID)
  379. ->select('CellScore', 'MinEnterScore', 'MaxEnterScore', 'ServerName', 'CellScore')
  380. ->first();
  381. $result->CellScore = $result->CellScore / 100;
  382. $result->MinEnterScore = number_float($result->MinEnterScore / 100);
  383. $result->MaxEnterScore = number_float($result->MaxEnterScore / 100);
  384. return compact('result');
  385. }
  386. // 多选框搜索
  387. public function user_search($build_sql, $data)
  388. {
  389. if (!is_array($data)) {
  390. $data = [];
  391. }
  392. if (in_array(1, $data)) {
  393. $data['checked1'] = 1;
  394. // 游戏中用户
  395. // $build_sql->whereNotNull("ServerName")->whereDate('CollectDate', date('Y-m-d'));;
  396. $build_sql->whereRaw('datediff(hh,CollectDate,getdate())<=5');
  397. }
  398. if (in_array(2, $data)) {
  399. $data['checked2'] = 2;
  400. $build_sql->where('ai.PassPortID', '');
  401. }
  402. if (in_array(3, $data)) {
  403. $data['checked3'] = 3;
  404. $build_sql->whereNull('ap.PhoneNum');
  405. }
  406. if (in_array(4, $data)) {
  407. $data['checked4'] = 4;
  408. $IP = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  409. ->selectRaw('LastLogonIP,count(*) as count ')
  410. ->groupBy('LastLogonIP')
  411. ->havingRaw('count(*) >1')
  412. ->get();
  413. if (!empty($IP)) {
  414. $arr = [];
  415. foreach ($IP as $k => $v) {
  416. if ($v->LastLogonIP != '未知') {
  417. $arr[$k] = $v->LastLogonIP;
  418. }
  419. }
  420. $build_sql->whereIn('ai.RegisterIP', $arr);
  421. }
  422. }
  423. if (in_array(5, $data)) {
  424. $data['checked5'] = 5;
  425. // 无渠道
  426. $build_sql->where('ai.Channel', 0);
  427. }
  428. if (in_array(6, $data)) {
  429. $data['checked6'] = 6;
  430. $VIP = DB::connection('read')->table('QPAccountsDB.dbo.YN_VIP')->select('ID')->get();
  431. $vip_id = [];
  432. if (!empty($VIP)) {
  433. foreach ($VIP as $k => $v) {
  434. $vip_id[$k] = $v->ID;
  435. }
  436. }
  437. $build_sql->whereNotIn('ai.UserID', $vip_id);
  438. }
  439. if (in_array(7, $data)) {
  440. $data['checked7'] = 7;
  441. $build_sql->where('ai.SpreaderID', '0');
  442. }
  443. if (in_array(8, $data)) {
  444. $data['checked8'] = 8;
  445. $build_sql->where('ai.Nullity', '1');
  446. }
  447. if (in_array(9, $data)) {
  448. $data['checked9'] = 9;
  449. $build_sql->whereNotNull('iu.UserID');
  450. }
  451. return compact('build_sql', 'data');
  452. }
  453. public function id_find($UserID, $OpenPage)
  454. {
  455. $AccountsInfoModel = new AccountsInfo();
  456. //玩家信息
  457. // $userInfo = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  458. // ->where('UserID', $UserID)
  459. // ->first();
  460. $userInfo = AccountsInfo::find($UserID);
  461. // dd($userInfo->gameScoreInfo);
  462. // 用户余额
  463. $score = $userInfo->gameScoreInfo->Score;
  464. $insureScore = $userInfo->gameScoreInfo->InsureScore;
  465. // 上级ID
  466. //$userInfo->spreaderID = $userInfo->SpreaderID;
  467. // 上级ID
  468. // $userInfo->spreaderGameId = AccountsInfo::GetUserGameID($userInfo->spreaderID);
  469. // 用户手机号
  470. $userInfo->phone = $userInfo->accountPhoneRelation->PhoneNum??"";
  471. // 用户游戏时长转换
  472. $userInfo->PlayTimeCount = $AccountsInfoModel->getUserPlayTimeCount($userInfo->PlayTimeCount);
  473. // 用户有没有在游戏
  474. $userInfo->getUserOnLine = $AccountsInfoModel->getUserOnLine($UserID);
  475. // 今日充值-- 今日提现-- 今日彩金 -- 总输赢
  476. $today = $AccountsInfoModel->accountTodayStatistics([$UserID]);
  477. // 全部充值 -- 提现 -- 彩金 -- 总输赢 -- 总得提现手续费
  478. $total = $AccountsInfoModel->accountTotalStatistics([$UserID]);
  479. // 未领取邮件金额
  480. $waitGetEmailScore = $AccountsInfoModel->waitGetEmailScore($UserID);
  481. // 月卡 -- 购买、已领
  482. [$buyMonthCard, $getMonthCard] = $AccountsInfoModel->monthCard($UserID);
  483. // 可提现金额
  484. $remainingBalance = $AccountsInfoModel->CashAble($UserID, 0, 0);
  485. // 关联IP数量-- 注册IP
  486. $userInfo->sameIpCount = $AccountsInfoModel->sameRegisterIPCount($userInfo->RegisterIP);
  487. $userInfo->samePhoneCount = $userInfo->phone?$AccountsInfoModel->samePhoneCount($userInfo->phone):0;
  488. $userInfo->sameWithDrawName = $AccountsInfoModel->sameWithDrawBankNameByUserID($UserID);
  489. // 关联IP数量-- 注册IP
  490. $userInfo->sameCpfCount = Cpf::getCpfCount($UserID);
  491. $rechargeCpf = Cpf::getCpf($UserID,1);
  492. $userInfo->rechargeCpf = $rechargeCpf?implode(',',$rechargeCpf):'';
  493. $userInfo->sameWithDrawMail = $AccountsInfoModel->sameWithDrawEmailByUserID($UserID);
  494. // 登录IP
  495. $userInfo->LastLogonIP = $AccountsInfoModel->sameLoginIPCount($UserID);
  496. // 关联银行卡数量
  497. $userInfo->sameBankNo = $AccountsInfoModel->sameBankNo($UserID);
  498. //关联设备
  499. $userInfo->sameMac = $AccountsInfoModel->sameLoginMacCount($UserID);
  500. // 充值奖金 已领
  501. $rechargeReward = $AccountsInfoModel->UserScoreChange($UserID, 53);
  502. // 充值奖金 可领
  503. $rechargeLastReward = (new Extensions())->recharge($UserID);
  504. // 推广赚金 注册已领
  505. $shareReward = $AccountsInfoModel->UserScoreChange($UserID, 72);
  506. // 推广赚金 注册可领
  507. $shareLastReward = (new Extensions())->register($UserID)['Register'];
  508. // 包名
  509. $userInfo->PackgeName = DB::connection('read')->table('QPRecordDB.dbo.RecordPackageName')
  510. ->where('UserID', $UserID)
  511. ->select('PackgeName')
  512. ->first()->PackgeName ?? '';
  513. // 裂变领取限制开关
  514. $redis = Redis::connection();
  515. $registerInviteSwitches = $redis->get('register_invite_switches_' . $UserID);
  516. // 黑名单
  517. $blacklist = UserBlacklist::where('UserID', $userInfo->UserID)->first();
  518. $userInfo->blacklist = $blacklist ? 1 : 0;
  519. $user = GlobalUserInfo::getGameUserInfo('UserID', $userInfo->UserID);
  520. $userInfo->GlobalUID = @$user->GlobalUID?:'';
  521. $agentUser=AgentUser::query()->where('UserID',$userInfo->UserID)->first();
  522. if($agentUser){
  523. $userInfo->spreaderID = $agentUser->Higher1ID;
  524. }else{
  525. $userInfo->spreaderID = 0;
  526. }
  527. $Record=DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('UserID', $UserID)->where('State',1)->first();
  528. $WithDrawNow=$Record?($Record->WithDraw-$Record->ServiceFee):0;
  529. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  530. ->lock('WITH(NOLOCK)')
  531. ->where('UserID', $UserID)
  532. ->first();
  533. $data = [
  534. 'today_cellData' => $today[0]->Handsel ?? 0,
  535. 'total_cellData' => $total[0]->Handsel ?? 0,
  536. 'withdraw' => $total[0]->Withdraw ?? 0,
  537. 'serviceFee' => $total[0]->ServiceFee ?? 0,
  538. 'MaxDrawBase' => $total[0]->MaxDrawBase ?? 0,
  539. 'today_withdraw' => $today[0]->Withdraw ?? 0,
  540. 'total_profit' => $total[0]->Score ?? 0,
  541. 'today_profit' => $today[0]->Score ?? 0,
  542. 'total_realpay' => -(($total[0]->Recharge??0)*NumConfig::NUM_VALUE-($total[0]->Withdraw ??0)+($total[0]->ServiceFee ??0)-$WithDrawNow),
  543. 'today_realpay' => -(($today[0]->Recharge??0)*NumConfig::NUM_VALUE-($today[0]->Withdraw ?? 0)+($today[0]->ServiceFee ?? 0)-$WithDrawNow),
  544. 'revenue' => $total[0]->Revenue ?? 0,
  545. 'buyMonthCard' => $buyMonthCard,
  546. 'getMonthCard' => $getMonthCard,
  547. 'remainingBalance' => $remainingBalance,
  548. 'rechargeReward' => $rechargeReward,
  549. 'rechargeLastReward' => $rechargeLastReward,
  550. 'shareReward' => $shareReward,
  551. 'shareLastReward' => $shareLastReward,
  552. 'waitGetEmailScore' => $waitGetEmailScore,
  553. 'score' => $score,
  554. 'insureScore' => $insureScore,
  555. 'todayMaxScore' => $today[0]->MaxScore ?? 0,
  556. 'todayMaxWinScore' => $today[0]->MaxWinScore ?? 0,
  557. ];
  558. foreach ($data as $key=>&$value) {
  559. try {
  560. $value = number_float($value / NumConfig::NUM_VALUE);
  561. }catch (\Exception $exception){
  562. echo $key;
  563. var_dump($data);
  564. die;
  565. }
  566. }
  567. $data['pix_cpf'] = $AccountWithDrawInfo?$AccountWithDrawInfo->PixNum:0;
  568. // 不用/100
  569. $data['today_cz'] = $today[0]->Recharge ?? 0;
  570. $data['total_cz'] = $total[0]->Recharge ?? 0;
  571. $data['remainingBalance'] = $remainingBalance;
  572. // 对局
  573. $gameCount = (new GamesCount())->gameCount($UserID);
  574. // 用户来源
  575. $userSource = (new AccountsSource())->getUserSource($UserID);
  576. $platform = ['only','atmosfera','pg','pp'];
  577. $platformData = [];
  578. foreach ($platform as $pitem){
  579. $dkey = 'platform_' . $pitem .'_'.$UserID.'_win_'.date('Ymd');
  580. $key = 'platform_' . $pitem .'_'.$UserID.'_win';
  581. $platformData[$pitem]['total'] = (Redis::get($key)?:0)/100;
  582. $platformData[$pitem]['today'] = (Redis::get($dkey)?:0)/100;
  583. }
  584. return compact('data', 'userInfo', 'registerInviteSwitches', 'gameCount', 'userSource', 'OpenPage','platformData');
  585. }
  586. public function id_find1($UserID, $OpenPage)
  587. {
  588. $AccountsInfoModel = new AccountsInfo();
  589. //玩家信息
  590. $User = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo as ai')
  591. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai1', 'ai.SpreaderID', '=', 'ai1.UserID')
  592. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gi', 'ai.UserID', '=', 'gi.UserID')
  593. ->leftJoin('QPAccountsDB.dbo.AccountPhone as ap', 'ai.UserID', 'ap.UserID')
  594. ->where('ai.UserID', $UserID)
  595. ->select('ai.*', 'ai1.GameID as SpreaderID', 'ap.PhoneNum', 'gi.Score', 'gi.Revenue', 'gi.InsureScore', 'gi.Score as gi_Score', 'gi.InsureScore as gi_InsureScore')
  596. ->first();
  597. if (empty($User)) return apiReturnFail('用户不存在');
  598. //////////
  599. /// 游戏时长
  600. $second = $User->PlayTimeCount;
  601. $day = floor($second / (3600 * 24));
  602. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  603. $hour = floor($second / 3600);
  604. $second = $second % 3600;//除去整小时之后剩余的时间
  605. $minute = floor($second / 60);
  606. //返回字符串
  607. $User->PlayGameTime = $day . '天' . $hour . '小时' . $minute . '分';
  608. // 有没有在房间
  609. $User->ServerName = DB::connection('read')->table('QPTreasureDB.dbo.GameScoreLocker as gsl')
  610. ->join('QPPlatformDB.dbo.GameRoomInfo as gri', 'gsl.ServerID', 'gri.ServerID')
  611. ->where('UserID', $UserID)
  612. ->whereRaw('datediff(hh,CollectDate,getdate())<=5')
  613. ->select('ServerName')
  614. ->first()->ServerName ?? '';
  615. // 用户标签
  616. $accountsTab = StoredProcedure::getUserTab($UserID);
  617. $TabType = $accountsTab[0]->TabType ?? '';
  618. $types = [];
  619. if (!empty($accountsTab) && $TabType == 1) {
  620. foreach ($accountsTab[0] as $k => $v) {
  621. if ($k != 'UserID' || $k != 'TabType') {
  622. $types[] = $v;
  623. }
  624. }
  625. }
  626. $GetUserTabTypeEx = StoredProcedure::GetUserTabTypeEx($UserID);
  627. $GetUserTabTypeExType = [];
  628. foreach ($GetUserTabTypeEx as $val) {
  629. $GetUserTabTypeExType[] = $val->type;
  630. }
  631. $types = array_merge($types, $GetUserTabTypeExType);
  632. $explain = DB::connection('read')->table('QPAccountsDB.dbo.AccountsTabExplain')
  633. ->whereIn('TabID', $types)
  634. ->pluck('TypeName', 'TabID');
  635. // 走势图
  636. $r = DB::connection('game')->table(TableName::QPTreasureDB() . 'YN_RecordScoreInfo_' . date('Ym'))
  637. ->selectRaw("Isnull(SUBSTRING(CONVERT(VARCHAR(13),UpdateTime,120),12,5),0) as Stime,Isnull(sum(ChangeScore),0) as Score")
  638. ->where('UserID', $UserID)
  639. ->whereDate('UpdateTime', date("Y-m-d"))
  640. ->groupBy(DB::raw('CONVERT(VARCHAR(13), UpdateTime, 120)'))
  641. ->get()->toArray();
  642. $list = $this->get_str($r);
  643. // +---------------------------充值--------------------------------
  644. // 今日充值-- 今日提现-- 今日彩金 -- 总输赢
  645. $today = $AccountsInfoModel->accountTodayStatistics([$UserID]);
  646. // 全部充值 -- 提现 -- 彩金 -- 总输赢 -- 总得提现手续费
  647. $total = $AccountsInfoModel->accountTotalStatistics([$UserID]);
  648. // 未领取邮件金币
  649. $mail = DB::connection('read')->table('QPAccountsDB.dbo.PrivateMail')
  650. ->where('UserID', $UserID)
  651. ->where('MailStatus', '<', 3)
  652. ->select('UserID', 'BonusString')
  653. ->get();
  654. foreach ($mail as $val) {
  655. $arr = explode(',', $val->BonusString);
  656. if (!empty($arr) && isset($arr[0]) && $arr[0] == 30000) {
  657. if (isset($mailData[$val->UserID])) {
  658. $mailData[$val->UserID] = $mailData[$val->UserID] + $arr[1] ?? 0;
  659. } else {
  660. $mailData[$val->UserID] = $arr[1];
  661. }
  662. }
  663. }
  664. // 月卡 -- 购买
  665. $buyMonthCard = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard as mc')
  666. ->join('QPPlatformDB.dbo.UserMonthCard as uc', 'mc.CardID', 'uc.CardID')
  667. ->where('uc.UserID', $UserID)
  668. ->selectRaw('IsNull(sum(Price),0) TotalReward')
  669. ->first()->TotalReward / 100 ?? 0;
  670. // 月卡 -- 已领
  671. $getMonthCard = DB::connection('read')->table('QPPlatformDB.dbo.UserMonthCard')
  672. ->where('UserID', $UserID)
  673. ->selectRaw('IsNull(sum(TotalReward),0) Reward')
  674. ->first()->Reward / 100 ?? 0;
  675. # 保底值
  676. $StatusValue = 0;
  677. // 可提现金额
  678. $remainingBalance = $AccountsInfoModel->CashAble($UserID, $User->Score, $StatusValue);
  679. // 用户标签展示
  680. $Type12 = $accountsTab[0]->Type12 ?? 0;
  681. $first = in_array($Type12, [1301, 1302, 1303]) ? true : false;
  682. $AccountWithDrawInfo = DB::connection('read')->table('QPAccountsDB.dbo.AccountWithDrawInfo')
  683. ->where('UserID', $UserID)
  684. ->select('Switch')
  685. ->first();
  686. if ($first) {
  687. $userTab = $AccountWithDrawInfo->Switch == 0 ? '已解除' : "<span style='color: #ff0000'>已禁止</span>";
  688. } else {
  689. $userTab = '未标记';
  690. }
  691. // 关联IP数量-- 注册IP
  692. $Ip = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  693. ->where('IsAndroid', 0)
  694. ->where('RegisterIP', $User->RegisterIP)->count();
  695. // 登录IP
  696. $LastLogonIP = DB::connection('read')->table('QPRecordDB.dbo.RecordUserLogonStatistics as a')
  697. ->whereExists(function ($query) {
  698. $query->from(TableName::QPRecordDB() . 'RecordUserLogonStatistics as b')
  699. ->whereRaw('a.LogonIP=b.LogonIP');
  700. })
  701. ->where('UserID', $UserID)
  702. ->selectRaw('count(distinct(UserID)) count_u')
  703. ->first()->count_u;
  704. // 关联银行卡数量
  705. $BankNo = DB::connection('read')->table('QPAccountsDB.dbo.AccountWithDrawInfo as di')
  706. ->join('QPAccountsDB.dbo.AccountWithDrawInfo as dif', 'di.BankNo', 'dif.BankNo')
  707. ->where('di.UserID', $UserID)
  708. ->whereNotNull('di.BankNo')
  709. ->where('di.BankNo', '<>', '')
  710. ->selectRaw('count(1) count,di.BankNo')
  711. ->groupBy('di.BankNo')
  712. ->first();
  713. // 充值奖金 已领
  714. $Reward = DB::connection('read')->table('QPRecordDB.dbo.RecordUserScoreChange')
  715. ->where('Reason', 53)
  716. ->where('UserID', $UserID)
  717. ->selectRaw('sum(ChangeScore) Score')
  718. ->first()->Score / NumConfig::NUM_VALUE ?? 0;
  719. // 充值奖金 可领
  720. $recharge = (new Extensions())->recharge($UserID);
  721. $rechargeScore['Balance'] = number_float($recharge / NumConfig::NUM_VALUE);
  722. $rechargeScore['Reward'] = $Reward;
  723. // 推广赚金 注册已领
  724. $reward = DB::connection('read')->table('QPRecordDB.dbo.RecordUserScoreChange')
  725. ->where('Reason', 72)
  726. ->where('UserID', $UserID)
  727. ->selectRaw('sum(ChangeScore) Score')
  728. ->first()->Score / NumConfig::NUM_VALUE ?? 0;
  729. // 推广赚金 注册可领
  730. $collectable = (new Extensions())->register($UserID)['Register'];
  731. $registerScore['collectable'] = ($collectable / NumConfig::NUM_VALUE);
  732. $registerScore['verify'] = 0;
  733. $registerScore['Reward'] = $reward;
  734. $todayReward = DB::connection('read')->table('QPRecordDB.dbo.RecordUserScoreStatisticsNew')
  735. ->whereIn('ScoreType', [53, 72])
  736. ->where('UserID', $UserID)
  737. ->selectRaw('sum(Score) Score')
  738. ->first()->Score / NumConfig::NUM_VALUE ?? 0;
  739. // 包名
  740. $PackgeName = DB::connection('read')->table('QPRecordDB.dbo.RecordPackageName')
  741. ->where('UserID', $UserID)
  742. ->select('PackgeName')
  743. ->first()->PackgeName ?? '';
  744. // 个人池控制:
  745. $RecordRechargeControl = DB::connection('read')->table('QPRecordDB.dbo.RecordRechargeControl as rc')
  746. ->leftJoin('QPTreasureDB.dbo.RechargeControlConfig as cnf', 'rc.State', 'cnf.ID')
  747. ->where('UserID', $UserID)
  748. ->select('ConfigName', 'State', 'Prob')
  749. ->first();
  750. isset($RecordRechargeControl->Prob) && $RecordRechargeControl->Prob = ($RecordRechargeControl->Prob / NumConfig::NUM_VALUE);
  751. // 反水活动
  752. $UserGameBet = DB::connection('write')->table('QPTreasureDB.dbo.UserGameBet')
  753. ->where('UserID', $UserID)
  754. ->selectRaw('IsNull(cast(HistoryBet as float),0) / 100 HistoryBet,IsNull(cast(NowBet as float),0) / 100 NowBet,RewardTime')
  755. ->first();
  756. $RewardTime = $UserGameBet->RewardTime ?? '';
  757. if ($UserGameBet) {
  758. if (!empty($RewardTime) && strtotime(date('Y-m-d H:i:s')) > strtotime($RewardTime)) {
  759. $UserGameBet->Collectable = number_float($UserGameBet->NowBet);
  760. $UserGameBet->HistoryBet = number_float($UserGameBet->HistoryBet);
  761. $UserGameBet->NowBet = number_float($UserGameBet->NowBet);
  762. } else {
  763. $UserGameBet->HistoryBet = number_float($UserGameBet->HistoryBet);
  764. $UserGameBet->NowBet = number_float($UserGameBet->NowBet);
  765. }
  766. }
  767. // 裂变领取限制开关
  768. $redis = Redis::connection();
  769. $register_invite_switches = $redis->get('register_invite_switches_' . $UserID);
  770. $data = [
  771. 'today_cz' => isset($today[0]->Recharge) ? $today[0]->Recharge : 0,
  772. 'total_cz' => isset($total[0]->Recharge) ? $total[0]->Recharge : 0,
  773. 'today_cellData' => isset($today[0]->Handsel) ? $today[0]->Handsel / NumConfig::NUM_VALUE : 0,
  774. 'total_cellData' => isset($total[0]->Handsel) ? $total[0]->Handsel / NumConfig::NUM_VALUE : 0,
  775. 'withdraw' => isset($total[0]->Withdraw) ? $total[0]->Withdraw / NumConfig::NUM_VALUE : 0,
  776. 'ServiceFee' => isset($total[0]->ServiceFee) ? $total[0]->ServiceFee / NumConfig::NUM_VALUE : 0,
  777. 'today_withdraw' => isset($today[0]->Withdraw) ? $today[0]->Withdraw / NumConfig::NUM_VALUE : 0,
  778. 'total_profit' => isset($total[0]->Score) ? $total[0]->Score / NumConfig::NUM_VALUE : 0,
  779. 'today_profit' => isset($today[0]->Score) ? $today[0]->Score / NumConfig::NUM_VALUE : 0,
  780. 'revenue' => isset($total[0]->Revenue) ? $total[0]->Revenue / NumConfig::NUM_VALUE : 0,
  781. 'buyMonthCard' => $buyMonthCard,
  782. 'getMonthCard' => $getMonthCard,
  783. 'remainingBalance' => $remainingBalance,
  784. 'reward' => $reward,
  785. ];
  786. foreach ($data as &$value) {
  787. $value = number_float($value);
  788. }
  789. $User->Score = number_float($User->Score / 100);
  790. $User->notReceived = isset($mailData[$User->UserID]) ? number_float($mailData[$User->UserID] / 100) : 0;
  791. // 对局
  792. $gameCount = (new GamesCount())->gameCount($UserID);
  793. // 用户来源
  794. $UserSource = (new AccountsSource())->getUserSource($UserID);
  795. return compact('User', 'list', 'data', 'explain', 'userTab', 'Ip', 'BankNo', 'LastLogonIP', 'PackgeName', 'RecordRechargeControl', 'UserGameBet', 'OpenPage', 'rechargeScore', 'registerScore', 'todayReward', 'register_invite_switches', 'gameCount', 'UserSource');
  796. }
  797. // 计算流水的值
  798. public function liushui($where = [])
  799. {
  800. $ServerIDs = [32, 33, 39]; // 过滤试玩场
  801. //$liushui = DB::connection('read')->table('QPRecordDB.dbo.RecordGameInfo')
  802. // ->where($where)
  803. // ->whereNotIn('ServerID', $ServerIDs)
  804. // ->selectRaw('Isnull(sum(ABS(Score)),0) as Score')
  805. // ->first()->Score;
  806. $liushui = DB::connection('read')->table('QPRecordDB.dbo.PD_RecordScoreInfo')
  807. ->where($where)
  808. ->whereNotIn('ServerID', $ServerIDs)
  809. ->selectRaw('Isnull(sum(ABS(Score)),0) as Score')
  810. ->first()->Score;
  811. return $liushui;
  812. }
  813. // 返回字符串
  814. protected function get_str($list)
  815. {
  816. // 定义时间内容
  817. $time_arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"];
  818. $new_arr = [];
  819. foreach ($time_arr as $key => $value) {
  820. if (!empty($list)) {
  821. foreach ($list as &$v) {
  822. if ($value == $v->Stime) {
  823. // $temp_arr['Stime'] = $v->Stime;
  824. $temp_arr['Score'] = $v->Score;
  825. } else {
  826. // $temp_arr['Stime'] = $value;
  827. $temp_arr['Score'] = 0;
  828. }
  829. }
  830. } else {
  831. $temp_arr['Score'] = 0;
  832. }
  833. $new_arr[] = $temp_arr;
  834. }
  835. foreach ($new_arr as $v) {
  836. $v = join(",", $v); //可以用implode将一维数组转换为用逗号连接的字符串,join是别名
  837. $temp[] = $v;
  838. }
  839. $str = "[";
  840. foreach ($temp as $v) {
  841. $str .= $v . ",";
  842. }
  843. $str = substr($str, 0, -1);
  844. $str .= "]";
  845. return $str;
  846. }
  847. // 推广员奖励报表
  848. public function reward($UserID, $SpreaderID, $start_time, $end_time, $Type)
  849. {
  850. $where = [];
  851. !empty($UserID) ? $where[] = ['ai.GameID', '=', $UserID] : $UserID = '';
  852. !empty($SpreaderID) ? $where[] = ['ain.GameID', '=', $SpreaderID] : $SpreaderID = '';
  853. !empty($start_time) && $where[] = ['SendTime', '>=', $start_time];
  854. !empty($end_time) && $where[] = ['SendTime', '<=', $end_time];
  855. !empty($Type) && $where[] = ['ua.Type', $Type];
  856. $list = DB::connection('read')->table('QPRecordDB.dbo.RecordUserAgent as ua')
  857. ->join('QPAccountsDB.dbo.accountsInfo as ai', 'ua.UserID', '=', 'ai.UserID')
  858. ->leftJoin('QPAccountsDB.dbo.accountsInfo as ain', 'ain.UserID', '=', 'ai.SpreaderID')
  859. ->select('ua.Id', 'ai.GameID', 'ain.GameID as SpreaderID', 'DirectRebate', 'SendTime', 'SourceUserID', 'OrderSn', 'ua.UserID', 'ua.Level', 'ua.Type', 'ua.orderIds')
  860. ->where($where)
  861. ->orderBy('SendTime', 'desc')
  862. ->paginate(10);
  863. // 自动审核开关
  864. $AutoVerify = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  865. ->where('StatusName', 'AutoVerify')
  866. ->value('StatusValue');
  867. foreach ($list as &$value) {
  868. $value->DirectRebate = number_float($value->DirectRebate / NumConfig::NUM_VALUE);
  869. $SourceGameID = 1;
  870. switch ($value->Type) {
  871. case 1: // 注册
  872. $SourceGameID = DB::table(TableName::QPAccountsDB() . 'accountsInfo')
  873. ->where('UserID', $value->SourceUserID)
  874. ->value('GameID');
  875. break;
  876. }
  877. $value->SourceGameID = $SourceGameID;
  878. }
  879. unset($value);
  880. $start_time = Helper::timeChange($start_time);
  881. $end_time = Helper::timeChange($end_time);
  882. return compact('list', 'UserID', 'SpreaderID', 'start_time', 'end_time', 'Type', 'AutoVerify');
  883. }
  884. public function winloser($GameID, $UniqueCode, $room, $start_time, $end_time, $excel, $id_list, $ChangeScoreMin, $ChangeScoreMax, $ChangeScoreSort, $afterScoreSort, $searchGame)
  885. {
  886. $where = [];
  887. $UserID = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  888. ->where('GameID', $GameID)
  889. ->select('UserID')
  890. ->first()->UserID ?? '';
  891. if (!empty($id_list) && empty($start_time)) {
  892. $withDrawFinal = DB::connection('read')->table('QPAccountsDB.dbo.OrderWithDraw as ow')
  893. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ow.UserID', 'ai.UserID')
  894. ->where('ow.State', 2)
  895. ->where('ai.GameID', $GameID)
  896. ->where('finishDate', '>=', date('Y-m-d 00:00:00'))
  897. ->select('finishDate')
  898. ->orderByDesc('finishDate')
  899. ->first()->finishDate ?? '';
  900. if (!empty($withDrawFinal)) {
  901. $start_time = date('Y-m-d H:i:s', strtotime($withDrawFinal));
  902. $end_time = date('Y-m-d 23:59:59', strtotime($start_time));
  903. }
  904. }
  905. $start_time = $start_time ?: date('Y-m-d 00:00:00');
  906. $end_time = $end_time ?: date('Y-m-d 23:59:59');
  907. ////////////////////////
  908. // 查询范围需要在同一个月份,暂时不支持跨月份查询
  909. $from_mm = intval(date('Ym', strtotime($start_time)));
  910. $to_mm = intval(date('Ym', strtotime($end_time)));
  911. if ($from_mm != $to_mm) {
  912. throw new \Exception('暂不支持跨月查询,开始时间和结束时间请选择相同月份');
  913. }
  914. //确定有效表范围,从202104月开始到当前月
  915. if ($from_mm < 202204 || $from_mm > intval(date('Ym'))) {
  916. throw new \Exception('超出时间范围,开始时间应大于等于2022年4月,小于等于当前月');
  917. }
  918. $table = TableName::QPTreasureDB() . 'YN_RecordScoreInfo_' . $from_mm;
  919. //////////////////////
  920. $where[] = ['ri.UpdateTime', '>=', date('Y-m-d H:i:s', strtotime($start_time))];
  921. $where[] = ['ri.UpdateTime', '<=', date('Y-m-d H:i:s', strtotime($end_time))];
  922. !empty($GameID) && $where[] = ['ri.UserID', $UserID];
  923. !empty($UniqueCode) && $where[] = ['UniqueCode', 'like', $UniqueCode . '%'];
  924. !empty($room) && $where[] = ['ri.ServerID', '=', $room];
  925. if (!empty($searchGame)) {
  926. $roomIds = DB::table(TableName::QPPlatformDB() . 'GameRoomInfo')
  927. ->where('GameID', $searchGame)
  928. ->select('ServerID')
  929. ->pluck('ServerID')->toArray();
  930. $where[] = [function ($query) use ($roomIds) {
  931. $query->whereIn('ServerID', $roomIds);
  932. }];
  933. }
  934. !empty($ChangeScoreMax) && $ChangeScoreMax = (int)$ChangeScoreMax * NumConfig::NUM_VALUE;
  935. !empty($ChangeScoreMin) && $ChangeScoreMin = (int)$ChangeScoreMin * NumConfig::NUM_VALUE;
  936. if ((!empty($ChangeScoreMax) || $ChangeScoreMax === '0') && (!empty($ChangeScoreMin) || $ChangeScoreMin === '0')) {
  937. $where[] = [function ($obj) use ($ChangeScoreMin, $ChangeScoreMax) {
  938. $obj->whereBetween('ChangeScore', [$ChangeScoreMin, $ChangeScoreMax]);
  939. }];
  940. } elseif (!empty($ChangeScoreMin) || $ChangeScoreMin === '0') {
  941. $where[] = ['ChangeScore', '>=', $ChangeScoreMin];
  942. } elseif (!empty($ChangeScoreMax) || $ChangeScoreMax === '0') {
  943. $where[] = ['ChangeScore', '<=', $ChangeScoreMax];
  944. }
  945. !empty($ChangeScoreSort) && $order = "ChangeScore $ChangeScoreSort";
  946. !empty($afterScoreSort) && $order = "afterScore $afterScoreSort";
  947. !isset($order) && $order = "ri.UpdateTime desc";
  948. // 房间列表
  949. $rooms = DB::connection('read')->table(TableName::QPPlatformDB() . 'GameRoomInfo')
  950. // ->whereIn('GameID', config('games.openKGame'))
  951. ->selectRaw('ServerID,ServerName')
  952. ->orderByDesc('ServerID')
  953. ->pluck('ServerName', 'ServerID')
  954. ->toArray();
  955. $build_sql = DB::connection('game')->table($table . ' as ri')
  956. ->where($where);
  957. // 游戏列表
  958. $games = DB::connection('read')->table(TableName::QPPlatformDB() . 'GameKindItem')
  959. // ->whereIn('GameID', config('games.openKGame'))
  960. ->select('KindName', 'GameID')
  961. ->pluck('KindName', 'GameID')
  962. ->toArray();
  963. // 输赢报表
  964. if (!empty($excel)) {
  965. $list = $build_sql
  966. //->leftJoin('QPPlatformDB.dbo.GameRoomInfo as gi', 'ri.ServerID', '=', 'gi.ServerID')
  967. ->select('UniqueCode', 'UserID', 'ri.UpdateTime', 'BeforeScore', 'ChangeScore', 'afterScore', 'Revenue', 'ServerID')
  968. ->selectRaw('null ServerName')
  969. ->orderBy('ri.UpdateTime', 'desc')->limit(10000)->get();
  970. // 获取用户游戏ID
  971. $getGameIDs = $this->getGameIDs($list);
  972. foreach ($list as &$value) {
  973. if (!empty($GameID)) {
  974. $value->UserID = $GameID;
  975. }else{
  976. $value->UserID = $getGameIDs[$value->UserID] ?? '';
  977. }
  978. $value->ServerName = $rooms[$value->ServerID] ?? '';
  979. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  980. $value->Revenue = number_float($value->Revenue / NumConfig::NUM_VALUE);
  981. $value->afterScore = number_float($value->afterScore / NumConfig::NUM_VALUE);
  982. $value->BeforeScore = number_float($value->BeforeScore / NumConfig::NUM_VALUE);
  983. $value->UniqueCode = (string)($value->UniqueCode) . ' ';
  984. unset($value->ServerID);
  985. }
  986. unset($value);
  987. $title = ['对局编码', '会员ID', '游戏时间', '变化前金豆', '税后输赢金豆', '变化后输赢金豆', '累计税收', '房间名称'];
  988. $list = json_decode(json_encode($list), true);
  989. downloadExcel($list, $title, '输赢报表列表' . date('YmdHis'));
  990. } else {
  991. $list = $build_sql
  992. ->select('ri.UpdateTime', 'ri.ServerID', 'afterScore', 'UserID', 'UniqueCode', 'ChangeScore', 'Revenue', 'BeforeScore')
  993. ->OrderByRaw($order)
  994. ->paginate(50);
  995. }
  996. // 获取用户游戏ID
  997. $getGameIDs = $this->getGameIDs($list);
  998. // +----------------房间总输赢------------------+
  999. $total = DB::connection('game')->table($table . ' as ri')
  1000. ->where($where)
  1001. ->selectRaw('IsNull(sum(abs(ChangeScore)),0) as water,count(distinct(UserID)) as UserID,sum(ChangeScore) as ChangeScore,sum(Revenue) as Revenue')
  1002. ->first();
  1003. // 税收
  1004. $data['Revenue'] = number_float($total->Revenue / NumConfig::NUM_VALUE);
  1005. // 总输赢
  1006. $data['ChangeScore'] = number_float(((-$total->ChangeScore / NumConfig::NUM_VALUE) - 0));
  1007. // 总人数
  1008. $data['UserID'] = $total->UserID;
  1009. // 流水
  1010. $data['liushui'] = number_float(($total->water) / NumConfig::NUM_VALUE);
  1011. $query=GameCard::query()->select(['brand','title','gid'])->where('state','>',0)->get()->toArray();
  1012. $thirdnames=[];
  1013. foreach ($query as $k=>$v){
  1014. $thirdnames[$v['gid']]=$v['brand'].'_'.$v['title'];
  1015. }
  1016. foreach ($list as &$value) {
  1017. $value->GameID = $getGameIDs[$value->UserID] ?? '';
  1018. $value->ServerName = $rooms[$value->ServerID] ?? '';
  1019. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  1020. $value->Revenue = number_float($value->Revenue / NumConfig::NUM_VALUE);
  1021. $value->afterScore = number_float($value->afterScore / NumConfig::NUM_VALUE);
  1022. $value->BeforeScore = number_float($value->BeforeScore / NumConfig::NUM_VALUE);
  1023. if(strstr($value->UniqueCode,'|')){
  1024. $values=explode('|',$value->UniqueCode);
  1025. // $value->ServerID=$values[1];
  1026. $value->thirdRoom=$thirdnames[$values[1]]??'';
  1027. // dd($values,$thirdnames);
  1028. $value->UniqueCode=null;
  1029. }
  1030. }
  1031. $start_time = strtotime($start_time);
  1032. $end_time = strtotime($end_time);
  1033. $start_time = date('Y-m-d', $start_time) . 'T' . date('H:i:s', $start_time);
  1034. $end_time = date('Y-m-d', $end_time) . 'T' . date('H:i:s', $end_time);
  1035. !empty($ChangeScoreMax) && $ChangeScoreMax /= NumConfig::NUM_VALUE;
  1036. !empty($ChangeScoreMin) && $ChangeScoreMin /= NumConfig::NUM_VALUE;
  1037. return compact('list', 'rooms', 'games', 'searchGame', 'GameID', 'data', 'UserID', 'UniqueCode', 'room', 'start_time', 'end_time', 'id_list', 'ChangeScoreMin', 'ChangeScoreMax', 'ChangeScoreSort', 'afterScoreSort');
  1038. }
  1039. public function game_record($UniqueCode, $gameId, $month)
  1040. {
  1041. $where[] = ['UniqueCode', '=', $UniqueCode];
  1042. $list = DB::connection('game')->table(TableName::QPTreasureDB() . 'YN_RecordScoreInfo_' . $month . ' as ri')
  1043. ->where($where)
  1044. ->whereNotNull('UniqueCode')
  1045. ->orderBy('UpdateTime', 'desc')
  1046. ->select('ri.UserID', 'ri.UpdateTime', 'UniqueCode', 'Revenue', 'AfterScore', 'ChangeScore', 'ServerID')
  1047. ->paginate(50);
  1048. // 获取用户游戏ID
  1049. $getGameIDs = $this->getGameIDs($list);
  1050. foreach ($list as &$value) {
  1051. $value->GameID = $getGameIDs[$value->UserID] ?? '';
  1052. $value->ServerName = $rooms[$value->ServerID] ?? '';
  1053. $value->ChangeScore = number_float(($value->ChangeScore + $value->Revenue) / 100);
  1054. $value->Revenue = number_float($value->Revenue / 100);
  1055. $value->AfterScore = number_float($value->AfterScore / 100);
  1056. }
  1057. return compact('list', 'gameId', 'UniqueCode');
  1058. }
  1059. // 获取用户游戏ID
  1060. protected function getGameIDs($list)
  1061. {
  1062. // 取出用户ID
  1063. $UserIDs = [];
  1064. foreach ($list as $value) {
  1065. $UserIDs[] = $value->UserID;
  1066. }
  1067. $getGameIDs = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  1068. ->whereIn('UserID', $UserIDs)
  1069. ->select('GameID', 'UserID')
  1070. ->pluck('GameID', 'UserID')->toArray();
  1071. return $getGameIDs;
  1072. }
  1073. }