正在显示
1 个修改的文件
包含
14 行增加
和
5 行删除
| @@ -106,17 +106,26 @@ class KeywordLogic extends BaseLogic | @@ -106,17 +106,26 @@ class KeywordLogic extends BaseLogic | ||
| 106 | * @time :2023/8/28 14:03 | 106 | * @time :2023/8/28 14:03 |
| 107 | */ | 107 | */ |
| 108 | public function batchAdd(){ | 108 | public function batchAdd(){ |
| 109 | - if(!empty($this->param['title'])){ | ||
| 110 | - $title = $this->param['title']; | ||
| 111 | - foreach ($title as $v){ | 109 | + try { |
| 110 | + $idArr = []; | ||
| 111 | + foreach ($this->param['title'] as $v){ | ||
| 112 | + $info = $this->model->read(['title'=>$v]); | ||
| 113 | + if($info === false){ | ||
| 112 | $param['project_id'] = $this->user['project_id']; | 114 | $param['project_id'] = $this->user['project_id']; |
| 113 | $param['created_at'] = date('Y-m-d H:i:s'); | 115 | $param['created_at'] = date('Y-m-d H:i:s'); |
| 114 | $param['updated_at'] = $param['created_at']; | 116 | $param['updated_at'] = $param['created_at']; |
| 115 | $param['title'] = $v; | 117 | $param['title'] = $v; |
| 116 | $id = $this->model->insertGetId($param); | 118 | $id = $this->model->insertGetId($param); |
| 117 | - $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); | ||
| 118 | - $this->model->edit(['route'=>$route],['id'=>$id]); | 119 | + $idArr[] = ['id'=>$id,'title'=>$v]; |
| 120 | + } | ||
| 119 | } | 121 | } |
| 122 | + //批量生成路由 | ||
| 123 | + foreach ($idArr as $v){ | ||
| 124 | + $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']); | ||
| 125 | + $this->model->edit(['route'=>$route],['id'=>$v['id']]); | ||
| 126 | + } | ||
| 127 | + }catch (\Exception $e){ | ||
| 128 | + $this->fail('error'); | ||
| 120 | } | 129 | } |
| 121 | return $this->success(); | 130 | return $this->success(); |
| 122 | } | 131 | } |
-
请 注册 或 登录 后发表评论