Jelajahi Sumber

删除问题

shish 5 tahun lalu
induk
melakukan
16a4a3592e
1 mengubah file dengan 25 tambahan dan 18 penghapusan
  1. 25 18
      app-pt/controllers/ShopAdminController.php

+ 25 - 18
app-pt/controllers/ShopAdminController.php

@@ -33,25 +33,32 @@ class ShopAdminController extends BaseController
         if (getenv('YII_ENV', 'local') == 'production') {
             util::fail('生产环境不能执行删除操作');
         }
-        $adminId = $shopAdmin['adminId'] ?? 0;
-        $sjId = $shopAdmin['merchantId'] ?? 0;
-        $sj = SjClass::getById($sjId, true);
-        if (!empty($sj)) {
-            $sj->delete();
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $adminId = $shopAdmin['adminId'] ?? 0;
+            $sjId = $shopAdmin['merchantId'] ?? 0;
+            $sj = SjClass::getById($sjId, true);
+            if (!empty($sj)) {
+                $sj->delete();
+            }
+            $apply = ApplyClass::getByCondition(['sjId' => $sjId], true);
+            if (!empty($apply)) {
+                $apply->delete();
+            }
+            $admin = AdminClass::getById($adminId, true);
+            if (!empty($admin)) {
+                $admin->delete();
+            }
+            $shopAdmin = ShopAdminClass::getById($id, true);
+            if (!empty($shopAdmin)) {
+                $shopAdmin->delete();
+            }
+            util::complete();
+        } catch (Exception $exception) {
+            $transaction->rollBack();
+            util::fail("删除失败");
         }
-        $apply = ApplyClass::getByCondition(['sjId' => $sjId], true);
-        if (!empty($apply)) {
-            $apply->delete();
-        }
-        $admin = AdminClass::getById($adminId);
-        if (!empty($admin)) {
-            $admin->delete();
-        }
-        $shopAdmin = ShopAdminClass::getById($id);
-        if (!empty($shopAdmin)) {
-            $shopAdmin->delete();
-        }
-        util::complete();
     }
 
 }