Home.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\PaymentOrder;
  6. use App\Models\Recharge;
  7. use App\Models\User;
  8. use App\Models\BalanceLog;
  9. use Illuminate\Validation\ValidationException;
  10. use Exception;
  11. use Carbon\Carbon;
  12. use App\Models\Withdraw;
  13. class Home extends Controller
  14. {
  15. public function index()
  16. {
  17. try {
  18. request()->validate([
  19. 'start_date' => ['nullable', 'date_format:Y-m-d'],
  20. 'end_date' => ['nullable', 'date_format:Y-m-d', 'after_or_equal:start_date'],
  21. ]);
  22. $start = request()->input('start_date');
  23. $end = request()->input('end_date');
  24. if (empty($end)) $end = date('Y-m-d');
  25. if (empty($start)) $start = date('Y-m-d');
  26. $end = Carbon::createFromFormat('Y-m-d', $end)->addDay()->format('Y-m-d');
  27. $today = date('Y-m-d');
  28. //投注统计
  29. $query = BalanceLog::query();
  30. $query->where('type', 1)->where('change_type', 'like', '%投注');
  31. $query1 = clone $query;
  32. $bet['amount'] = (float)$query1->whereBetween('created_at', [$start, $end])->sum('amount');//投注金额
  33. $bet['amount'] = abs($bet['amount']);
  34. $query1 = clone $query;
  35. $bet['today_amount'] = (float)$query1->whereBetween('created_at', [$today, $end])->sum('amount');//今日投注金额
  36. $bet['today_amount'] = abs($bet['today_amount']);
  37. //投注退款统计
  38. $query = BalanceLog::query();
  39. $query->where('type', 1)->where('change_type', 'like', '%退款');
  40. $query1 = clone $query;
  41. $bet['refund_amount'] = (float)$query1->whereBetween('created_at', [$start, $end])->sum('amount');//投注退款金额
  42. $query1 = clone $query;
  43. $bet['today_refund_amount'] = (float)$query1->whereBetween('created_at', [$today, $end])->sum('amount');//今日投注退款金额
  44. //投注中奖统计
  45. $query = BalanceLog::query();
  46. $query->where('type', 1)->where('change_type', 'like', '%中奖');
  47. $query1 = clone $query;
  48. $bet['win_amount'] = (float)$query1->whereBetween('created_at', [$start, $end])->sum('amount');//投注中奖金额
  49. $query1 = clone $query;
  50. $bet['today_win_amount'] = (float)$query1->whereBetween('created_at', [$today, $end])->sum('amount');//今日投注中奖金额
  51. //余额宝统计
  52. $query = BalanceLog::query();
  53. $yuebao['in_amount'] = (float)$query->where('change_type', '余额宝转入')->whereBetween('created_at', [$start, $end])->sum('amount');//余额宝转入金额
  54. $yuebao['in_amount'] = abs($yuebao['in_amount']);
  55. $yuebao['today_in_amount'] = (float)$query->where('change_type', '余额宝转入')->whereBetween('created_at', [$today, $end])->sum('amount');//今日余额宝转入金额
  56. $yuebao['today_in_amount'] = abs($yuebao['today_in_amount']);
  57. $yuebao['out_amount'] = (float)$query->where('change_type', '余额宝转出')->whereBetween('created_at', [$start, $end])->sum('amount');//余额宝转出金额
  58. $yuebao['out_amount'] = abs($yuebao['out_amount']);
  59. $yuebao['today_out_amount'] = (float)$query->where('change_type', '余额宝转出')->whereBetween('created_at', [$today, $end])->sum('amount');//今日余额宝转出金额
  60. $yuebao['today_out_amount'] = abs($yuebao['today_out_amount']);
  61. $yuebao['interest_amount'] = (float)$query->where('change_type', '余额宝利息')->whereBetween('created_at', [$start, $end])->sum('amount');//余额宝利息
  62. $yuebao['today_interest_amount'] = (float)$query->where('change_type', '余额宝利息')->whereBetween('created_at', [$today, $end])->sum('amount');//今日余额宝利息
  63. //老用户回归返彩金额
  64. $activity['user_return'] = (float)$query->where('change_type', '老用户回归')->whereBetween('created_at', [$start, $end])->sum('amount');//老用户回归返彩金额
  65. $activity['today_user_return'] = (float)$query->where('change_type', '老用户回归')->whereBetween('created_at', [$today, $end])->sum('amount');//今日老用户回归返彩金额
  66. //即充即送返彩金额
  67. $activity['recharge_frozen'] = (float)$query->where('change_type', '即充即送')->whereBetween('created_at', [$start, $end])->sum('amount');//即充即送返彩金额
  68. $activity['today_recharge_frozen'] = (float)$query->where('change_type', '即充即送')->whereBetween('created_at', [$today, $end])->sum('amount');//今日即充即送返彩金额
  69. //充值返现金额
  70. $activity['recharge_amount'] = (float)$query->where('change_type', '充值返现')->whereBetween('created_at', [$start, $end])->sum('amount');//充值返现金额
  71. $activity['today_recharge_amount'] = (float)$query->where('change_type', '充值返现')->whereBetween('created_at', [$today, $end])->sum('amount');//今日充值返现金额
  72. //流水解冻金额
  73. $activity['unfreeze_amount'] = (float)$query->where('change_type', '流水解冻')->whereBetween('created_at', [$start, $end])->sum('amount');//流水解冻金额
  74. $activity['unfreeze_amount'] = abs($activity['unfreeze_amount']);
  75. $activity['today_unfreeze_amount'] = (float)$query->where('change_type', '流水解冻')->whereBetween('created_at', [$today, $end])->sum('amount');//今日流水解冻金额
  76. $activity['today_unfreeze_amount'] = abs($activity['today_unfreeze_amount']);
  77. //新增会员统计
  78. $query = User::where('from','<>',2);
  79. $totalUser = (float)$query->whereBetween('created_at', [$start, $end])->count('id');
  80. $todayUser = (float)$query->whereBetween('created_at', [$today, $end])->count('id');//今日新增会员
  81. //第三方提现统计(RMB)
  82. $query = PaymentOrder::query();
  83. $query->whereBetween('created_at', [$start, $end]);
  84. $query1 = clone $query;
  85. $totalAmount = (float)$query1->where('type', 2)->sum('amount');
  86. $query1 = clone $query;
  87. $totalPending = (float)$query1->where('type', 2)->where('status', 0)->sum('amount');//待处理
  88. $query1 = clone $query;
  89. $totalProcessing = (float)$query1->where('type', 2)->where('status', 1)->sum('amount');//处理中
  90. $query1 = clone $query;
  91. $totalSuccess = (float)$query1->where('type', 2)->where('status', 2)->sum('amount');//成功
  92. $query1 = clone $query;
  93. $totalFail = (float)$query1->where('type', 2)->where('status', 3)->sum('amount'); // 失败
  94. //第三方提现统计(RMB)今日
  95. $query = PaymentOrder::query();
  96. $query->whereBetween('created_at', [$today, $end]);
  97. $query1 = clone $query;
  98. $todayAmount = (float)$query1->where('type', 2)->sum('amount');
  99. $query1 = clone $query;
  100. $todayPending = (float)$query1->where('type', 2)->where('status', 0)->sum('amount');//待处理
  101. $query1 = clone $query;
  102. $todayProcessing = (float)$query1->where('type', 2)->where('status', 1)->sum('amount');//处理中
  103. $query1 = clone $query;
  104. $todaySuccess = (float)$query1->where('type', 2)->where('status', 2)->sum('amount');//成功
  105. $query1 = clone $query;
  106. $todayFail = (float)$query1->where('type', 2)->where('status', 3)->sum('amount'); // 失败
  107. //第三方充值统计(RMB)
  108. $query1 = clone $query;
  109. $rechargeRmbTotalAmount = (float)$query1->where('type', 1)->sum('amount');//总金额
  110. $query1 = clone $query;
  111. $rechargeRmbTotalPending = (float)$query1->where('type', 1)->where('status', 0)->sum('amount');//待处理
  112. $query1 = clone $query;
  113. $rechargeRmbTotalProcessing = (float)$query1->where('type', 1)->where('status', 1)->sum('amount');//处理中
  114. $query1 = clone $query;
  115. $rechargeRmbTotalSuccess = (float)$query1->where('type', 1)->where('status', 2)->sum('amount');//成功
  116. $query1 = clone $query;
  117. $rechargeRmbTotalFail = (float)$query1->where('type', 1)->where('status', 3)->sum('amount');//失败
  118. //第三方充值统计(RMB)今日
  119. $query1 = clone $query;
  120. $rechargeRmbTodayAmount = (float)$query1->where('type', 1)->sum('amount');//总金额
  121. $query1 = clone $query;
  122. $rechargeRmbTodayPending = (float)$query1->where('type', 1)->where('status', 0)->sum('amount');//待处理
  123. $query1 = clone $query;
  124. $rechargeRmbTodayProcessing = (float)$query1->where('type', 1)->where('status', 1)->sum('amount');//处理中
  125. $query1 = clone $query;
  126. $rechargeRmbTodaySuccess = (float)$query1->where('type', 1)->where('status', 2)->sum('amount');//成功
  127. $query1 = clone $query;
  128. $rechargeRmbTodayFail = (float)$query1->where('type', 1)->where('status', 3)->sum('amount');//失败
  129. //USDT提现统计
  130. $query = Withdraw::query();
  131. $query->whereBetween('created_at', [$start, $end]);
  132. $query1 = clone $query;
  133. $usdTotalAmount = (float)$query1->sum('amount');//总金额
  134. $query1 = clone $query;
  135. $usdTotalSuccess = (float)$query1->where('status', 1)->sum('amount');//成功
  136. $query1 = clone $query;
  137. $usdTotalFail = (float)$query1->where('status', 2)->sum('amount');//失败
  138. //USDT提现统计(今日)
  139. $query = Withdraw::query();
  140. $query->whereBetween('created_at', [$today, $end]);
  141. $query1 = clone $query;
  142. $usdTodayAmount = (float)$query1->sum('amount');//总金额
  143. $query1 = clone $query;
  144. $usdTodaySuccess = (float)$query1->where('status', 1)->sum('amount');//成功
  145. $query1 = clone $query;
  146. $usdTodayFail = (float)$query1->where('status', 2)->sum('amount');//失败
  147. //USDT提现统计(今日)
  148. $query = Withdraw::query();
  149. $query->whereBetween('created_at', [$today, $end]);
  150. $query1 = clone $query;
  151. $usdTodayAmount = (float)$query1->sum('amount');//总金额
  152. $query1 = clone $query;
  153. $usdTodaySuccess = (float)$query1->where('status', 1)->sum('amount');//成功
  154. $query1 = clone $query;
  155. $usdTodayFail = (float)$query1->where('status', 2)->sum('amount');//失败
  156. //USDT充值统计
  157. $query = Recharge::query();
  158. $query->whereBetween('created_at', [$start, $end]);
  159. $query1 = clone $query;
  160. $rechargeTotalAmount = (float)$query1->sum('amount');//总充值
  161. $query1 = clone $query;
  162. $rechargeTotalSuccess = (float)$query1->where('status', 1)->sum('amount');//成功
  163. $query1 = clone $query;
  164. $rechargeTotalFail = (float)$query1->where('status', 2)->sum('amount');//失败
  165. //USDT充值(今日)
  166. $query = Recharge::query();
  167. $query->whereBetween('created_at', [$today, $end]);
  168. $query1 = clone $query;
  169. $rechargeTodayAmount = (float)$query1->sum('amount');//总充值
  170. $query1 = clone $query;
  171. $rechargeTodaySuccess = (float)$query1->where('status', 1)->sum('amount');//成功
  172. $query1 = clone $query;
  173. $rechargeTodayFail = (float)$query1->where('status', 2)->sum('amount');//失败
  174. $result = [
  175. 'start' => $start,
  176. 'end' => $end,
  177. 'bet' => $bet,//投注相关的
  178. 'activity' => $activity,//活动相关的
  179. 'yuebao' => $yuebao,//余额宝相关的
  180. 'recharge_usd' => [
  181. 'total_amount' => $rechargeTotalAmount,
  182. 'total_success' => $rechargeTotalSuccess,
  183. 'total_fail' => $rechargeTotalFail,
  184. 'today_amount' => $rechargeTodayAmount,
  185. 'today_success' => $rechargeTodaySuccess,
  186. 'today_fail' => $rechargeTodayFail,
  187. ],
  188. 'recharge_rmb' => [
  189. 'total_amount' => $rechargeRmbTotalAmount,
  190. 'total_success' => $rechargeRmbTotalSuccess,
  191. 'total_fail' => $rechargeRmbTotalFail,
  192. 'total_processing' => $rechargeRmbTotalProcessing,
  193. 'total_pending' => $rechargeRmbTotalPending,
  194. 'today_amount' => $rechargeRmbTodayAmount,
  195. 'today_success' => $rechargeRmbTodaySuccess,
  196. 'today_fail' => $rechargeRmbTodayFail,
  197. 'today_processing' => $rechargeRmbTodayProcessing,
  198. 'today_pending' => $rechargeRmbTodayPending,
  199. ],
  200. 'withdraw_usdt' => [
  201. 'total_fail' => $usdTotalFail,
  202. 'total_success' => $usdTotalSuccess,
  203. 'total_amount' => $usdTotalAmount,
  204. 'today_amount' => $usdTodayAmount,
  205. 'today_success' => $usdTodaySuccess,
  206. 'today_fail' => $usdTodayFail,
  207. ],
  208. 'withdraw_rmb' => [
  209. 'total_fail' => $totalFail,
  210. 'total_success' => $totalSuccess,
  211. 'total_amount' => $totalAmount,
  212. 'total_processing' => $totalProcessing,
  213. 'total_pending' => $totalPending,
  214. 'today_amount' => $todayAmount,
  215. 'today_success' => $todaySuccess,
  216. 'today_fail' => $todayFail,
  217. 'today_processing' => $todayProcessing,
  218. 'today_pending' => $todayPending,
  219. ],
  220. 'total_user' => $totalUser,
  221. 'today_user' => $todayUser,
  222. ];
  223. } catch (ValidationException $e) {
  224. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  225. } catch (Exception $e) {
  226. return $this->error($e->getCode(), $e->getmessage());
  227. }
  228. return $this->success($result);
  229. }
  230. }