ChartController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\DB;
  6. class ChartController extends Controller
  7. {
  8. public function dashboard(Request $request)
  9. {
  10. $start_date = '20210918'; //统计最早开始日期
  11. $from_date = date('Ymd',strtotime('-1 week')); //统计开始时间
  12. $to_date = date('Ymd'); //统计结束时间
  13. // 总充值金额
  14. $recharge_total = DB::connection('read')->table('agent.dbo.order')
  15. ->whereNotNull('pay_at')
  16. ->sum('amount');
  17. // 总提现金额
  18. $withdraw_total = DB::connection('read')->table('QPAccountsDB.dbo.OrderWithDraw')
  19. ->where('State', 2)
  20. ->sum('WithDraw');
  21. // 注册人数
  22. $register_user_count = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  23. ->where('IsAndroid', 0)
  24. ->count();
  25. // 充值人数
  26. $recharge_user_count = DB::connection('read')->table('agent.dbo.order')
  27. ->whereNotNull('pay_at')
  28. ->count(DB::raw('DISTINCT(user_id)'));
  29. // 平台总输赢 从2021-09-18日开始
  30. $win_lose_total = DB::connection('read')->table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
  31. ->where('DateID','>=','20210918')
  32. ->sum(DB::raw('WinScore+LostScore'));
  33. // 平台总流水
  34. $flow_total = DB::connection('read')->table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
  35. ->where('DateID','>=','20210918')
  36. ->sum(DB::raw('WinScore+ABS(LostScore)+Revenue'));
  37. // 总税收
  38. $revenue_total = DB::connection('read')->table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
  39. ->where('DateID','>=','20210918')
  40. ->sum('Revenue');
  41. // 总回收
  42. $recovery_total = DB::connection('read')->table('QPAccountsDB.dbo.OrderWithDraw')
  43. ->where('State', 4)
  44. ->sum('WithDraw');
  45. // 休眠用户
  46. $silent_user_count = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  47. ->whereRaw('DATEDIFF(DAY, LastLogonDate, GETDATE())>7')
  48. ->where('IsAndroid', 0)
  49. ->count();
  50. // 流失用户
  51. $lost_user_count = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  52. ->whereRaw('DATEDIFF(DAY, LastLogonDate, GETDATE())>30')
  53. ->where('IsAndroid', 0)
  54. ->count();
  55. //
  56. // 首充礼包相关数据
  57. //
  58. $first_recharge_count_array = DB::connection('read')->table('QPAccountsDB.dbo.FirstRechargeGifts')
  59. ->select('GiftsID,TotalCount')
  60. ->pluck('TotalCount','GiftsID')
  61. ->toArray();
  62. $first_recharge_amount_array = DB::connection('read')->table('agent.dbo.order')
  63. ->selectRaw('GiftsID,SUM(amount)')
  64. ->where('pay_status',1)
  65. ->groupBy('GiftsID')
  66. ->pluck('TotalCount','GiftsID')
  67. ->toArray();
  68. //
  69. // 周卡相关统计
  70. //
  71. $card_rows = DB::connection('read')->table('QPPlatformDB.dbo.MonthCard')
  72. ->whereIn('CardID',[4,5,6,7])
  73. ->get();
  74. //周卡累计未支付成功
  75. $unpaid_card_total = DB::connection('read')->table('agent.dbo.order')
  76. ->whereIn('GiftsID', [104, 105, 106, 107])
  77. ->where('o.pay_status', 0)
  78. ->sum('amount');
  79. //拉起的总单数
  80. $totalNum = DB::connection('read')->table('agent.dbo.order')
  81. ->whereIn('GiftsID', [104, 105, 106, 107])
  82. ->selectRaw('count(id) count,GiftsID')
  83. ->groupBy('GiftsID')
  84. ->pluck('count', 'GiftsID')
  85. ->toArray();
  86. //
  87. // 不同渠道用户数
  88. //
  89. // 安卓用户数
  90. $android_user_count = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  91. ->where('IsAndroid', 0)
  92. ->where('LastLogonMobile','Android')
  93. ->where('RegisterDate', '>=', $start_date)
  94. ->count();
  95. // IOS用户数
  96. $ios_user_count = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  97. ->where('IsAndroid', 0)
  98. ->where('LastLogonMobile','IOS')
  99. ->where('RegisterDate', '>=', $start_date)
  100. ->count();
  101. // 访客人数
  102. $guest_count = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  103. ->where('WebLogonTimes', 1)
  104. ->where('IsAndroid', 0)
  105. ->where('RegisterDate', '>=', $start_date)
  106. ->count();
  107. // 手机账号人数
  108. $bind_phone_count = DB::connection('read')->table('QPAccountsDB.dbo.AccountPhone')
  109. ->where('BindDate', '>=', $start_date)
  110. ->count();
  111. // facebook用户数
  112. $facebook_user_count = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  113. ->where('RegisterDate', '>=', $start_date)
  114. ->where('IsAndroid', 0)
  115. ->where('WebLogonTimes', 0)
  116. ->count();
  117. // 谷歌试玩场会员人数
  118. $google_user_count = DB::connection('read')->table('QPTreasureDB.dbo.RecordUserInout as ri')
  119. ->join('QPPlatformDB.dbo.GameRoomInfo as gi', 'ri.ServerID', 'gi.ServerID')
  120. ->where('gi.ServerType', 2)
  121. ->where('GameID', 1005)
  122. ->where('ri.EnterTime', '>=', $start_date)
  123. ->count(DB::raw('distinct(ri.UserID)'));
  124. //
  125. // 不同渠道充值
  126. //
  127. // IOS总充值、充值用户数(暂无ios渠道)
  128. $ios_recharge_total = 0;
  129. $ios_recharge_user_count = 0;
  130. // 安卓总充值、充值用户数
  131. $android_order_array = DB::connection('read')->table('agent.dbo.order as o')
  132. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'o.user_id', 'ai.UserID')
  133. ->where('o.pay_at', '>=', $start_date)
  134. ->selectRaw('COUNT(DISTINCT(o.user_id)) count, SUM(amount) amount')
  135. ->lock('with(nolock)')
  136. ->where('LastLogonMobile', 'Android')
  137. ->first()
  138. ->toArray();
  139. $android_recharge_total = $android_order_array['amount'];
  140. $android_recharge_user_count = $android_order_array['count'];
  141. // 谷歌渠道总充值、充值用户数
  142. $google_order_array = DB::connection('read')->table('agent.dbo.order as o')
  143. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'o.user_id', 'ai.UserID')
  144. ->where('Channel', 100)
  145. ->lock('with(nolock)')
  146. ->where('o.pay_at', '>=', $start_date)
  147. ->selectRaw('COUNT(DISTINCT(o.user_id)) count, SUM(amount) amount')
  148. ->first();
  149. $google_recharge_total = $google_order_array['amount'];
  150. $google_recharge_user_count = $google_order_array['count'];
  151. return view('admin.chart.dashboard',[
  152. 'recharge_total' => $recharge_total, //总充值
  153. 'withdraw_total' => $withdraw_total, //总提现
  154. 'register_user_count' => $register_user_count, //注册用户数
  155. 'recharge_user_count' => $recharge_user_count, //充值用户数
  156. 'flow_total' => $flow_total, //平台总流水
  157. 'win_lose_total' => $win_lose_total, //平台总输赢
  158. 'revenue_total' => $revenue_total, //总税收
  159. 'recovery_total' => $recovery_total, //总回收
  160. ]);
  161. }
  162. }