作者 lyh

gx

@@ -136,41 +136,37 @@ class KeywordLogic extends BaseLogic @@ -136,41 +136,37 @@ 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 {  
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]);  
168 - DB::connection('custom_mysql')->commit();  
169 - }catch (\Exception $e){  
170 - $this->fail('系统错误请联系管理员');  
171 - DB::connection('custom_mysql')->rollBack(); 148 + $data = [];
  149 + if (empty($v)) {
  150 + continue;
172 } 151 }
173 - 152 + $this->model = new Keyword();
  153 + $info = $this->model->read(['title' => $v]);
  154 + if ($info !== false) {
  155 + continue;
  156 + }
  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;
  168 + }
  169 + $this->model->edit(['route' => $route], ['id' => $ids]);
174 } 170 }
175 return $this->success(); 171 return $this->success();
176 } 172 }