|
...
|
...
|
@@ -75,9 +75,6 @@ class BlogLogic extends BaseLogic |
|
|
|
$this->param['image'] = $data;
|
|
|
|
}
|
|
|
|
$rs = $this->model->insertGetId($this->param);
|
|
|
|
//分类计数
|
|
|
|
$category_data = explode(',',trim($this->param['category_id'],','));
|
|
|
|
$this->set_num(BlogCategoryModel::class,$category_data);
|
|
|
|
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
...
|
...
|
@@ -106,11 +103,6 @@ class BlogLogic extends BaseLogic |
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$info = $this->model->read(['id'=>$this->param['id']],['id','image','category_id']);
|
|
|
|
//查看分类是否有更新
|
|
|
|
if($info['category_id'] !== $this->param['category_id']){
|
|
|
|
$this->update_category_num($info['category_id'],$this->param['category_id']);
|
|
|
|
}
|
|
|
|
//是否有图片更新
|
|
|
|
if(isset($this->param['image']) && is_file($this->param['image'])){
|
|
|
|
//查看当前用户是否已有头像
|
|
...
|
...
|
@@ -183,7 +175,7 @@ class BlogLogic 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();
|
|
|
|
}
|
|
...
|
...
|
@@ -196,51 +188,15 @@ class BlogLogic extends BaseLogic |
|
|
|
*/
|
|
|
|
public function blog_del(){
|
|
|
|
$ids = $this->param['id'];
|
|
|
|
//获取所有博客的分类id
|
|
|
|
$str = $this->get_category_id($ids);
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$category_data = explode(',',$str);
|
|
|
|
//分类计数减1
|
|
|
|
$this->set_num(BlogCategoryModel::class,$category_data,'del');
|
|
|
|
$this->param['id'] = ['in',$this->param['id']];
|
|
|
|
$this->del($this->param,$ids);
|
|
|
|
DB::commit();
|
|
|
|
}catch (Exception $e){
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('当前数据不存在');
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param $ids
|
|
|
|
* @name :删除数据时获取所有数据的分类id
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function get_category_id($ids = []){
|
|
|
|
$str = '';
|
|
|
|
$list = $this->model->list(['id'=>['in',$ids]],'id',['id','category_id']);
|
|
|
|
foreach ($list as $v){
|
|
|
|
$str .= trim($v['category_id'],',').',';
|
|
|
|
}
|
|
|
|
return trim($str,',');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :编辑分类时更新分类计数
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function update_category_num($category_del = '',$category_add = ''){
|
|
|
|
//分类计数(减)
|
|
|
|
$category_del_data = explode(',',trim($category_del,','));
|
|
|
|
$this->set_num(BlogCategoryModel::class,$category_del_data);
|
|
|
|
//分类计数(加)
|
|
|
|
$category_add_data = explode(',',trim($category_add,','));
|
|
|
|
$this->set_num(BlogCategoryModel::class,$category_add_data,'del');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|