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'); return $this->success($end); $end = Carbon::createFromFormat('Y-m-d', $end)->addDay()->format('Y-m-d'); $query = PaymentOrder::query(); $params['type'] = 2; $where = PaymentOrderService::getWhere($params); $query->where($where)->whereBetween('created_at', [$start, $end]); $query1 = clone $query; $totalAmount = (float)$query1->sum('amount'); $query1 = clone $query; $totalSuccess = (float)$query1->whereIn('status', [1, 2])->sum('amount'); $query1 = clone $query; $totalFail = (float)$query1->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'); $query1 = clone $query; $sql = $query1->where('status', 2)->toSql(); $bindings = $query1->getBindings(); // 将绑定的参数替换到 SQL 查询中 foreach ($bindings as $binding) { // 使用 ? 替换成绑定的值 $sql = preg_replace('/\?/', "'" . addslashes($binding) . "'", $sql, 1); } $result = [ 'withdraw_usdt' => [ 'total_fail' => $usdTotalFail, 'total_success' => $usdTotalSuccess, 'total_amount' => $usdTotalAmount, 'sql'=>$sql ], '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); } }