| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Models\PaymentOrder;
- use App\Services\PaymentOrderService;
- use Illuminate\Validation\ValidationException;
- use Exception;
- use Carbon\Carbon;
- 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', date('Y-m-d'));
- $start = Carbon::createFromFormat('Y-m-d', $start);
- $end = request()->input('end_date', date('Y-m-d'));
- // $end = Carbon::createFromFormat('Y-m-d', $end)->addDay();
- $query = PaymentOrder::query();
- $params['type'] = 2;
- $where = PaymentOrderService::getWhere($params);
- $totalAmount = (float)$query->where($where)->whereBetween('created_at', [$start, $end])->sum('amount');
- $totalSuccess = (float)$query->where($where)->whereBetween('created_at', [$start, $end])->whereIn('status', [1, 2])->sum('amount');
- $totalFail = (float)$query->where($where)->whereBetween('created_at', [$start, $end])->where('status', 3)->sum('amount');
- $result = [
- '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);
- }
- }
|