作者 lyh

gx

... ... @@ -66,15 +66,12 @@ class BlogCategoryLogic extends BaseLogic
public function editHandleCategory($id,$pid){
$info = $this->model->read(['id'=>$id],['id','pid']);
if($info['pid'] != $pid){
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(1111111, true) . PHP_EOL, FILE_APPEND);
//修改勒上级,先查看上级是否拥有博客
$blogModel = new BlogModel();
$blogCount = $blogModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(222222, true) . PHP_EOL, FILE_APPEND);
if($blogCount > 0){
//随机获取最后一级id
$replacement = $this->getLastId($id);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(33333, true) . PHP_EOL, FILE_APPEND);
if($blogCount > 0){
//存在博客时,移动所有博客到当前分类最后一级
$blogModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
... ...
... ... @@ -114,6 +114,23 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @remark :随机获取当前id下最后一级的id
* @name :getLastId
* @author :lyh
* @method :post
* @time :2023/10/20 9:45
*/
public function getLastId($id){
$info = $this->model->read(['pid'=>$id],['id']);
if($info == false){
return $this->getLastId($id);
}else{
return $id;
}
}
/**
* @remark :编辑路由时生成路由记录
* @name :editCategoryRoute
* @author :lyh
... ...