作者 lyh

gx

@@ -144,30 +144,37 @@ class KeywordLogic extends BaseLogic @@ -144,30 +144,37 @@ 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 - $data = [];  
149 - if (empty($v)) {  
150 - continue;  
151 - }  
152 - $this->model = new Keyword();  
153 - $info = $this->model->read(['title' => $v]);  
154 - if ($info !== false) {  
155 - continue; 147 + DB::connection('custom_mysql')->beginTransaction();
  148 + try {
  149 + foreach ($this->param['title'] as $k=>$v) {
  150 + $data = [];
  151 + if (empty($v)) {
  152 + continue;
  153 + }
  154 + $this->model = new Keyword();
  155 + $info = $this->model->read(['title' => $v]);
  156 + if ($info !== false) {
  157 + continue;
  158 + }
  159 + $param['project_id'] = $this->user['project_id'];
  160 + $param['created_at'] = date('Y-m-d H:i:s');
  161 + $param['updated_at'] = $param['created_at'];
  162 + $param['title'] = $v;
  163 + $id = $this->model->insertGetId($param);
  164 + $data[$k] = $id;
156 } 165 }
157 - $param['project_id'] = $this->user['project_id'];  
158 - $param['created_at'] = date('Y-m-d H:i:s');  
159 - $param['updated_at'] = $param['created_at'];  
160 - $param['title'] = $v;  
161 - $id = $this->model->insertGetId($param);  
162 - $data[$k] = $id;  
163 - }  
164 - foreach ($data as $k=>$ids){  
165 - $route = RouteMap::setRoute($route_array[$k], RouteMap::SOURCE_PRODUCT_KEYWORD, $ids, $this->user['project_id']);  
166 - if (empty($route)) {  
167 - continue; 166 + foreach ($data as $k=>$ids){
  167 + $route = RouteMap::setRoute($route_array[$k], RouteMap::SOURCE_PRODUCT_KEYWORD, $ids, $this->user['project_id']);
  168 + if (empty($route)) {
  169 + continue;
  170 + }
  171 + $this->model->edit(['route' => $route], ['id' => $ids]);
168 } 172 }
169 - $this->model->edit(['route' => $route], ['id' => $ids]); 173 + DB::connection('custom_mysql')->commit();
  174 + }catch (\Exception $e){
  175 + DB::connection('custom_mysql')->rollBack();
170 } 176 }
  177 +
171 return $this->success(); 178 return $this->success();
172 } 179 }
173 180