|
...
|
...
|
@@ -61,17 +61,13 @@ class NewsCategoryLogic extends BaseLogic |
|
|
|
public function newsCategorySave(){
|
|
|
|
//验证名称是否存在
|
|
|
|
$this->verifyParamName($this->param['name']);
|
|
|
|
//验证是否可编辑
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])) {
|
|
|
|
$this->verifyEditParam($this->param['id'], $this->param['pid']);
|
|
|
|
}
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
//查看路由是否更新
|
|
|
|
$id = $this->editCategoryRoute($this->param['id'],$this->param['alias'] ?? RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
|
|
|
|
RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']));
|
|
|
|
$id = $this->editCategoryRoute($this->param['id'],$this->param['alias']);
|
|
|
|
$this->editHandleCategory($this->param['id'],$this->param['pid']);
|
|
|
|
$this->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
}else{
|
|
|
|
$this->param = $this->addParamProcessing($this->param);
|
|
...
|
...
|
@@ -91,6 +87,31 @@ class NewsCategoryLogic extends BaseLogic |
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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){
|
|
|
|
//修改勒上级,先查看上级是否拥有博客
|
|
|
|
$newsModel = new NewsModel();
|
|
|
|
$newsCount = $newsModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
|
|
|
|
//随机获取最后一级id
|
|
|
|
$replacement = $this->getLastId($id);
|
|
|
|
if($newsCount > 0){
|
|
|
|
//存在博客时,移动所有博客到当前分类最后一级
|
|
|
|
$newsCount->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
|
|
|
|
$newsCount->where('category_id', 'like', '%,' . $pid . ',%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑路由时生成路由记录
|
|
...
|
...
|
@@ -272,7 +293,7 @@ class NewsCategoryLogic extends BaseLogic |
|
|
|
$newsModel = new NewsModel();
|
|
|
|
$news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
|
|
|
if ($news_count > 0) {
|
|
|
|
$replacement = ','. $this->param['pid'] .','. $cate_id . ',';
|
|
|
|
$replacement = ',' . $cate_id . ',';
|
|
|
|
$old = ',' . $this->param['pid'] . ',';
|
|
|
|
//更新所有商品到当前分类
|
|
|
|
$newsModel->where('category_id', 'like', '%' . $old . '%')
|
...
|
...
|
|