|
...
|
...
|
@@ -28,17 +28,11 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
public function categorySave(){
|
|
|
|
//验证名称是否存在
|
|
|
|
$this->verifyParamName($this->param['name']);
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])) {
|
|
|
|
//验证参数是否可编辑
|
|
|
|
$this->verifyParamEdit($this->param['id'], $this->param['pid']);
|
|
|
|
}
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
//查看路由是否更新
|
|
|
|
$id = $this->editCategoryRoute($this->param['id'],
|
|
|
|
isset($this->param['alias']) ?? RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
|
|
|
|
RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']));
|
|
|
|
$id = $this->editCategoryRoute($this->param['id'], $this->param['alias']);
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$this->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
}else{
|
|
...
|
...
|
@@ -62,6 +56,46 @@ 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();
|
|
|
|
$blogList = $blogModel->list(['category_id'=>['like','%,'.$pid.',%']],['id']);
|
|
|
|
//随机获取最后一级id
|
|
|
|
$replacement = $this->getLastId($id);
|
|
|
|
if(!empty($blogList)){
|
|
|
|
//存在博客时,移动所有博客到当前分类最后一级
|
|
|
|
$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){
|
|
|
|
$this->getLastId($id);
|
|
|
|
}else{
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑路由时生成路由记录
|
|
|
|
* @name :editCategoryRoute
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -106,6 +140,7 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :详情
|
|
|
|
* @return array
|
|
...
|
...
|
@@ -271,7 +306,7 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
$blogModel = new BlogModel();
|
|
|
|
$blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
|
|
|
if ($blog_count > 0) {
|
|
|
|
$replacement = ','. $this->param['pid'] . ',' . $cate_id . ',';
|
|
|
|
$replacement = ',' . $cate_id . ',';
|
|
|
|
$old = ',' . $this->param['pid'] . ',';
|
|
|
|
//更新所有商品到当前分类
|
|
|
|
$blogModel->where('category_id', 'like', '%' . $old . '%')
|
...
|
...
|
|