GlobalLogicController.php 56 KB

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