Ken vor 1 Woche
Ursprung
Commit
bd2cef0529
2 geänderte Dateien mit 53 neuen und 11 gelöschten Zeilen
  1. 49 0
      app/Http/Controllers/admin/Home.php
  2. 4 11
      app/Http/Controllers/admin/Withdraw.php

+ 49 - 0
app/Http/Controllers/admin/Home.php

@@ -0,0 +1,49 @@
+<?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;
+
+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:start_date'],
+            ]);
+            $start = request()->input('start_date', date('Y-m-d'));
+            $end = request()->input('end_date', date('Y-m-d'));
+            $query = PaymentOrder::query();
+            $params['type'] = 2;
+            $where = PaymentOrderService::getWhere($params);
+
+            $totalAmount = (float)$query->where($where)
+                ->whereDate('created_at', date('Y-m-d'))->sum('amount');
+            $totalSuccess = (float)$query->where($where)->whereDate('created_at', date('Y-m-d'))
+                ->whereIn('status', [1, 2])->sum('amount');
+            $totalFail = (float)$query->where($where)->whereDate('created_at', date('Y-m-d'))
+                ->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);
+    }
+}

+ 4 - 11
app/Http/Controllers/admin/Withdraw.php

@@ -59,25 +59,18 @@ class Withdraw extends Controller
                 ->orderByDesc('created_at')
                 ->forpage($page, $limit)->get();
 
-            $totalAmount = (float)$query->where($where)
-                ->whereDate('created_at', date('Y-m-d'))->sum('amount');
-            $totalSuccess = (float)$query->where($where)->whereDate('created_at', date('Y-m-d'))
-                ->whereIn('status', [1, 2])->sum('amount');
-            $totalFail = (float)$query->where($where)->whereDate('created_at', date('Y-m-d'))
-                ->where('status', 3)->sum('amount');
-
 
             $result = [
-                'total_fail' => $totalFail,
-                'total_success' => $totalSuccess,
-                'total_amount' => $totalAmount,
+//                'total_fail' => $totalFail,
+//                'total_success' => $totalSuccess,
+//                'total_amount' => $totalAmount,
                 'total' => $count,
                 'data' => $list
             ];
         } catch (ValidationException $e) {
             return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
         } catch (Exception $e) {
-            return $this->error(intval($e->getCode()));
+            return $this->error($e->getCode(), $e->getmessage());
         }
         return $this->success($result);
     }