作者 lyh

gx

@@ -105,17 +105,26 @@ class KeywordLogic extends BaseLogic @@ -105,17 +105,26 @@ class KeywordLogic extends BaseLogic
105 * @time :2023/8/28 14:03 105 * @time :2023/8/28 14:03
106 */ 106 */
107 public function batchAdd(){ 107 public function batchAdd(){
108 - foreach ($this->param['title'] as $v){  
109 - $info = $this->model->read(['title'=>$v]);  
110 - if($info === false){  
111 - $param['project_id'] = $this->user['project_id'];  
112 - $param['created_at'] = date('Y-m-d H:i:s');  
113 - $param['updated_at'] = $param['created_at'];  
114 - $param['title'] = $v;  
115 - $id = $this->model->insertGetId($param);  
116 - $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); 108 + try {
  109 + $idArr = [];
  110 + foreach ($this->param['title'] as $v){
  111 + $info = $this->model->read(['title'=>$v]);
  112 + if($info === false){
  113 + $param['project_id'] = $this->user['project_id'];
  114 + $param['created_at'] = date('Y-m-d H:i:s');
  115 + $param['updated_at'] = $param['created_at'];
  116 + $param['title'] = $v;
  117 + $id = $this->model->insertGetId($param);
  118 + $idArr[] = ['id'=>$id,'title'=>$v];
  119 + }
  120 + }
  121 + //批量生成路由
  122 + foreach ($idArr as $v){
  123 + $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']);
117 $this->model->edit(['route'=>$route],['id'=>$id]); 124 $this->model->edit(['route'=>$route],['id'=>$id]);
118 } 125 }
  126 + }catch (\Exception $e){
  127 + $this->fail('error');
119 } 128 }
120 return $this->success(); 129 return $this->success();
121 } 130 }