作者 赵彬吉

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

@@ -137,11 +137,11 @@ class BaseLogic extends Logic @@ -137,11 +137,11 @@ class BaseLogic extends Logic
137 } 137 }
138 }else{ 138 }else{
139 if($type == 'del'){ 139 if($type == 'del'){
140 - $model::where('id',$data)->decrement('num',$num); 140 + $rs = $model::where('id',$data)->decrement('num',$num);
141 }else{ 141 }else{
142 - $model::where('id',$data)->increment('num',$num); 142 + $rs = $model::where('id',$data)->increment('num',$num);
143 } 143 }
144 } 144 }
145 - return true; 145 + return $rs;
146 } 146 }
147 } 147 }
@@ -106,9 +106,14 @@ class BlogLogic extends BaseLogic @@ -106,9 +106,14 @@ class BlogLogic extends BaseLogic
106 $this->param['operator_id'] = $this->user['id']; 106 $this->param['operator_id'] = $this->user['id'];
107 DB::beginTransaction(); 107 DB::beginTransaction();
108 try { 108 try {
  109 + $info = $this->model->read(['id'=>$this->param['id']],['id','image','category_id']);
  110 + //查看分类是否有更新
  111 + if($info['category_id'] !== $this->param['category_id']){
  112 + $this->update_category_num($info['category_id'],$this->param['category_id']);
  113 + }
  114 + //是否有图片更新
109 if(isset($this->param['image']) && is_file($this->param['image'])){ 115 if(isset($this->param['image']) && is_file($this->param['image'])){
110 //查看当前用户是否已有头像 116 //查看当前用户是否已有头像
111 - $info = $this->model->read(['id'=>$this->param['id']],['id','image']);  
112 if($info !== false && !empty($info['image'])){ 117 if($info !== false && !empty($info['image'])){
113 //TODO::删除资源 118 //TODO::删除资源
114 $imageModel = new Image(); 119 $imageModel = new Image();
@@ -222,4 +227,20 @@ class BlogLogic extends BaseLogic @@ -222,4 +227,20 @@ class BlogLogic extends BaseLogic
222 } 227 }
223 return trim($str,','); 228 return trim($str,',');
224 } 229 }
  230 +
  231 + /**
  232 + * @name :编辑分类时更新分类计数
  233 + * @return void
  234 + * @author :liyuhang
  235 + * @method
  236 + */
  237 + public function update_category_num($category_del = '',$category_add = ''){
  238 + //分类计数(减)
  239 + $category_del_data = explode(',',trim($category_del,','));
  240 + $this->set_num(BlogCategoryModel::class,$category_del_data);
  241 + //分类计数(加)
  242 + $category_add_data = explode(',',trim($category_add,','));
  243 + $this->set_num(BlogCategoryModel::class,$category_add_data,'del');
  244 + return true;
  245 + }
225 } 246 }
@@ -36,6 +36,7 @@ class NewsCategoryLogic extends BaseLogic @@ -36,6 +36,7 @@ class NewsCategoryLogic extends BaseLogic
36 $v['category_name'] = trim($str,','); 36 $v['category_name'] = trim($str,',');
37 return $this->success($v); 37 return $this->success($v);
38 } 38 }
  39 +
39 /** 40 /**
40 * @name :详情 41 * @name :详情
41 * @return array 42 * @return array
@@ -76,13 +77,15 @@ class NewsCategoryLogic extends BaseLogic @@ -76,13 +77,15 @@ class NewsCategoryLogic extends BaseLogic
76 if ($cate_info === false) { 77 if ($cate_info === false) {
77 //查看当前上一级分类下是否有新闻 78 //查看当前上一级分类下是否有新闻
78 $newsModel = new NewsModel(); 79 $newsModel = new NewsModel();
79 - $news_info = $newsModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);  
80 - if ($news_info !== false) {  
81 - $replacement = ',' . $cate_id . ','; 80 + $news_count = $newsModel->formatQuery(['category_id' => ['like', ',' . $this->param['pid'] . ',']])->count();
  81 + if ($news_count > 0) {
  82 + $replacement = ','. $this->param['pid'] .','. $cate_id . ',';
82 $old = ',' . $this->param['pid'] . ','; 83 $old = ',' . $this->param['pid'] . ',';
83 //更新所有商品到当前分类 84 //更新所有商品到当前分类
84 DB::table('gl_news')->where('category_id', 'like', '%' . $old . '%') 85 DB::table('gl_news')->where('category_id', 'like', '%' . $old . '%')
85 ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]); 86 ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
  87 + //更新计数
  88 + $this->set_num($this->model,$cate_id,'add',$news_count);
86 } 89 }
87 } 90 }
88 } 91 }
@@ -99,10 +99,14 @@ class NewsLogic extends BaseLogic @@ -99,10 +99,14 @@ class NewsLogic extends BaseLogic
99 $this->param['category_id'] = $this->param['category_id']; 99 $this->param['category_id'] = $this->param['category_id'];
100 DB::beginTransaction(); 100 DB::beginTransaction();
101 try { 101 try {
  102 + $info = $this->model->read(['id'=>$this->param['id']],['id','image','category_id']);
  103 + //查看分类是否有跟新
  104 + if($info['category_id'] !== $this->param['category_id']){
  105 + $this->update_category_num($info['category_id'],$this->param['category_id']);
  106 + }
102 //上传图片 107 //上传图片
103 if(isset($this->param['image']) && is_file($this->param['image'])){ 108 if(isset($this->param['image']) && is_file($this->param['image'])){
104 //查看当前用户是否已有头像 109 //查看当前用户是否已有头像
105 - $info = $this->model->read(['id'=>$this->param['id']],['id','image']);  
106 if($info !== false && !empty($info['image'])){ 110 if($info !== false && !empty($info['image'])){
107 //TODO::删除资源 111 //TODO::删除资源
108 $imageModel = new Image(); 112 $imageModel = new Image();
@@ -216,4 +220,20 @@ class NewsLogic extends BaseLogic @@ -216,4 +220,20 @@ class NewsLogic extends BaseLogic
216 } 220 }
217 return trim($str,','); 221 return trim($str,',');
218 } 222 }
  223 +
  224 + /**
  225 + * @name :编辑分类时更新分类计数
  226 + * @return void
  227 + * @author :liyuhang
  228 + * @method
  229 + */
  230 + public function update_category_num($category_del = '',$category_add = ''){
  231 + //分类计数(减)
  232 + $category_del_data = explode(',',trim($category_del,','));
  233 + $this->set_num(NewsCategoryModel::class,$category_del_data);
  234 + //分类计数(加)
  235 + $category_add_data = explode(',',trim($category_add,','));
  236 + $this->set_num(NewsCategoryModel::class,$category_add_data,'del');
  237 + return true;
  238 + }
219 } 239 }