GlobalLogicController.php 56 KB

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