作者 lyh

gx

@@ -61,17 +61,13 @@ class NewsCategoryLogic extends BaseLogic @@ -61,17 +61,13 @@ class NewsCategoryLogic extends BaseLogic
61 public function newsCategorySave(){ 61 public function newsCategorySave(){
62 //验证名称是否存在 62 //验证名称是否存在
63 $this->verifyParamName($this->param['name']); 63 $this->verifyParamName($this->param['name']);
64 - //验证是否可编辑  
65 - if(isset($this->param['id']) && !empty($this->param['id'])) {  
66 - $this->verifyEditParam($this->param['id'], $this->param['pid']);  
67 - }  
68 DB::beginTransaction(); 64 DB::beginTransaction();
69 try { 65 try {
70 if(isset($this->param['id']) && !empty($this->param['id'])){ 66 if(isset($this->param['id']) && !empty($this->param['id'])){
71 $this->param['operator_id'] = $this->user['id']; 67 $this->param['operator_id'] = $this->user['id'];
72 //查看路由是否更新 68 //查看路由是否更新
73 - $id = $this->editCategoryRoute($this->param['id'],$this->param['alias'] ?? RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],  
74 - RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id'])); 69 + $id = $this->editCategoryRoute($this->param['id'],$this->param['alias']);
  70 + $this->editHandleCategory($this->param['id'],$this->param['pid']);
75 $this->edit($this->param,['id'=>$this->param['id']]); 71 $this->edit($this->param,['id'=>$this->param['id']]);
76 }else{ 72 }else{
77 $this->param = $this->addParamProcessing($this->param); 73 $this->param = $this->addParamProcessing($this->param);
@@ -91,6 +87,31 @@ class NewsCategoryLogic extends BaseLogic @@ -91,6 +87,31 @@ class NewsCategoryLogic extends BaseLogic
91 return $this->success(); 87 return $this->success();
92 } 88 }
93 89
  90 + /**
  91 + * @remark :编辑分类,处理博客数据
  92 + * @name :editCategory
  93 + * @author :lyh
  94 + * @method :post
  95 + * @time :2023/10/20 9:32
  96 + */
  97 + public function editHandleCategory($id,$pid){
  98 + $info = $this->model->read(['id'=>$id],['id','pid']);
  99 + if($info['pid'] != $pid){
  100 + //修改勒上级,先查看上级是否拥有博客
  101 + $newsModel = new NewsModel();
  102 + $newsCount = $newsModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
  103 + //随机获取最后一级id
  104 + $replacement = $this->getLastId($id);
  105 + if($newsCount > 0){
  106 + //存在博客时,移动所有博客到当前分类最后一级
  107 + $newsCount->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
  108 + ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
  109 + $newsCount->where('category_id', 'like', '%,' . $pid . ',%')
  110 + ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
  111 + }
  112 + }
  113 + return $this->success();
  114 + }
94 115
95 /** 116 /**
96 * @remark :编辑路由时生成路由记录 117 * @remark :编辑路由时生成路由记录
@@ -272,7 +293,7 @@ class NewsCategoryLogic extends BaseLogic @@ -272,7 +293,7 @@ class NewsCategoryLogic extends BaseLogic
272 $newsModel = new NewsModel(); 293 $newsModel = new NewsModel();
273 $news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count(); 294 $news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
274 if ($news_count > 0) { 295 if ($news_count > 0) {
275 - $replacement = ','. $this->param['pid'] .','. $cate_id . ','; 296 + $replacement = ',' . $cate_id . ',';
276 $old = ',' . $this->param['pid'] . ','; 297 $old = ',' . $this->param['pid'] . ',';
277 //更新所有商品到当前分类 298 //更新所有商品到当前分类
278 $newsModel->where('category_id', 'like', '%' . $old . '%') 299 $newsModel->where('category_id', 'like', '%' . $old . '%')
@@ -7,6 +7,7 @@ use App\Helper\Common; @@ -7,6 +7,7 @@ use App\Helper\Common;
7 use App\Http\Logic\Bside\BaseLogic; 7 use App\Http\Logic\Bside\BaseLogic;
8 use App\Models\Com\AssociationCate; 8 use App\Models\Com\AssociationCate;
9 use App\Models\News\News; 9 use App\Models\News\News;
  10 +use App\Models\News\NewsCategory;
10 use App\Models\News\NewsCategory as NewsCategoryModel; 11 use App\Models\News\NewsCategory as NewsCategoryModel;
11 use App\Models\RouteMap\RouteMap; 12 use App\Models\RouteMap\RouteMap;
12 use App\Services\CosService; 13 use App\Services\CosService;
@@ -148,13 +149,36 @@ class NewsLogic extends BaseLogic @@ -148,13 +149,36 @@ class NewsLogic extends BaseLogic
148 public function newsInfo() 149 public function newsInfo()
149 { 150 {
150 $info = $this->model->read($this->param); 151 $info = $this->model->read($this->param);
  152 + if($info === false){
  153 + $this->fail('error');
  154 + }
  155 + $category = explode(',',trim($info['category_id'],','));
  156 + $str = [];
  157 + foreach ($category as $v){
  158 + $this->getAllFather($v,$str);
  159 + }
  160 + $info['category_id'] = array_unique($str);
151 $info['image_link'] = getImageUrl($info['image']); 161 $info['image_link'] = getImageUrl($info['image']);
152 - $newsCategoryLogic = new NewsCategoryLogic();  
153 - $info = $newsCategoryLogic->get_category_name($info);  
154 return $this->success($info); 162 return $this->success($info);
155 } 163 }
156 164
157 /** 165 /**
  166 + * @remark :获取分类的所有上级
  167 + * @name :getAllFather
  168 + * @author :lyh
  169 + * @method :post
  170 + * @time :2023/10/20 9:08
  171 + */
  172 + public function getAllFather($id,&$str = []){
  173 + $cateModel = new NewsCategoryModel();
  174 + $info = $cateModel->read(['id'=>$id],['id','pid']);
  175 + if($info !== false){
  176 + $str[] = (int)$id;
  177 + $this->getAllFather($info['pid'],$str);
  178 + }
  179 + }
  180 +
  181 + /**
158 * @name :逻辑删除 182 * @name :逻辑删除
159 * @return void 183 * @return void
160 * @author :liyuhang 184 * @author :liyuhang
@@ -184,23 +208,42 @@ class NewsLogic extends BaseLogic @@ -184,23 +208,42 @@ class NewsLogic extends BaseLogic
184 */ 208 */
185 public function paramProcessing($param) 209 public function paramProcessing($param)
186 { 210 {
187 - if (isset($this->param['id'])) { 211 + if(isset($this->param['id'])){
188 $param['operator_id'] = $this->user['id']; 212 $param['operator_id'] = $this->user['id'];
189 - if (isset($param['category_id']) && !empty($param['category_id'])) {  
190 - $param['category_id'] = ',' . trim($param['category_id'], ',') . ','; 213 + if(isset($param['category_id']) && !empty($param['category_id'])){
  214 + $param['category_id'] = $this->getLastCategory($param['category_id']);
191 } 215 }
192 - } else { 216 + }else{
193 $param['create_id'] = $this->user['id']; 217 $param['create_id'] = $this->user['id'];
194 $param['operator_id'] = $this->user['id']; 218 $param['operator_id'] = $this->user['id'];
195 $param['project_id'] = $this->user['project_id']; 219 $param['project_id'] = $this->user['project_id'];
196 - if (isset($param['category_id']) && !empty($param['category_id'])) {  
197 - $param['category_id'] = ',' . $param['category_id'] . ','; 220 + if(isset($param['category_id']) && !empty($param['category_id'])){
  221 + $param['category_id'] = $this->getLastCategory($param['category_id']);
198 } 222 }
199 } 223 }
200 return $this->success($param); 224 return $this->success($param);
201 } 225 }
202 226
203 /** 227 /**
  228 + * @remark :获取最后一级分类id
  229 + * @name :getLastCategory
  230 + * @author :lyh
  231 + * @method :post
  232 + * @time :2023/10/20 9:02
  233 + */
  234 + public function getLastCategory($category){
  235 + $str = '';
  236 + $cateModel = new NewsCategoryModel();
  237 + foreach ($category as $v){
  238 + $info = $cateModel->read(['pid'=>$v]);
  239 + if($info === false){
  240 + $str .= $v.',';
  241 + }
  242 + }
  243 + return ','.$str;
  244 + }
  245 +
  246 + /**
204 * @remark :根据状态获取数量 247 * @remark :根据状态获取数量
205 * @name :getStatusNumber 248 * @name :getStatusNumber
206 * @author :lyh 249 * @author :lyh