Browse Source

update: order manual

tokumeikoi 3 years ago
parent
commit
c95d374cc0

+ 32 - 38
app/Http/Controllers/Admin/OrderController.php

@@ -63,66 +63,60 @@ class OrderController extends Controller
         ]);
     }
 
-    public function update(OrderUpdate $request)
+    public function paid(Request $request)
     {
-        $params = $request->only([
-            'status',
-            'commission_status'
-        ]);
-
         $order = Order::where('trade_no', $request->input('trade_no'))
             ->first();
         if (!$order) {
             abort(500, '订单不存在');
         }
+        if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
 
-        if (isset($params['status'])) {
-            $orderService = new OrderService($order);
-            switch ((int)$params['status']) {
-                case 1: {
-                    if (!$orderService->success(time())) {
-                        abort(500, '更新失败');
-                    }
-                    break;
-                }
-                case 2: {
-                    if (!$orderService->cancel()) {
-                        abort(500, '更新失败');
-                    }
-                    break;
-                }
-            }
-            return response([
-                'data' => true
-            ]);
+        $orderService = new OrderService($order);
+        if (!$orderService->paid('manual_operation')) {
+            abort(500, '更新失败');
         }
+        return response([
+            'data' => true
+        ]);
+    }
 
-        try {
-            $order->update($params);
-        } catch (\Exception $e) {
-            abort(500, '更新失败');
+    public function cancel(Request $request)
+    {
+        $order = Order::where('trade_no', $request->input('trade_no'))
+            ->first();
+        if (!$order) {
+            abort(500, '订单不存在');
         }
+        if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
 
+        $orderService = new OrderService($order);
+        if (!$orderService->cancel()) {
+            abort(500, '更新失败');
+        }
         return response([
             'data' => true
         ]);
     }
 
-    public function repair(Request $request)
+    public function update(OrderUpdate $request)
     {
-        if (empty($request->input('trade_no'))) {
-            abort(500, '参数错误');
-        }
+        $params = $request->only([
+            'commission_status'
+        ]);
+
         $order = Order::where('trade_no', $request->input('trade_no'))
-            ->where('status', 0)
             ->first();
         if (!$order) {
-            abort(500, '订单不存在或订单已支付');
+            abort(500, '订单不存在');
         }
-        $order->status = 1;
-        if (!$order->save()) {
-            abort(500, '保存失败');
+
+        try {
+            $order->update($params);
+        } catch (\Exception $e) {
+            abort(500, '更新失败');
         }
+
         return response([
             'data' => true
         ]);

+ 1 - 1
app/Http/Controllers/Guest/PaymentController.php

@@ -34,7 +34,7 @@ class PaymentController extends Controller
         }
         if ($order->status === 1) return true;
         $orderService = new OrderService($order);
-        if (!$orderService->success($callbackNo)) {
+        if (!$orderService->paid($callbackNo)) {
             return false;
         }
         $telegramService = new TelegramService();

+ 2 - 1
app/Http/Routes/AdminRoute.php

@@ -63,9 +63,10 @@ class AdminRoute
             });
             // Order
             $router->get ('/order/fetch', 'Admin\\OrderController@fetch');
-            $router->post('/order/repair', 'Admin\\OrderController@repair');
             $router->post('/order/update', 'Admin\\OrderController@update');
             $router->post('/order/assign', 'Admin\\OrderController@assign');
+            $router->post('/order/paid', 'Admin\\OrderController@paid');
+            $router->post('/order/cancel', 'Admin\\OrderController@cancel');
             // User
             $router->get ('/user/fetch', 'Admin\\UserController@fetch');
             $router->post('/user/update', 'Admin\\UserController@update');

+ 21 - 23
app/Services/OrderService.php

@@ -81,25 +81,6 @@ class OrderService
         DB::commit();
     }
 
-    public function cancel():bool
-    {
-        $order = $this->order;
-        DB::beginTransaction();
-        $order->status = 2;
-        if (!$order->save()) {
-            DB::rollBack();
-            return false;
-        }
-        if ($order->balance_amount) {
-            $userService = new UserService();
-            if (!$userService->addBalance($order->user_id, $order->balance_amount)) {
-                DB::rollBack();
-                return false;
-            }
-        }
-        DB::commit();
-        return true;
-    }
 
     public function setOrderType(User $user)
     {
@@ -232,18 +213,35 @@ class OrderService
         $order->surplus_order_ids = array_column($orders->toArray(), 'id');
     }
 
-    public function success(string $callbackNo)
+    public function paid(string $callbackNo)
     {
         $order = $this->order;
-        if ($order->status !== 0) {
-            return true;
-        }
+        if ($order->status !== 0) return true;
         $order->status = 1;
         $order->paid_at = time();
         $order->callback_no = $callbackNo;
         return $order->save();
     }
 
+    public function cancel():bool
+    {
+        $order = $this->order;
+        DB::beginTransaction();
+        $order->status = 2;
+        if (!$order->save()) {
+            DB::rollBack();
+            return false;
+        }
+        if ($order->balance_amount) {
+            $userService = new UserService();
+            if (!$userService->addBalance($order->user_id, $order->balance_amount)) {
+                DB::rollBack();
+                return false;
+            }
+        }
+        DB::commit();
+        return true;
+    }
 
     private function buyByResetTraffic()
     {

File diff suppressed because it is too large
+ 0 - 0
public/assets/admin/umi.js


Some files were not shown because too many files changed in this diff