GlobalLogicController.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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. // 手机型号
  585. $data['mobileBand'] = '';
  586. $res = Redis::get('user_ua_' . ($user->UserID ?? ''));
  587. if ($res) {
  588. $ua = $res ?? '';
  589. if (stripos($ua, 'iPhone') !== false) {
  590. $data['mobileBand'] = 'iPhone';
  591. }
  592. if (preg_match('/Android\s[\d\.]+;\s([^)]+)/i', $ua, $match)) {
  593. $data['mobileBand'] = 'Android' . trim($match[1]);
  594. }
  595. $data['mobileBand'] .= "(".mb_substr(trim($ua), 0, 25).")";
  596. }
  597. return compact('data', 'userInfo', 'registerInviteSwitches', 'gameCount', 'userSource', 'OpenPage','platformData');
  598. }
  599. public function id_find1($UserID, $OpenPage)
  600. {
  601. $AccountsInfoModel = new AccountsInfo();
  602. //玩家信息
  603. $User = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo as ai')
  604. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai1', 'ai.SpreaderID', '=', 'ai1.UserID')
  605. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gi', 'ai.UserID', '=', 'gi.UserID')
  606. ->leftJoin('QPAccountsDB.dbo.AccountPhone as ap', 'ai.UserID', 'ap.UserID')
  607. ->where('ai.UserID', $UserID)
  608. ->select('ai.*', 'ai1.GameID as SpreaderID', 'ap.PhoneNum', 'gi.Score', 'gi.Revenue', 'gi.InsureScore', 'gi.Score as gi_Score', 'gi.InsureScore as gi_InsureScore')
  609. ->first();
  610. if (empty($User)) return apiReturnFail('用户不存在');
  611. //////////
  612. /// 游戏时长
  613. $second = $User->PlayTimeCount;
  614. $day = floor($second / (3600 * 24));
  615. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  616. $hour = floor($second / 3600);
  617. $second = $second % 3600;//除去整小时之后剩余的时间
  618. $minute = floor($second / 60);
  619. //返回字符串
  620. $User->PlayGameTime = $day . '天' . $hour . '小时' . $minute . '分';
  621. // 有没有在房间
  622. $User->ServerName = DB::connection('read')->table('QPTreasureDB.dbo.GameScoreLocker as gsl')
  623. ->join('QPPlatformDB.dbo.GameRoomInfo as gri', 'gsl.ServerID', 'gri.ServerID')
  624. ->where('UserID', $UserID)
  625. ->whereRaw('datediff(hh,CollectDate,getdate())<=5')
  626. ->select('ServerName')
  627. ->first()->ServerName ?? '';
  628. // 用户标签
  629. $accountsTab = StoredProcedure::getUserTab($UserID);
  630. $TabType = $accountsTab[0]->TabType ?? '';
  631. $types = [];
  632. if (!empty($accountsTab) && $TabType == 1) {
  633. foreach ($accountsTab[0] as $k => $v) {
  634. if ($k != 'UserID' || $k != 'TabType') {
  635. $types[] = $v;
  636. }
  637. }
  638. }
  639. $GetUserTabTypeEx = StoredProcedure::GetUserTabTypeEx($UserID);
  640. $GetUserTabTypeExType = [];
  641. foreach ($GetUserTabTypeEx as $val) {
  642. $GetUserTabTypeExType[] = $val->type;
  643. }
  644. $types = array_merge($types, $GetUserTabTypeExType);
  645. $explain = DB::connection('read')->table('QPAccountsDB.dbo.AccountsTabExplain')
  646. ->whereIn('TabID', $types)
  647. ->pluck('TypeName', 'TabID');
  648. // 走势图
  649. $r = DB::connection('game')->table(TableName::QPTreasureDB() . 'YN_RecordScoreInfo_' . date('Ym'))
  650. ->selectRaw("Isnull(SUBSTRING(CONVERT(VARCHAR(13),UpdateTime,120),12,5),0) as Stime,Isnull(sum(ChangeScore),0) as Score")
  651. ->where('UserID', $UserID)
  652. ->whereDate('UpdateTime', date("Y-m-d"))
  653. ->groupBy(DB::raw('CONVERT(VARCHAR(13), UpdateTime, 120)'))
  654. ->get()->toArray();
  655. $list = $this->get_str($r);
  656. // +---------------------------充值--------------------------------
  657. // 今日充值-- 今日提现-- 今日彩金 -- 总输赢
  658. $today = $AccountsInfoModel->accountTodayStatistics([$UserID]);
  659. // 全部充值 -- 提现 -- 彩金 -- 总输赢 -- 总得提现手续费
  660. $total = $AccountsInfoModel->accountTotalStatistics([$UserID]);
  661. // 未领取邮件金币
  662. $mail = DB::connection('read')->table('QPAccountsDB.dbo.PrivateMail')
  663. ->where('UserID', $UserID)
  664. ->where('MailStatus', '<', 3)
  665. ->select('UserID', 'BonusString')
  666. ->get();
  667. foreach ($mail as $val) {
  668. $arr = explode(',', $val->BonusString);
  669. if (!empty($arr) && isset($arr[0]) && $arr[0] == 30000) {
  670. if (isset($mailData[$val->UserID])) {
  671. $mailData[$val->UserID] = $mailData[$val->UserID] + $arr[1] ?? 0;
  672. } else {
  673. $mailData[$val->UserID] = $arr[1];
  674. }
  675. }
  676. }
  677. // 月卡 -- 购买
  678. $buyMonthCard = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard as mc')
  679. ->join('QPPlatformDB.dbo.UserMonthCard as uc', 'mc.CardID', 'uc.CardID')
  680. ->where('uc.UserID', $UserID)
  681. ->selectRaw('IsNull(sum(Price),0) TotalReward')
  682. ->first()->TotalReward / 100 ?? 0;
  683. // 月卡 -- 已领
  684. $getMonthCard = DB::connection('read')->table('QPPlatformDB.dbo.UserMonthCard')
  685. ->where('UserID', $UserID)
  686. ->selectRaw('IsNull(sum(TotalReward),0) Reward')
  687. ->first()->Reward / 100 ?? 0;
  688. # 保底值
  689. $StatusValue = 0;
  690. // 可提现金额
  691. $remainingBalance = $AccountsInfoModel->CashAble($UserID, $User->Score, $StatusValue);
  692. // 用户标签展示
  693. $Type12 = $accountsTab[0]->Type12 ?? 0;
  694. $first = in_array($Type12, [1301, 1302, 1303]) ? true : false;
  695. $AccountWithDrawInfo = DB::connection('read')->table('QPAccountsDB.dbo.AccountWithDrawInfo')
  696. ->where('UserID', $UserID)
  697. ->select('Switch')
  698. ->first();
  699. if ($first) {
  700. $userTab = $AccountWithDrawInfo->Switch == 0 ? '已解除' : "<span style='color: #ff0000'>已禁止</span>";
  701. } else {
  702. $userTab = '未标记';
  703. }
  704. // 关联IP数量-- 注册IP
  705. $Ip = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  706. ->where('IsAndroid', 0)
  707. ->where('RegisterIP', $User->RegisterIP)->count();
  708. // 登录IP
  709. $LastLogonIP = DB::connection('read')->table('QPRecordDB.dbo.RecordUserLogonStatistics as a')
  710. ->whereExists(function ($query) {
  711. $query->from(TableName::QPRecordDB() . 'RecordUserLogonStatistics as b')
  712. ->whereRaw('a.LogonIP=b.LogonIP');
  713. })
  714. ->where('UserID', $UserID)
  715. ->selectRaw('count(distinct(UserID)) count_u')
  716. ->first()->count_u;
  717. // 关联银行卡数量
  718. $BankNo = DB::connection('read')->table('QPAccountsDB.dbo.AccountWithDrawInfo as di')
  719. ->join('QPAccountsDB.dbo.AccountWithDrawInfo as dif', 'di.BankNo', 'dif.BankNo')
  720. ->where('di.UserID', $UserID)
  721. ->whereNotNull('di.BankNo')
  722. ->where('di.BankNo', '<>', '')
  723. ->selectRaw('count(1) count,di.BankNo')
  724. ->groupBy('di.BankNo')
  725. ->first();
  726. // 充值奖金 已领
  727. $Reward = DB::connection('read')->table('QPRecordDB.dbo.RecordUserScoreChange')
  728. ->where('Reason', 53)
  729. ->where('UserID', $UserID)
  730. ->selectRaw('sum(ChangeScore) Score')
  731. ->first()->Score / NumConfig::NUM_VALUE ?? 0;
  732. // 充值奖金 可领
  733. $recharge = (new Extensions())->recharge($UserID);
  734. $rechargeScore['Balance'] = number_float($recharge / NumConfig::NUM_VALUE);
  735. $rechargeScore['Reward'] = $Reward;
  736. // 推广赚金 注册已领
  737. $reward = DB::connection('read')->table('QPRecordDB.dbo.RecordUserScoreChange')
  738. ->where('Reason', 72)
  739. ->where('UserID', $UserID)
  740. ->selectRaw('sum(ChangeScore) Score')
  741. ->first()->Score / NumConfig::NUM_VALUE ?? 0;
  742. // 推广赚金 注册可领
  743. $collectable = (new Extensions())->register($UserID)['Register'];
  744. $registerScore['collectable'] = ($collectable / NumConfig::NUM_VALUE);
  745. $registerScore['verify'] = 0;
  746. $registerScore['Reward'] = $reward;
  747. $todayReward = DB::connection('read')->table('QPRecordDB.dbo.RecordUserScoreStatisticsNew')
  748. ->whereIn('ScoreType', [53, 72])
  749. ->where('UserID', $UserID)
  750. ->selectRaw('sum(Score) Score')
  751. ->first()->Score / NumConfig::NUM_VALUE ?? 0;
  752. // 包名
  753. $PackgeName = DB::connection('read')->table('QPRecordDB.dbo.RecordPackageName')
  754. ->where('UserID', $UserID)
  755. ->select('PackgeName')
  756. ->first()->PackgeName ?? '';
  757. // 个人池控制:
  758. $RecordRechargeControl = DB::connection('read')->table('QPRecordDB.dbo.RecordRechargeControl as rc')
  759. ->leftJoin('QPTreasureDB.dbo.RechargeControlConfig as cnf', 'rc.State', 'cnf.ID')
  760. ->where('UserID', $UserID)
  761. ->select('ConfigName', 'State', 'Prob')
  762. ->first();
  763. isset($RecordRechargeControl->Prob) && $RecordRechargeControl->Prob = ($RecordRechargeControl->Prob / NumConfig::NUM_VALUE);
  764. // 反水活动
  765. $UserGameBet = DB::connection('write')->table('QPTreasureDB.dbo.UserGameBet')
  766. ->where('UserID', $UserID)
  767. ->selectRaw('IsNull(cast(HistoryBet as float),0) / 100 HistoryBet,IsNull(cast(NowBet as float),0) / 100 NowBet,RewardTime')
  768. ->first();
  769. $RewardTime = $UserGameBet->RewardTime ?? '';
  770. if ($UserGameBet) {
  771. if (!empty($RewardTime) && strtotime(date('Y-m-d H:i:s')) > strtotime($RewardTime)) {
  772. $UserGameBet->Collectable = number_float($UserGameBet->NowBet);
  773. $UserGameBet->HistoryBet = number_float($UserGameBet->HistoryBet);
  774. $UserGameBet->NowBet = number_float($UserGameBet->NowBet);
  775. } else {
  776. $UserGameBet->HistoryBet = number_float($UserGameBet->HistoryBet);
  777. $UserGameBet->NowBet = number_float($UserGameBet->NowBet);
  778. }
  779. }
  780. // 裂变领取限制开关
  781. $redis = Redis::connection();
  782. $register_invite_switches = $redis->get('register_invite_switches_' . $UserID);
  783. $data = [
  784. 'today_cz' => isset($today[0]->Recharge) ? $today[0]->Recharge : 0,
  785. 'total_cz' => isset($total[0]->Recharge) ? $total[0]->Recharge : 0,
  786. 'today_cellData' => isset($today[0]->Handsel) ? $today[0]->Handsel / NumConfig::NUM_VALUE : 0,
  787. 'total_cellData' => isset($total[0]->Handsel) ? $total[0]->Handsel / NumConfig::NUM_VALUE : 0,
  788. 'withdraw' => isset($total[0]->Withdraw) ? $total[0]->Withdraw / NumConfig::NUM_VALUE : 0,
  789. 'ServiceFee' => isset($total[0]->ServiceFee) ? $total[0]->ServiceFee / NumConfig::NUM_VALUE : 0,
  790. 'today_withdraw' => isset($today[0]->Withdraw) ? $today[0]->Withdraw / NumConfig::NUM_VALUE : 0,
  791. 'total_profit' => isset($total[0]->Score) ? $total[0]->Score / NumConfig::NUM_VALUE : 0,
  792. 'today_profit' => isset($today[0]->Score) ? $today[0]->Score / NumConfig::NUM_VALUE : 0,
  793. 'revenue' => isset($total[0]->Revenue) ? $total[0]->Revenue / NumConfig::NUM_VALUE : 0,
  794. 'buyMonthCard' => $buyMonthCard,
  795. 'getMonthCard' => $getMonthCard,
  796. 'remainingBalance' => $remainingBalance,
  797. 'reward' => $reward,
  798. ];
  799. foreach ($data as &$value) {
  800. $value = number_float($value);
  801. }
  802. $User->Score = number_float($User->Score / 100);
  803. $User->notReceived = isset($mailData[$User->UserID]) ? number_float($mailData[$User->UserID] / 100) : 0;
  804. // 对局
  805. $gameCount = (new GamesCount())->gameCount($UserID);
  806. // 用户来源
  807. $UserSource = (new AccountsSource())->getUserSource($UserID);
  808. return compact('User', 'list', 'data', 'explain', 'userTab', 'Ip', 'BankNo', 'LastLogonIP', 'PackgeName', 'RecordRechargeControl', 'UserGameBet', 'OpenPage', 'rechargeScore', 'registerScore', 'todayReward', 'register_invite_switches', 'gameCount', 'UserSource');
  809. }
  810. // 计算流水的值
  811. public function liushui($where = [])
  812. {
  813. $ServerIDs = [32, 33, 39]; // 过滤试玩场
  814. //$liushui = DB::connection('read')->table('QPRecordDB.dbo.RecordGameInfo')
  815. // ->where($where)
  816. // ->whereNotIn('ServerID', $ServerIDs)
  817. // ->selectRaw('Isnull(sum(ABS(Score)),0) as Score')
  818. // ->first()->Score;
  819. $liushui = DB::connection('read')->table('QPRecordDB.dbo.PD_RecordScoreInfo')
  820. ->where($where)
  821. ->whereNotIn('ServerID', $ServerIDs)
  822. ->selectRaw('Isnull(sum(ABS(Score)),0) as Score')
  823. ->first()->Score;
  824. return $liushui;
  825. }
  826. // 返回字符串
  827. protected function get_str($list)
  828. {
  829. // 定义时间内容
  830. $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"];
  831. $new_arr = [];
  832. foreach ($time_arr as $key => $value) {
  833. if (!empty($list)) {
  834. foreach ($list as &$v) {
  835. if ($value == $v->Stime) {
  836. // $temp_arr['Stime'] = $v->Stime;
  837. $temp_arr['Score'] = $v->Score;
  838. } else {
  839. // $temp_arr['Stime'] = $value;
  840. $temp_arr['Score'] = 0;
  841. }
  842. }
  843. } else {
  844. $temp_arr['Score'] = 0;
  845. }
  846. $new_arr[] = $temp_arr;
  847. }
  848. foreach ($new_arr as $v) {
  849. $v = join(",", $v); //可以用implode将一维数组转换为用逗号连接的字符串,join是别名
  850. $temp[] = $v;
  851. }
  852. $str = "[";
  853. foreach ($temp as $v) {
  854. $str .= $v . ",";
  855. }
  856. $str = substr($str, 0, -1);
  857. $str .= "]";
  858. return $str;
  859. }
  860. // 推广员奖励报表
  861. public function reward($UserID, $SpreaderID, $start_time, $end_time, $Type)
  862. {
  863. $where = [];
  864. !empty($UserID) ? $where[] = ['ai.GameID', '=', $UserID] : $UserID = '';
  865. !empty($SpreaderID) ? $where[] = ['ain.GameID', '=', $SpreaderID] : $SpreaderID = '';
  866. !empty($start_time) && $where[] = ['SendTime', '>=', $start_time];
  867. !empty($end_time) && $where[] = ['SendTime', '<=', $end_time];
  868. !empty($Type) && $where[] = ['ua.Type', $Type];
  869. $list = DB::connection('read')->table('QPRecordDB.dbo.RecordUserAgent as ua')
  870. ->join('QPAccountsDB.dbo.accountsInfo as ai', 'ua.UserID', '=', 'ai.UserID')
  871. ->leftJoin('QPAccountsDB.dbo.accountsInfo as ain', 'ain.UserID', '=', 'ai.SpreaderID')
  872. ->select('ua.Id', 'ai.GameID', 'ain.GameID as SpreaderID', 'DirectRebate', 'SendTime', 'SourceUserID', 'OrderSn', 'ua.UserID', 'ua.Level', 'ua.Type', 'ua.orderIds')
  873. ->where($where)
  874. ->orderBy('SendTime', 'desc')
  875. ->paginate(10);
  876. // 自动审核开关
  877. $AutoVerify = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  878. ->where('StatusName', 'AutoVerify')
  879. ->value('StatusValue');
  880. foreach ($list as &$value) {
  881. $value->DirectRebate = number_float($value->DirectRebate / NumConfig::NUM_VALUE);
  882. $SourceGameID = 1;
  883. switch ($value->Type) {
  884. case 1: // 注册
  885. $SourceGameID = DB::table(TableName::QPAccountsDB() . 'accountsInfo')
  886. ->where('UserID', $value->SourceUserID)
  887. ->value('GameID');
  888. break;
  889. }
  890. $value->SourceGameID = $SourceGameID;
  891. }
  892. unset($value);
  893. $start_time = Helper::timeChange($start_time);
  894. $end_time = Helper::timeChange($end_time);
  895. return compact('list', 'UserID', 'SpreaderID', 'start_time', 'end_time', 'Type', 'AutoVerify');
  896. }
  897. public function winloser($GameID, $UniqueCode, $room, $start_time, $end_time, $excel, $id_list, $ChangeScoreMin, $ChangeScoreMax, $ChangeScoreSort, $afterScoreSort, $searchGame)
  898. {
  899. $where = [];
  900. $UserID = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  901. ->where('GameID', $GameID)
  902. ->select('UserID')
  903. ->first()->UserID ?? '';
  904. if (!empty($id_list) && empty($start_time)) {
  905. $withDrawFinal = DB::connection('read')->table('QPAccountsDB.dbo.OrderWithDraw as ow')
  906. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ow.UserID', 'ai.UserID')
  907. ->where('ow.State', 2)
  908. ->where('ai.GameID', $GameID)
  909. ->where('finishDate', '>=', date('Y-m-d 00:00:00'))
  910. ->select('finishDate')
  911. ->orderByDesc('finishDate')
  912. ->first()->finishDate ?? '';
  913. if (!empty($withDrawFinal)) {
  914. $start_time = date('Y-m-d H:i:s', strtotime($withDrawFinal));
  915. $end_time = date('Y-m-d 23:59:59', strtotime($start_time));
  916. }
  917. }
  918. $start_time = $start_time ?: date('Y-m-d 00:00:00');
  919. $end_time = $end_time ?: date('Y-m-d 23:59:59');
  920. ////////////////////////
  921. // 查询范围需要在同一个月份,暂时不支持跨月份查询
  922. $from_mm = intval(date('Ym', strtotime($start_time)));
  923. $to_mm = intval(date('Ym', strtotime($end_time)));
  924. if ($from_mm != $to_mm) {
  925. throw new \Exception('暂不支持跨月查询,开始时间和结束时间请选择相同月份');
  926. }
  927. //确定有效表范围,从202104月开始到当前月
  928. if ($from_mm < 202204 || $from_mm > intval(date('Ym'))) {
  929. throw new \Exception('超出时间范围,开始时间应大于等于2022年4月,小于等于当前月');
  930. }
  931. $table = TableName::QPTreasureDB() . 'YN_RecordScoreInfo_' . $from_mm;
  932. //////////////////////
  933. $where[] = ['ri.UpdateTime', '>=', date('Y-m-d H:i:s', strtotime($start_time))];
  934. $where[] = ['ri.UpdateTime', '<=', date('Y-m-d H:i:s', strtotime($end_time))];
  935. !empty($GameID) && $where[] = ['ri.UserID', $UserID];
  936. !empty($UniqueCode) && $where[] = ['UniqueCode', 'like', $UniqueCode . '%'];
  937. !empty($room) && $where[] = ['ri.ServerID', '=', $room];
  938. if (!empty($searchGame)) {
  939. $roomIds = DB::table(TableName::QPPlatformDB() . 'GameRoomInfo')
  940. ->where('GameID', $searchGame)
  941. ->select('ServerID')
  942. ->pluck('ServerID')->toArray();
  943. $where[] = [function ($query) use ($roomIds) {
  944. $query->whereIn('ServerID', $roomIds);
  945. }];
  946. }
  947. !empty($ChangeScoreMax) && $ChangeScoreMax = (int)$ChangeScoreMax * NumConfig::NUM_VALUE;
  948. !empty($ChangeScoreMin) && $ChangeScoreMin = (int)$ChangeScoreMin * NumConfig::NUM_VALUE;
  949. if ((!empty($ChangeScoreMax) || $ChangeScoreMax === '0') && (!empty($ChangeScoreMin) || $ChangeScoreMin === '0')) {
  950. $where[] = [function ($obj) use ($ChangeScoreMin, $ChangeScoreMax) {
  951. $obj->whereBetween('ChangeScore', [$ChangeScoreMin, $ChangeScoreMax]);
  952. }];
  953. } elseif (!empty($ChangeScoreMin) || $ChangeScoreMin === '0') {
  954. $where[] = ['ChangeScore', '>=', $ChangeScoreMin];
  955. } elseif (!empty($ChangeScoreMax) || $ChangeScoreMax === '0') {
  956. $where[] = ['ChangeScore', '<=', $ChangeScoreMax];
  957. }
  958. !empty($ChangeScoreSort) && $order = "ChangeScore $ChangeScoreSort";
  959. !empty($afterScoreSort) && $order = "afterScore $afterScoreSort";
  960. !isset($order) && $order = "ri.UpdateTime desc";
  961. // 房间列表
  962. $rooms = DB::connection('read')->table(TableName::QPPlatformDB() . 'GameRoomInfo')
  963. // ->whereIn('GameID', config('games.openKGame'))
  964. ->selectRaw('ServerID,ServerName')
  965. ->orderByDesc('ServerID')
  966. ->pluck('ServerName', 'ServerID')
  967. ->toArray();
  968. $build_sql = DB::connection('game')->table($table . ' as ri')
  969. ->where($where);
  970. // 游戏列表
  971. $games = DB::connection('read')->table(TableName::QPPlatformDB() . 'GameKindItem')
  972. // ->whereIn('GameID', config('games.openKGame'))
  973. ->select('KindName', 'GameID')
  974. ->pluck('KindName', 'GameID')
  975. ->toArray();
  976. // 输赢报表
  977. if (!empty($excel)) {
  978. $list = $build_sql
  979. //->leftJoin('QPPlatformDB.dbo.GameRoomInfo as gi', 'ri.ServerID', '=', 'gi.ServerID')
  980. ->select('UniqueCode', 'UserID', 'ri.UpdateTime', 'BeforeScore', 'ChangeScore', 'afterScore', 'Revenue', 'ServerID')
  981. ->selectRaw('null ServerName')
  982. ->orderBy('ri.UpdateTime', 'desc')->limit(10000)->get();
  983. // 获取用户游戏ID
  984. $getGameIDs = $this->getGameIDs($list);
  985. foreach ($list as &$value) {
  986. if (!empty($GameID)) {
  987. $value->UserID = $GameID;
  988. }else{
  989. $value->UserID = $getGameIDs[$value->UserID] ?? '';
  990. }
  991. $value->ServerName = $rooms[$value->ServerID] ?? '';
  992. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  993. $value->Revenue = number_float($value->Revenue / NumConfig::NUM_VALUE);
  994. $value->afterScore = number_float($value->afterScore / NumConfig::NUM_VALUE);
  995. $value->BeforeScore = number_float($value->BeforeScore / NumConfig::NUM_VALUE);
  996. $value->UniqueCode = (string)($value->UniqueCode) . ' ';
  997. unset($value->ServerID);
  998. }
  999. unset($value);
  1000. $title = ['对局编码', '会员ID', '游戏时间', '变化前金豆', '税后输赢金豆', '变化后输赢金豆', '累计税收', '房间名称'];
  1001. $list = json_decode(json_encode($list), true);
  1002. downloadExcel($list, $title, '输赢报表列表' . date('YmdHis'));
  1003. } else {
  1004. $list = $build_sql
  1005. ->select('ri.UpdateTime', 'ri.ServerID', 'afterScore', 'UserID', 'UniqueCode', 'ChangeScore', 'Revenue', 'BeforeScore')
  1006. ->OrderByRaw($order)
  1007. ->paginate(50);
  1008. }
  1009. // 获取用户游戏ID
  1010. $getGameIDs = $this->getGameIDs($list);
  1011. // +----------------房间总输赢------------------+
  1012. $total = DB::connection('game')->table($table . ' as ri')
  1013. ->where($where)
  1014. ->selectRaw('IsNull(sum(abs(ChangeScore)),0) as water,count(distinct(UserID)) as UserID,sum(ChangeScore) as ChangeScore,sum(Revenue) as Revenue')
  1015. ->first();
  1016. // 税收
  1017. $data['Revenue'] = number_float($total->Revenue / NumConfig::NUM_VALUE);
  1018. // 总输赢
  1019. $data['ChangeScore'] = number_float(((-$total->ChangeScore / NumConfig::NUM_VALUE) - 0));
  1020. // 总人数
  1021. $data['UserID'] = $total->UserID;
  1022. // 流水
  1023. $data['liushui'] = number_float(($total->water) / NumConfig::NUM_VALUE);
  1024. $query=GameCard::query()->select(['brand','title','gid'])->where('state','>',0)->get()->toArray();
  1025. $thirdnames=[];
  1026. foreach ($query as $k=>$v){
  1027. $thirdnames[$v['gid']]=$v['brand'].'_'.$v['title'];
  1028. }
  1029. foreach ($list as &$value) {
  1030. $value->GameID = $getGameIDs[$value->UserID] ?? '';
  1031. $value->ServerName = $rooms[$value->ServerID] ?? '';
  1032. $value->ChangeScore = number_float($value->ChangeScore / NumConfig::NUM_VALUE);
  1033. $value->Revenue = number_float($value->Revenue / NumConfig::NUM_VALUE);
  1034. $value->afterScore = number_float($value->afterScore / NumConfig::NUM_VALUE);
  1035. $value->BeforeScore = number_float($value->BeforeScore / NumConfig::NUM_VALUE);
  1036. if(strstr($value->UniqueCode,'|')){
  1037. $values=explode('|',$value->UniqueCode);
  1038. // $value->ServerID=$values[1];
  1039. $value->thirdRoom=$thirdnames[$values[1]]??'';
  1040. // dd($values,$thirdnames);
  1041. $value->UniqueCode=null;
  1042. }
  1043. }
  1044. $start_time = strtotime($start_time);
  1045. $end_time = strtotime($end_time);
  1046. $start_time = date('Y-m-d', $start_time) . 'T' . date('H:i:s', $start_time);
  1047. $end_time = date('Y-m-d', $end_time) . 'T' . date('H:i:s', $end_time);
  1048. !empty($ChangeScoreMax) && $ChangeScoreMax /= NumConfig::NUM_VALUE;
  1049. !empty($ChangeScoreMin) && $ChangeScoreMin /= NumConfig::NUM_VALUE;
  1050. return compact('list', 'rooms', 'games', 'searchGame', 'GameID', 'data', 'UserID', 'UniqueCode', 'room', 'start_time', 'end_time', 'id_list', 'ChangeScoreMin', 'ChangeScoreMax', 'ChangeScoreSort', 'afterScoreSort');
  1051. }
  1052. public function game_record($UniqueCode, $gameId, $month)
  1053. {
  1054. $where[] = ['UniqueCode', '=', $UniqueCode];
  1055. $list = DB::connection('game')->table(TableName::QPTreasureDB() . 'YN_RecordScoreInfo_' . $month . ' as ri')
  1056. ->where($where)
  1057. ->whereNotNull('UniqueCode')
  1058. ->orderBy('UpdateTime', 'desc')
  1059. ->select('ri.UserID', 'ri.UpdateTime', 'UniqueCode', 'Revenue', 'AfterScore', 'ChangeScore', 'ServerID')
  1060. ->paginate(50);
  1061. // 获取用户游戏ID
  1062. $getGameIDs = $this->getGameIDs($list);
  1063. foreach ($list as &$value) {
  1064. $value->GameID = $getGameIDs[$value->UserID] ?? '';
  1065. $value->ServerName = $rooms[$value->ServerID] ?? '';
  1066. $value->ChangeScore = number_float(($value->ChangeScore + $value->Revenue) / 100);
  1067. $value->Revenue = number_float($value->Revenue / 100);
  1068. $value->AfterScore = number_float($value->AfterScore / 100);
  1069. }
  1070. return compact('list', 'gameId', 'UniqueCode');
  1071. }
  1072. // 获取用户游戏ID
  1073. protected function getGameIDs($list)
  1074. {
  1075. // 取出用户ID
  1076. $UserIDs = [];
  1077. foreach ($list as $value) {
  1078. $UserIDs[] = $value->UserID;
  1079. }
  1080. $getGameIDs = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  1081. ->whereIn('UserID', $UserIDs)
  1082. ->select('GameID', 'UserID')
  1083. ->pluck('GameID', 'UserID')->toArray();
  1084. return $getGameIDs;
  1085. }
  1086. }