Browse Source

事务顺序

rkljw 2 days ago
parent
commit
5a98bf0a0a
1 changed files with 4 additions and 3 deletions
  1. 4 3
      app/JsonRpc/NewsService.php

+ 4 - 3
app/JsonRpc/NewsService.php

@@ -287,13 +287,14 @@ class NewsService implements NewsServiceInterface
       $result = Category::where($data)->delete();
       WebsiteCategory::where(['category_id' => $data['id']])->delete();
       if (!$result) {
-        return Result::error("删除失败");
+          Db::rollBack();
+         return Result::error("删除失败");
       }
-      return Result::success($result);
       Db::commit();
+      return Result::success($result);
     } catch (\Exception $e) {
       Db::rollBack();
-      return Result::error("删除失败");
+      return Result::error("删除失败".$e->getMessage());
     }
   }