|
...
|
...
|
@@ -34,7 +34,6 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
$this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']);
|
|
|
|
$route = $this->param['alias'];
|
|
|
|
$this->editHandleCategory($this->param['id'],$this->param['pid']);
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$this->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
}else{
|
|
...
|
...
|
@@ -47,8 +46,6 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
$route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
|
|
|
|
$this->edit(['alias'=>$route],['id'=>$id]);
|
|
|
|
//处理子集
|
|
|
|
$this->addProcessingSon($id);
|
|
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
...
|
...
|
@@ -61,48 +58,6 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑分类,处理博客数据
|
|
|
|
* @name :editCategory
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/20 9:32
|
|
|
|
*/
|
|
|
|
public function editHandleCategory($id,$pid){
|
|
|
|
$info = $this->model->read(['id'=>$id],['id','pid']);
|
|
|
|
if($info['pid'] != $pid){
|
|
|
|
//修改勒上级,先查看上级是否拥有博客
|
|
|
|
$blogModel = new BlogModel();
|
|
|
|
$blogCount = $blogModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
|
|
|
|
if($blogCount > 0){
|
|
|
|
//随机获取最后一级id
|
|
|
|
$replacement = $this->getLastId($id);
|
|
|
|
//存在博客时,移动所有博客到当前分类最后一级
|
|
|
|
$blogModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
|
|
|
|
$blogModel->where('category_id', 'like', '%,' . $pid . ',%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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($info['id']);
|
|
|
|
}else{
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :详情
|
|
|
|
* @return array
|
|
|
|
* @author :liyuhang
|
|
...
|
...
|
@@ -122,7 +77,7 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
public function status_blog_category(){
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
if($rs === false){
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
...
|
...
|
@@ -248,37 +203,6 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $cate_id
|
|
|
|
* @name :(处理子集)addProcessingSon
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/13 11:59
|
|
|
|
*/
|
|
|
|
public function addProcessingSon($cate_id){
|
|
|
|
if(!isset($this->param['pid'])){
|
|
|
|
$this->param['pid'] = 0;
|
|
|
|
}
|
|
|
|
//判断为子分类时
|
|
|
|
if($this->param['pid'] != 0){
|
|
|
|
//查看当前上级分类下是否有其他子分类
|
|
|
|
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
|
|
|
|
if ($cate_info === false) {
|
|
|
|
//查看当前上一级分类下是否有新闻
|
|
|
|
$blogModel = new BlogModel();
|
|
|
|
$blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
|
|
|
if ($blog_count > 0) {
|
|
|
|
$replacement = ',' . $cate_id . ',';
|
|
|
|
$old = ',' . $this->param['pid'] . ',';
|
|
|
|
//更新所有商品到当前分类
|
|
|
|
$blogModel->where('category_id', 'like', '%' . $old . '%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :删除路由
|
|
|
|
* @name :delRoute
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -322,7 +246,7 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
$pid = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->getLastCategory($return);
|
|
|
|
return $this->getCategory($return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -332,15 +256,12 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/20 9:02
|
|
|
|
*/
|
|
|
|
public function getLastCategory($category){
|
|
|
|
public function getCategory($category){
|
|
|
|
$str = '';
|
|
|
|
foreach ($category as $v){
|
|
|
|
$info = $this->model->read(['pid'=>$v]);
|
|
|
|
if($info === false){
|
|
|
|
$str .= $v.',';
|
|
|
|
}
|
|
|
|
$str .= $v.',';
|
|
|
|
}
|
|
|
|
return ','.$str;
|
|
|
|
return !empty($str) ? ','.$str : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|