正在显示
2 个修改的文件
包含
28 行增加
和
6 行删除
| @@ -383,15 +383,26 @@ class BlogLogic extends BaseLogic | @@ -383,15 +383,26 @@ class BlogLogic extends BaseLogic | ||
| 383 | public function batchSetCategory(){ | 383 | public function batchSetCategory(){ |
| 384 | if(isset($this->param['category_id']) && !empty($this->param['category_id'])) { | 384 | if(isset($this->param['category_id']) && !empty($this->param['category_id'])) { |
| 385 | DB::connection('custom_mysql')->beginTransaction(); | 385 | DB::connection('custom_mysql')->beginTransaction(); |
| 386 | - $this->param['category_id'] = ','.implode(',',$this->param['category_id']).','; | 386 | + $category_id_str = ','.implode(',',$this->param['category_id']).','; |
| 387 | try { | 387 | try { |
| 388 | - //批量 | 388 | + if(!isset($this->param['is_cover']) || ($this->param['is_cover'] == 1)){ |
| 389 | + //批量覆盖 | ||
| 389 | $param = [ | 390 | $param = [ |
| 390 | - 'category_id'=>$this->param['category_id'], | 391 | + 'category_id'=>$category_id_str, |
| 391 | 'status'=>$this->param['status'] | 392 | 'status'=>$this->param['status'] |
| 392 | ]; | 393 | ]; |
| 393 | $this->model->edit($param,['id'=>['in',$this->param['id']]]); | 394 | $this->model->edit($param,['id'=>['in',$this->param['id']]]); |
| 394 | DB::connection('custom_mysql')->commit(); | 395 | DB::connection('custom_mysql')->commit(); |
| 396 | + }else{ | ||
| 397 | + foreach ($this->param['id'] as $id){ | ||
| 398 | + //获取当前产品的分类 | ||
| 399 | + $blogInfo = $this->model->read(['id'=>$id],['id','category_id']); | ||
| 400 | + $category_ids = explode(',',trim($blogInfo['category_id'],',')); | ||
| 401 | + $category_ids_arr = array_values(array_unique(array_merge($category_ids,$this->param['category_id']))); | ||
| 402 | + $category_ids = ','.implode(',',$category_ids_arr).','; | ||
| 403 | + $this->model->edit(['category_id'=>$category_ids],['id'=>$id]); | ||
| 404 | + } | ||
| 405 | + } | ||
| 395 | //对应添加关联表 | 406 | //对应添加关联表 |
| 396 | }catch (\Exception $e){ | 407 | }catch (\Exception $e){ |
| 397 | DB::connection('custom_mysql')->rollBack(); | 408 | DB::connection('custom_mysql')->rollBack(); |
| @@ -428,15 +428,26 @@ class NewsLogic extends BaseLogic | @@ -428,15 +428,26 @@ class NewsLogic extends BaseLogic | ||
| 428 | public function batchSetCategory(){ | 428 | public function batchSetCategory(){ |
| 429 | if(isset($this->param['category_id']) && !empty($this->param['category_id'])) { | 429 | if(isset($this->param['category_id']) && !empty($this->param['category_id'])) { |
| 430 | DB::connection('custom_mysql')->beginTransaction(); | 430 | DB::connection('custom_mysql')->beginTransaction(); |
| 431 | - $this->param['category_id'] = ','.implode(',',$this->param['category_id']).','; | 431 | + $category_id_str = ','.implode(',',$this->param['category_id']).','; |
| 432 | try { | 432 | try { |
| 433 | - //批量 | 433 | + if(!isset($this->param['is_cover']) || ($this->param['is_cover'] == 1)){ |
| 434 | + //批量覆盖 | ||
| 434 | $param = [ | 435 | $param = [ |
| 435 | - 'category_id'=>$this->param['category_id'], | 436 | + 'category_id'=>$category_id_str, |
| 436 | 'status'=>$this->param['status'] | 437 | 'status'=>$this->param['status'] |
| 437 | ]; | 438 | ]; |
| 438 | $this->model->edit($param,['id'=>['in',$this->param['id']]]); | 439 | $this->model->edit($param,['id'=>['in',$this->param['id']]]); |
| 439 | DB::connection('custom_mysql')->commit(); | 440 | DB::connection('custom_mysql')->commit(); |
| 441 | + }else{ | ||
| 442 | + foreach ($this->param['id'] as $id){ | ||
| 443 | + //获取当前产品的分类 | ||
| 444 | + $newsInfo = $this->model->read(['id'=>$id],['id','category_id']); | ||
| 445 | + $category_ids = explode(',',trim($newsInfo['category_id'],',')); | ||
| 446 | + $category_ids_arr = array_values(array_unique(array_merge($category_ids,$this->param['category_id']))); | ||
| 447 | + $category_ids = ','.implode(',',$category_ids_arr).','; | ||
| 448 | + $this->model->edit(['category_id'=>$category_ids],['id'=>$id]); | ||
| 449 | + } | ||
| 450 | + } | ||
| 440 | //对应添加关联表 | 451 | //对应添加关联表 |
| 441 | }catch (\Exception $e){ | 452 | }catch (\Exception $e){ |
| 442 | DB::connection('custom_mysql')->rollBack(); | 453 | DB::connection('custom_mysql')->rollBack(); |
-
请 注册 或 登录 后发表评论