| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Models\PaymentOrder;
- use App\Models\Recharge;
- use App\Services\PaymentOrderService;
- use Illuminate\Validation\ValidationException;
- use Exception;
- use Carbon\Carbon;
- use App\Models\Withdraw;
- class Home extends Controller
- {
- public function index()
- {
- try {
- request()->validate([
- 'start_date' => ['nullable', 'date_format:Y-m-d'],
- 'end_date' => ['nullable', 'date_format:Y-m-d', 'after_or_equal:start_date'],
- ]);
- $start = request()->input('start_date');
- $end = request()->input('end_date');
- if (empty($end)) $end = date('Y-m-d');
- if (empty($start)) $start = date('Y-m-d');
- $end = Carbon::createFromFormat('Y-m-d', $end)->addDay()->format('Y-m-d');
- $query = PaymentOrder::query();
- $query->whereBetween('created_at', [$start, $end]);
- $query1 = clone $query;
- $totalAmount = (float)$query1->where('type', 2)->sum('amount');
- $query1 = clone $query;
- $totalSuccess = (float)$query1->where('type', 2)->whereIn('status', [1, 2])->sum('amount');
- $query1 = clone $query;
- $totalFail = (float)$query1->where('type', 2)->where('status', 3)->sum('amount');
- $query1 = clone $query;
- $rechargeRmbTotalAmount = (float)$query1->where('type', 1)->sum('amount');
- $query1 = clone $query;
- $rechargeRmbTotalSuccess = (float)$query1->where('type', 1)->whereIn('status', [1, 2])->sum('amount');
- $query1 = clone $query;
- $rechargeRmbTotalFail = (float)$query1->where('type', 1)->where('status', 3)->sum('amount');
- $query = Withdraw::query();
- $query->whereBetween('created_at', [$start, $end]);
- $query1 = clone $query;
- $usdTotalAmount = (float)$query1->sum('amount');
- $query1 = clone $query;
- $usdTotalSuccess = (float)$query1->where('status', 1)->sum('amount');
- $query1 = clone $query;
- $usdTotalFail = (float)$query1->where('status', 2)->sum('amount');
- $query = Recharge::query();
- $query->whereBetween('created_at', [$start, $end]);
- $query1 = clone $query;
- $rechargeTotalAmount = (float)$query1->sum('amount');
- $query1 = clone $query;
- $rechargeTotalSuccess = (float)$query1->where('status', 1)->sum('amount');
- $query1 = clone $query;
- $rechargeTotalFail = (float)$query1->where('status', 2)->sum('amount');
- $result = [
- 'start' => $start,
- 'end' => $end,
- 'recharge_usd' => [
- 'total_amount' => $rechargeTotalAmount,
- 'total_success' => $rechargeTotalSuccess,
- 'total_fail' => $rechargeTotalFail,
- ],
- 'recharge_rmb' => [
- 'total_amount' => $rechargeRmbTotalAmount,
- 'total_success' => $rechargeRmbTotalSuccess,
- 'total_fail' => $rechargeRmbTotalFail,
- ],
- 'withdraw_usdt' => [
- 'total_fail' => $usdTotalFail,
- 'total_success' => $usdTotalSuccess,
- 'total_amount' => $usdTotalAmount,
- ],
- 'withdraw_rmb' => [
- 'total_fail' => $totalFail,
- 'total_success' => $totalSuccess,
- 'total_amount' => $totalAmount,
- ]
- ];
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error($e->getCode(), $e->getmessage());
- }
- return $this->success($result);
- }
- }
|