作者 赵彬吉

Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev

... ... @@ -137,11 +137,11 @@ class BaseLogic extends Logic
}
}else{
if($type == 'del'){
$model::where('id',$data)->decrement('num',$num);
$rs = $model::where('id',$data)->decrement('num',$num);
}else{
$model::where('id',$data)->increment('num',$num);
$rs = $model::where('id',$data)->increment('num',$num);
}
}
return true;
return $rs;
}
}
... ...
... ... @@ -106,9 +106,14 @@ 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'])){
//查看当前用户是否已有头像
$info = $this->model->read(['id'=>$this->param['id']],['id','image']);
if($info !== false && !empty($info['image'])){
//TODO::删除资源
$imageModel = new Image();
... ... @@ -222,4 +227,20 @@ class BlogLogic extends BaseLogic
}
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;
}
}
... ...
... ... @@ -36,6 +36,7 @@ class NewsCategoryLogic extends BaseLogic
$v['category_name'] = trim($str,',');
return $this->success($v);
}
/**
* @name :详情
* @return array
... ... @@ -76,13 +77,15 @@ class NewsCategoryLogic extends BaseLogic
if ($cate_info === false) {
//查看当前上一级分类下是否有新闻
$newsModel = new NewsModel();
$news_info = $newsModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);
if ($news_info !== false) {
$replacement = ',' . $cate_id . ',';
$news_count = $newsModel->formatQuery(['category_id' => ['like', ',' . $this->param['pid'] . ',']])->count();
if ($news_count > 0) {
$replacement = ','. $this->param['pid'] .','. $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
DB::table('gl_news')->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
//更新计数
$this->set_num($this->model,$cate_id,'add',$news_count);
}
}
}
... ...
... ... @@ -99,10 +99,14 @@ class NewsLogic extends BaseLogic
$this->param['category_id'] = $this->param['category_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'])){
//查看当前用户是否已有头像
$info = $this->model->read(['id'=>$this->param['id']],['id','image']);
if($info !== false && !empty($info['image'])){
//TODO::删除资源
$imageModel = new Image();
... ... @@ -216,4 +220,20 @@ class NewsLogic extends BaseLogic
}
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(NewsCategoryModel::class,$category_del_data);
//分类计数(加)
$category_add_data = explode(',',trim($category_add,','));
$this->set_num(NewsCategoryModel::class,$category_add_data,'del');
return true;
}
}
... ...