作者 lyh

gx

@@ -144,25 +144,32 @@ class KeywordLogic extends BaseLogic @@ -144,25 +144,32 @@ class KeywordLogic extends BaseLogic
144 if($num > 1000){ 144 if($num > 1000){
145 $this->fail('最大数量不能超过1000'); 145 $this->fail('最大数量不能超过1000');
146 } 146 }
147 - foreach ($this->param['title'] as $k=>$v){  
148 - if(empty($v)){  
149 - continue;  
150 - }  
151 - $this->model = new Keyword();  
152 - $info = $this->model->read(['title'=>$v]);  
153 - if($info !== false) {  
154 - continue;  
155 - }  
156 - $param['project_id'] = $this->user['project_id'];  
157 - $param['created_at'] = date('Y-m-d H:i:s');  
158 - $param['updated_at'] = $param['created_at'];  
159 - $param['title'] = $v;  
160 - $id = $this->model->insertGetId($param);  
161 - $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);  
162 - if(empty($route)){  
163 - continue; 147 + DB::connection('custom_mysql')->beginTransaction();
  148 + try {
  149 + foreach ($this->param['title'] as $k=>$v){
  150 + if(empty($v)){
  151 + continue;
  152 + }
  153 + $this->model = new Keyword();
  154 + $info = $this->model->read(['title'=>$v]);
  155 + if($info !== false) {
  156 + continue;
  157 + }
  158 + $param['project_id'] = $this->user['project_id'];
  159 + $param['created_at'] = date('Y-m-d H:i:s');
  160 + $param['updated_at'] = $param['created_at'];
  161 + $param['title'] = $v;
  162 + $id = $this->model->insertGetId($param);
  163 + $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
  164 + if(empty($route)){
  165 + continue;
  166 + }
  167 + $this->model->edit(['route'=>$route],['id'=>$id]);
164 } 168 }
165 - $this->model->edit(['route'=>$route],['id'=>$id]); 169 + DB::connection('custom_mysql')->commit();
  170 + }catch (\Exception $e){
  171 + $this->fail('系统错误请联系管理员');
  172 + DB::connection('custom_mysql')->rollBack();
166 } 173 }
167 return $this->success(); 174 return $this->success();
168 } 175 }