正在显示
1 个修改的文件
包含
19 行增加
和
8 行删除
| @@ -382,15 +382,26 @@ class BlogLogic extends BaseLogic | @@ -382,15 +382,26 @@ class BlogLogic extends BaseLogic | ||
| 382 | public function batchSetCategory(){ | 382 | public function batchSetCategory(){ |
| 383 | if(isset($this->param['category_id']) && !empty($this->param['category_id'])) { | 383 | if(isset($this->param['category_id']) && !empty($this->param['category_id'])) { |
| 384 | DB::connection('custom_mysql')->beginTransaction(); | 384 | DB::connection('custom_mysql')->beginTransaction(); |
| 385 | - $this->param['category_id'] = ','.implode(',',$this->param['category_id']).','; | 385 | + $category_id_str = ','.implode(',',$this->param['category_id']).','; |
| 386 | try { | 386 | try { |
| 387 | - //批量 | ||
| 388 | - $param = [ | ||
| 389 | - 'category_id'=>$this->param['category_id'], | ||
| 390 | - 'status'=>$this->param['status'] | ||
| 391 | - ]; | ||
| 392 | - $this->model->edit($param,['id'=>['in',$this->param['id']]]); | ||
| 393 | - DB::connection('custom_mysql')->commit(); | 387 | + if(!isset($this->param['is_cover']) || ($this->param['is_cover'] == 1)){ |
| 388 | + //批量覆盖 | ||
| 389 | + $param = [ | ||
| 390 | + 'category_id'=>$category_id_str, | ||
| 391 | + 'status'=>$this->param['status'] | ||
| 392 | + ]; | ||
| 393 | + $this->model->edit($param,['id'=>['in',$this->param['id']]]); | ||
| 394 | + DB::connection('custom_mysql')->commit(); | ||
| 395 | + }else{ | ||
| 396 | + foreach ($this->param['id'] as $id){ | ||
| 397 | + //获取当前产品的分类 | ||
| 398 | + $blogInfo = $this->model->read(['id'=>$id],['id','category_id']); | ||
| 399 | + $category_ids = explode(',',trim($blogInfo['category_id'],',')); | ||
| 400 | + $category_ids_arr = array_values(array_unique(array_merge($category_ids,$this->param['category_id']))); | ||
| 401 | + $category_ids = ','.implode(',',$category_ids_arr).','; | ||
| 402 | + $this->model->edit(['category_id'=>$category_ids],['id'=>$id]); | ||
| 403 | + } | ||
| 404 | + } | ||
| 394 | //对应添加关联表 | 405 | //对应添加关联表 |
| 395 | }catch (\Exception $e){ | 406 | }catch (\Exception $e){ |
| 396 | DB::connection('custom_mysql')->rollBack(); | 407 | DB::connection('custom_mysql')->rollBack(); |
-
请 注册 或 登录 后发表评论