|
@@ -170,21 +170,30 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function delCategory(array $data): array
|
|
|
{
|
|
|
- $categoryList = Category::where(['pid' => $data['id']])->get();
|
|
|
- var_dump("分类列表:", $data, $categoryList);
|
|
|
- if ($categoryList->toArray()) {
|
|
|
- return Result::error("分类下面有子分类不能删除");
|
|
|
- }
|
|
|
- $articleList = Article::where(['catid' => $data['id']])->get();
|
|
|
- var_dump("文章列表:", $articleList);
|
|
|
- if ($articleList->toArray()) {
|
|
|
- return Result::error("分类下面有资讯不能删除");
|
|
|
- }
|
|
|
- $result = Category::where($data)->delete();
|
|
|
- if (!$result) {
|
|
|
+ Db::beginTransaction();
|
|
|
+ try {
|
|
|
+ $categoryList = Category::where(['pid' => $data['id']])->get();
|
|
|
+ if ($categoryList->toArray()) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error("分类下面有子分类不能删除");
|
|
|
+ }
|
|
|
+ $articleList = Article::where(['catid' => $data['id']])->get();
|
|
|
+ if ($articleList->toArray()) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error("分类下面有资讯不能删除");
|
|
|
+ }
|
|
|
+ $result = Category::where($data)->delete();
|
|
|
+ WebsiteCategory::where(['category_id' => $data['id']])->delete();
|
|
|
+ if (!$result) {
|
|
|
+ return Result::error("删除失败");
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ Db::commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Db::rollBack();
|
|
|
return Result::error("删除失败");
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|