作者 lyh

gx

@@ -66,15 +66,12 @@ class BlogCategoryLogic extends BaseLogic @@ -66,15 +66,12 @@ class BlogCategoryLogic extends BaseLogic
66 public function editHandleCategory($id,$pid){ 66 public function editHandleCategory($id,$pid){
67 $info = $this->model->read(['id'=>$id],['id','pid']); 67 $info = $this->model->read(['id'=>$id],['id','pid']);
68 if($info['pid'] != $pid){ 68 if($info['pid'] != $pid){
69 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export(1111111, true) . PHP_EOL, FILE_APPEND);  
70 //修改勒上级,先查看上级是否拥有博客 69 //修改勒上级,先查看上级是否拥有博客
71 $blogModel = new BlogModel(); 70 $blogModel = new BlogModel();
72 $blogCount = $blogModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count(); 71 $blogCount = $blogModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
73 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export(222222, true) . PHP_EOL, FILE_APPEND); 72 + if($blogCount > 0){
74 //随机获取最后一级id 73 //随机获取最后一级id
75 $replacement = $this->getLastId($id); 74 $replacement = $this->getLastId($id);
76 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export(33333, true) . PHP_EOL, FILE_APPEND);  
77 - if($blogCount > 0){  
78 //存在博客时,移动所有博客到当前分类最后一级 75 //存在博客时,移动所有博客到当前分类最后一级
79 $blogModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%') 76 $blogModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
80 ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]); 77 ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
@@ -114,6 +114,23 @@ class NewsCategoryLogic extends BaseLogic @@ -114,6 +114,23 @@ class NewsCategoryLogic extends BaseLogic
114 } 114 }
115 115
116 /** 116 /**
  117 + * @remark :随机获取当前id下最后一级的id
  118 + * @name :getLastId
  119 + * @author :lyh
  120 + * @method :post
  121 + * @time :2023/10/20 9:45
  122 + */
  123 + public function getLastId($id){
  124 + $info = $this->model->read(['pid'=>$id],['id']);
  125 + if($info == false){
  126 + return $this->getLastId($id);
  127 + }else{
  128 + return $id;
  129 + }
  130 +
  131 + }
  132 +
  133 + /**
117 * @remark :编辑路由时生成路由记录 134 * @remark :编辑路由时生成路由记录
118 * @name :editCategoryRoute 135 * @name :editCategoryRoute
119 * @author :lyh 136 * @author :lyh