| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?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;
- 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', date('Y-m-d'));
- $end = request()->input('end_date', date('Y-m-d'));
- $end = Carbon::createFromFormat('Y-m-d', $end)->addDay()->format('Y-m-d');
- $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');
- $query = Withdraw::query();
- $usdTotalAmount = (float)$query->whereBetween('created_at', [$start, $end])->sum('amount');
- $usdTotalSuccess = (float)$query->whereBetween('created_at', [$start, $end])->where('status', 1)->sum('amount');
- $usdTotalFail = (float)$query->whereBetween('created_at', [$start, $end])->where('status', 2)
- ->sum('amount');
- $sql = $query->whereBetween('created_at', [$start, $end])->where('status', 2)->toSql();
- $bindings = $query->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);
- }
- }
|