正在显示
1 个修改的文件
包含
19 行增加
和
9 行删除
| @@ -427,16 +427,26 @@ class NewsLogic extends BaseLogic | @@ -427,16 +427,26 @@ class NewsLogic extends BaseLogic | ||
| 427 | public function batchSetCategory(){ | 427 | public function batchSetCategory(){ |
| 428 | if(isset($this->param['category_id']) && !empty($this->param['category_id'])) { | 428 | if(isset($this->param['category_id']) && !empty($this->param['category_id'])) { |
| 429 | DB::connection('custom_mysql')->beginTransaction(); | 429 | DB::connection('custom_mysql')->beginTransaction(); |
| 430 | - $this->param['category_id'] = ','.implode(',',$this->param['category_id']).','; | 430 | + $category_id_str = ','.implode(',',$this->param['category_id']).','; |
| 431 | try { | 431 | try { |
| 432 | - //批量 | ||
| 433 | - $param = [ | ||
| 434 | - 'category_id'=>$this->param['category_id'], | ||
| 435 | - 'status'=>$this->param['status'] | ||
| 436 | - ]; | ||
| 437 | - $this->model->edit($param,['id'=>['in',$this->param['id']]]); | ||
| 438 | - DB::connection('custom_mysql')->commit(); | ||
| 439 | - //对应添加关联表 | 432 | + if(!isset($this->param['is_cover']) || ($this->param['is_cover'] == 1)){ |
| 433 | + //批量覆盖 | ||
| 434 | + $param = [ | ||
| 435 | + 'category_id'=>$category_id_str, | ||
| 436 | + 'status'=>$this->param['status'] | ||
| 437 | + ]; | ||
| 438 | + $this->model->edit($param,['id'=>['in',$this->param['id']]]); | ||
| 439 | + DB::connection('custom_mysql')->commit(); | ||
| 440 | + }else{ | ||
| 441 | + foreach ($this->param['id'] as $id){ | ||
| 442 | + //获取当前产品的分类 | ||
| 443 | + $newsInfo = $this->model->read(['id'=>$id],['id','category_id']); | ||
| 444 | + $category_ids = explode(',',trim($newsInfo['category_id'],',')); | ||
| 445 | + $category_ids_arr = array_values(array_unique(array_merge($category_ids,$this->param['category_id']))); | ||
| 446 | + $category_ids = ','.implode(',',$category_ids_arr).','; | ||
| 447 | + $this->model->edit(['category_id'=>$category_ids],['id'=>$id]); | ||
| 448 | + } | ||
| 449 | + } | ||
| 440 | }catch (\Exception $e){ | 450 | }catch (\Exception $e){ |
| 441 | DB::connection('custom_mysql')->rollBack(); | 451 | DB::connection('custom_mysql')->rollBack(); |
| 442 | $this->fail('系统错误,请联系管理员'); | 452 | $this->fail('系统错误,请联系管理员'); |
-
请 注册 或 登录 后发表评论