|
...
|
...
|
@@ -27,54 +27,66 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function add_blog_category(){
|
|
|
|
DB::beginTransaction();
|
|
|
|
$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');
|
|
|
|
$cate_id = $this->model->insertGetId($this->param);
|
|
|
|
if($cate_id === false){
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('error',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
//判断为子分类时
|
|
|
|
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
|
|
|
|
//查看当前上级分类下是否有其他分类
|
|
|
|
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
|
|
|
|
if ($cate_info === false) {
|
|
|
|
//查看当前上一级分类下是否有新闻
|
|
|
|
$blogModel = new BlogModel();
|
|
|
|
$news_info = $blogModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);
|
|
|
|
if ($news_info !== false) {
|
|
|
|
$replacement = ',' . $cate_id . ',';
|
|
|
|
$old = ',' . $this->param['pid'] . ',';
|
|
|
|
//更新所有商品到当前分类
|
|
|
|
$rs = DB::table('gl_Blog')->where('category_id', 'like', '%' . $old . '%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
|
|
|
|
if ($rs === false) {
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('error', Code::USER_ERROR);
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$cate_id = $this->model->insertGetId($this->param);
|
|
|
|
//判断为子分类时
|
|
|
|
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
|
|
|
|
//查看当前上级分类下是否有其他分类
|
|
|
|
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
|
|
|
|
if ($cate_info === false) {
|
|
|
|
//查看当前上一级分类下是否有新闻
|
|
|
|
$blogModel = new BlogModel();
|
|
|
|
$blog_info = $blogModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);
|
|
|
|
if ($blog_info !== false) {
|
|
|
|
$replacement = ',' . $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')")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :编辑分类
|
|
|
|
* @return void
|
|
|
|
* @throws \App\Exceptions\BsideGlobalException
|
|
|
|
* @author :liyuhang
|
|
|
|
* @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->param['operator_id'] = $this->user['id'];
|
|
|
|
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$this->fail('error',Code::USER_ERROR);
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
...
|
...
|
@@ -82,14 +94,13 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
/**
|
|
|
|
* @name :详情
|
|
|
|
* @return array
|
|
|
|
* @throws \App\Exceptions\BsideGlobalException
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function info_blog_category(){
|
|
|
|
$info = $this->model->read($this->param);
|
|
|
|
if($info === false){
|
|
|
|
$this->fail('error',Code::USER_ERROR);
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
return $this->success($info);
|
|
|
|
}
|
|
...
|
...
|
@@ -104,7 +115,7 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$this->fail('error',Code::USER_ERROR);
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
...
|
...
|
@@ -115,24 +126,23 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function del_blog_category(){
|
|
|
|
$this->param = $this->requestAll;
|
|
|
|
foreach ($this->param['id'] as $v){
|
|
|
|
//查询是否有子分类
|
|
|
|
$rs = $this->model->read(['pid'=>$v],['id']);
|
|
|
|
if($rs !== false){
|
|
|
|
$this->response('当前分类拥有子分类不允许删除',Code::USER_ERROR);
|
|
|
|
$this->response('当前分类拥有子分类不允许删除');
|
|
|
|
}
|
|
|
|
//查看当前分内下是否有博客
|
|
|
|
$blogModel = new BlogModel();
|
|
|
|
$rs = $blogModel->read(['category_id'=>$v],['id']);
|
|
|
|
if($rs !== false){
|
|
|
|
$this->response('当前分类拥有博客',Code::USER_ERROR);
|
|
|
|
$this->response('当前分类拥有博客');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->param['id'] = ['in',$this->param['id']];
|
|
|
|
$rs = $this->model->del($this->param);
|
|
|
|
if($rs === false){
|
|
|
|
$this->response('error',Code::USER_ERROR);
|
|
|
|
$this->response('error');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
...
|
...
|
|