Răsfoiți Sursa

取消预订单

shish 2 ani în urmă
părinte
comite
1f18c7e744
1 a modificat fișierele cu 41 adăugiri și 0 ștergeri
  1. 41 0
      app-ghs/controllers/OrderController.php

+ 41 - 0
app-ghs/controllers/OrderController.php

@@ -1200,6 +1200,47 @@ class OrderController extends BaseController
         }
     }
 
+    //取消预订单 ssh 20240503
+    public function actionCancelBookOrder()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('请选择订单');
+        }
+        $order = OrderClass::getById($id, true);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        OrderClass::valid($order, $this->shopId);
+        if ($order->book == 0) {
+            util::fail('不是预订单');
+        }
+        if ($order->status != 2) {
+            util::fail('当前订单状态不能取消');
+        }
+        $purchaseId = $order->purchaseId ?? 0;
+        $purchase = PurchaseClass::getById($purchaseId);
+        if (empty($purchase)) {
+            util::fail('没有找到采购单');
+        }
+
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $order->status = 5;
+            $order->save();
+            $purchase->status = 5;
+            $purchase->save();
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            $msg = $e->getMessage();
+            $orderSn = $order->orderSn ?? '';
+            noticeUtil::push("预订单{$orderSn}取消失败:{$msg}", '15280215347');
+        }
+    }
+
     //取消订单 shizhongqi 20220619
     public function actionCancelOrder()
     {