|
...
|
...
|
@@ -46,41 +46,15 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function add_blog_category(){
|
|
|
|
$condition = [
|
|
|
|
'name'=>$this->param['name']
|
|
|
|
];
|
|
|
|
$info = $this->model->read($condition);
|
|
|
|
if($info !== false){
|
|
|
|
$this->fail('当前分类名称已存在');
|
|
|
|
}
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$this->param['create_id'] = $this->user['id'];
|
|
|
|
$this->param['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
$this->param['updated_at'] = date('Y-m-d H:i:s');
|
|
|
|
//验证名称是否存在
|
|
|
|
$this->verifyParamName();
|
|
|
|
//拼接参数
|
|
|
|
$this->param = $this->addParamProcessing($this->param);
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$cate_id = $this->model->insertGetId($this->param);
|
|
|
|
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 = ','. $this->param['pid'] . ',' . $cate_id . ',';
|
|
|
|
$old = ',' . $this->param['pid'] . ',';
|
|
|
|
//更新所有商品到当前分类
|
|
|
|
DB::table('gl_Blog')->where('category_id', 'like', '%' . $old . '%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//处理子集
|
|
|
|
$this->addProcessingSon($cate_id);
|
|
|
|
RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_BLOG_CATE, $cate_id, $this->user['project_id']);
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
...
|
...
|
@@ -97,15 +71,8 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function edit_blog_category(){
|
|
|
|
$condition = [
|
|
|
|
'id'=>['!=',$this->param['id']],
|
|
|
|
'name'=>$this->param['name']
|
|
|
|
];
|
|
|
|
//查看当前分类名称是否存在
|
|
|
|
$info = $this->model->read($condition);
|
|
|
|
if($info !== false){
|
|
|
|
$this->fail('当前分类名称已存在');
|
|
|
|
}
|
|
|
|
//验证名称是否存在
|
|
|
|
$this->verifyParamName();
|
|
|
|
$info = $this->model->read(['id'=>$this->param['id']]);
|
|
|
|
if($info['id'] == $this->param['pid']){
|
|
|
|
$this->fail('不能成为自己的上级');
|
|
...
|
...
|
@@ -167,7 +134,7 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
$blogModel = new BlogModel();
|
|
|
|
$rs = $blogModel->read(['category_id'=>$v],['id']);
|
|
|
|
if($rs !== false){
|
|
|
|
$this->response('当前分类拥有博客');
|
|
|
|
$this->response('当前分类拥有博客,不允许删除');
|
|
|
|
}
|
|
|
|
RouteMap::delRoute(RouteMap::SOURCE_BLOG_CATE, $v, $this->user['project_id']);
|
|
|
|
}
|
|
...
|
...
|
@@ -191,4 +158,74 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
$list = $this->model->list($map);
|
|
|
|
return $this->success($list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :(参数处理)paramProcessing
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/13 11:30
|
|
|
|
*/
|
|
|
|
public function addParamProcessing($param){
|
|
|
|
$param['project_id'] = $this->user['project_id'];
|
|
|
|
$param['operator_id'] = $this->user['id'];
|
|
|
|
$param['create_id'] = $this->user['id'];
|
|
|
|
$param['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
$param['updated_at'] = date('Y-m-d H:i:s');
|
|
|
|
return $this->success($param);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :(验证名称是否存在)verifyParamName
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/13 11:41
|
|
|
|
*/
|
|
|
|
public function verifyParamName(){
|
|
|
|
if(isset($this->param['id'])){
|
|
|
|
$condition = [
|
|
|
|
'id'=>['!=',$this->param['id']],
|
|
|
|
'name'=>$this->param['name'],
|
|
|
|
];
|
|
|
|
}else{
|
|
|
|
$condition = [
|
|
|
|
'name'=>$this->param['name']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$info = $this->model->read($condition);
|
|
|
|
if($info !== false){
|
|
|
|
$this->fail('当前分类名称已存在');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 = ','. $this->param['pid'] . ',' . $cate_id . ',';
|
|
|
|
$old = ',' . $this->param['pid'] . ',';
|
|
|
|
//更新所有商品到当前分类
|
|
|
|
DB::table('gl_Blog')->where('category_id', 'like', '%' . $old . '%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|