作者 lyh

gx

@@ -136,17 +136,16 @@ class KeywordLogic extends BaseLogic @@ -136,17 +136,16 @@ 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 -// } 139 + $route_array = Translate::tran($this->param['title'], 'en');
  140 + if (empty($route_array)) {
  141 + $this->fail('路由生成失败,请稍后重试!');
  142 + }
143 $num = count($this->param['title']); 143 $num = count($this->param['title']);
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) { 147 foreach ($this->param['title'] as $k=>$v) {
148 - DB::connection('custom_mysql')->beginTransaction();  
149 - try { 148 + $data = [];
150 if (empty($v)) { 149 if (empty($v)) {
151 continue; 150 continue;
152 } 151 }
@@ -160,17 +159,14 @@ class KeywordLogic extends BaseLogic @@ -160,17 +159,14 @@ class KeywordLogic extends BaseLogic
160 $param['updated_at'] = $param['created_at']; 159 $param['updated_at'] = $param['created_at'];
161 $param['title'] = $v; 160 $param['title'] = $v;
162 $id = $this->model->insertGetId($param); 161 $id = $this->model->insertGetId($param);
163 - $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); 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']);
164 if (empty($route)) { 166 if (empty($route)) {
165 continue; 167 continue;
166 } 168 }
167 - $this->model->edit(['route' => $route], ['id' => $id]);  
168 - DB::connection('custom_mysql')->commit();  
169 - }catch (\Exception $e){  
170 - $this->fail('系统错误请联系管理员');  
171 - DB::connection('custom_mysql')->rollBack();  
172 - }  
173 - 169 + $this->model->edit(['route' => $route], ['id' => $ids]);
174 } 170 }
175 return $this->success(); 171 return $this->success();
176 } 172 }