Просмотр исходного кода

师傅商城增加取消订单接口

林海涛 1 год назад
Родитель
Сommit
4b19015c3a

+ 15 - 0
app/workerapi/controller/shops/OrderController.php

@@ -27,4 +27,19 @@ class OrderController extends BaseApiController
         }
         return $this->data($result);
     }
+
+    /**
+     * 取消订单
+     */
+    public function cancelOrder()
+    {
+        $params = (new ShopOrderValidate())->goCheck('detail',[
+            'worker_id' => $this->userId,
+        ]);
+        $result = ShopOrderLogic::cancelOrder($params);
+        if (false === $result) {
+            return $this->fail(ShopOrderLogic::getError());
+        }
+        return $this->success('取消成功', [], 1, 1);
+    }
 }

+ 24 - 0
app/workerapi/logic/shops/ShopOrderLogic.php

@@ -40,4 +40,28 @@ class ShopOrderLogic extends BaseLogic
         }
         return $detail;
     }
+
+
+    public static function cancelOrder($params):bool
+    {
+        Db::startTrans();
+        try {
+            $orderModel =  ShopOrders::where([
+                'shop_order_type' => 1,
+                'worker_id' => $params['worker_id'],
+                'sn'=>$params['sn']
+            ])->findOrEmpty();
+            if($orderModel->isEmpty()){
+                throw new Exception('订单不存在或不是待支付状态');
+            }
+            $orderModel->shop_order_type = 0;
+            $orderModel->save();
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 }