Home.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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\Services\PaymentOrderService;
  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. //新增会员统计
  28. $query = User::query();
  29. $query->where('from','<>',2)->whereBetween('created_at', [$start, $end]);
  30. $totalUser = (float)$query->count('id');
  31. $query = PaymentOrder::query();
  32. $query->whereBetween('created_at', [$start, $end]);
  33. $query1 = clone $query;
  34. $totalAmount = (float)$query1->where('type', 2)->sum('amount');
  35. $query1 = clone $query;
  36. $totalPending = (float)$query1->where('type', 2)->where('status', 0)->sum('amount');
  37. $query1 = clone $query;
  38. $totalProcessing = (float)$query1->where('type', 2)->where('status', 1)->sum('amount');
  39. $query1 = clone $query;
  40. $totalSuccess = (float)$query1->where('type', 2)->where('status', 2)->sum('amount');
  41. $query1 = clone $query;
  42. $totalFail = (float)$query1->where('type', 2)->where('status', 3)->sum('amount');
  43. $query1 = clone $query;
  44. $rechargeRmbTotalAmount = (float)$query1->where('type', 1)->sum('amount');
  45. $query1 = clone $query;
  46. $rechargeRmbTotalPending = (float)$query1->where('type', 1)->where('status', 0)->sum('amount');
  47. $query1 = clone $query;
  48. $rechargeRmbTotalProcessing = (float)$query1->where('type', 1)->where('status', 1)->sum('amount');
  49. $query1 = clone $query;
  50. $rechargeRmbTotalSuccess = (float)$query1->where('type', 1)->where('status', 2)->sum('amount');
  51. $query1 = clone $query;
  52. $rechargeRmbTotalFail = (float)$query1->where('type', 1)->where('status', 3)->sum('amount');
  53. $query = Withdraw::query();
  54. $query->whereBetween('created_at', [$start, $end]);
  55. $query1 = clone $query;
  56. $usdTotalAmount = (float)$query1->sum('amount');
  57. $query1 = clone $query;
  58. $usdTotalSuccess = (float)$query1->where('status', 1)->sum('amount');
  59. $query1 = clone $query;
  60. $usdTotalFail = (float)$query1->where('status', 2)->sum('amount');
  61. $query = Recharge::query();
  62. $query->whereBetween('created_at', [$start, $end]);
  63. $query1 = clone $query;
  64. $rechargeTotalAmount = (float)$query1->sum('amount');
  65. $query1 = clone $query;
  66. $rechargeTotalSuccess = (float)$query1->where('status', 1)->sum('amount');
  67. $query1 = clone $query;
  68. $rechargeTotalFail = (float)$query1->where('status', 2)->sum('amount');
  69. $result = [
  70. 'start' => $start,
  71. 'end' => $end,
  72. 'recharge_usd' => [
  73. 'total_amount' => $rechargeTotalAmount,
  74. 'total_success' => $rechargeTotalSuccess,
  75. 'total_fail' => $rechargeTotalFail,
  76. ],
  77. 'recharge_rmb' => [
  78. 'total_amount' => $rechargeRmbTotalAmount,
  79. 'total_success' => $rechargeRmbTotalSuccess,
  80. 'total_fail' => $rechargeRmbTotalFail,
  81. 'total_processing' => $rechargeRmbTotalProcessing,
  82. 'total_pending' => $rechargeRmbTotalPending
  83. ],
  84. 'withdraw_usdt' => [
  85. 'total_fail' => $usdTotalFail,
  86. 'total_success' => $usdTotalSuccess,
  87. 'total_amount' => $usdTotalAmount,
  88. ],
  89. 'withdraw_rmb' => [
  90. 'total_fail' => $totalFail,
  91. 'total_success' => $totalSuccess,
  92. 'total_amount' => $totalAmount,
  93. 'total_processing' => $totalProcessing,
  94. 'total_pending' => $totalPending
  95. ],
  96. 'total_user' => $totalUser,
  97. ];
  98. } catch (ValidationException $e) {
  99. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  100. } catch (Exception $e) {
  101. return $this->error($e->getCode(), $e->getmessage());
  102. }
  103. return $this->success($result);
  104. }
  105. }