GlobalLogicController.php 57 KB

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