作者 lyh

gx

@@ -136,16 +136,11 @@ class KeywordLogic extends BaseLogic @@ -136,16 +136,11 @@ class KeywordLogic extends BaseLogic
136 * @time :2023/8/28 14:03 136 * @time :2023/8/28 14:03
137 */ 137 */
138 public function batchAdd(){ 138 public function batchAdd(){
139 - $route_array = Translate::tran($this->param['title'], 'en');  
140 - if (empty($route_array)) {  
141 - $this->fail('路由生成失败,请稍后重试!');  
142 - }  
143 $num = count($this->param['title']); 139 $num = count($this->param['title']);
144 if($num > 1000){ 140 if($num > 1000){
145 $this->fail('最大数量不能超过1000'); 141 $this->fail('最大数量不能超过1000');
146 } 142 }
147 foreach ($this->param['title'] as $k=>$v) { 143 foreach ($this->param['title'] as $k=>$v) {
148 - $data = [];  
149 if (empty($v)) { 144 if (empty($v)) {
150 continue; 145 continue;
151 } 146 }
@@ -158,17 +153,14 @@ class KeywordLogic extends BaseLogic @@ -158,17 +153,14 @@ class KeywordLogic extends BaseLogic
158 $param['created_at'] = date('Y-m-d H:i:s'); 153 $param['created_at'] = date('Y-m-d H:i:s');
159 $param['updated_at'] = $param['created_at']; 154 $param['updated_at'] = $param['created_at'];
160 $param['title'] = $v; 155 $param['title'] = $v;
  156 + DB::connection('custom_mysql')->beginTransaction();
161 $id = $this->model->insertGetId($param); 157 $id = $this->model->insertGetId($param);
162 - $data[$k] = $id;  
163 - }  
164 - if(!empty($data)){  
165 - foreach ($data as $k=>$ids){  
166 - $route = RouteMap::setRoute($route_array[$k], RouteMap::SOURCE_PRODUCT_KEYWORD, $ids, $this->user['project_id']);  
167 - if (empty($route)) {  
168 - continue;  
169 - }  
170 - $this->model->edit(['route' => $route], ['id' => $ids]); 158 + $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
  159 + if (empty($route)) {
  160 + DB::connection('custom_mysql')->rollBack();
171 } 161 }
  162 + $this->model->edit(['route' => $route], ['id' => $id]);
  163 + DB::connection('custom_mysql')->commit();
172 } 164 }
173 return $this->success(); 165 return $this->success();
174 } 166 }