作者 lyh

gx

@@ -10,7 +10,10 @@ @@ -10,7 +10,10 @@
10 namespace App\Http\Logic\Aside\Project; 10 namespace App\Http\Logic\Aside\Project;
11 11
12 use App\Http\Logic\Aside\BaseLogic; 12 use App\Http\Logic\Aside\BaseLogic;
  13 +use App\Models\Product\Keyword;
13 use App\Models\Project\AggregateKeyword; 14 use App\Models\Project\AggregateKeyword;
  15 +use App\Services\ProjectServer;
  16 +use Illuminate\Support\Facades\DB;
14 17
15 class AggregateKeywordLogic extends BaseLogic 18 class AggregateKeywordLogic extends BaseLogic
16 { 19 {
@@ -22,7 +25,7 @@ class AggregateKeywordLogic extends BaseLogic @@ -22,7 +25,7 @@ class AggregateKeywordLogic extends BaseLogic
22 } 25 }
23 26
24 /** 27 /**
25 - * @remark : 28 + * @remark :保存关键词
26 * @name :saveKeyword 29 * @name :saveKeyword
27 * @author :lyh 30 * @author :lyh
28 * @method :post 31 * @method :post
@@ -34,7 +37,16 @@ class AggregateKeywordLogic extends BaseLogic @@ -34,7 +37,16 @@ class AggregateKeywordLogic extends BaseLogic
34 $this->model->edit($this->param,['id'=>$this->param['id']]); 37 $this->model->edit($this->param,['id'=>$this->param['id']]);
35 }else{ 38 }else{
36 $id = $this->model->addReturnId($this->param); 39 $id = $this->model->addReturnId($this->param);
  40 + //保存到客户关键词
  41 + $keywords = explode("\n", $this->param['keywords']);
  42 + if(!empty($keywords)){
  43 + ProjectServer::useProject($this->param['project_id']);
  44 + $keywordModel = new Keyword();
  45 + $keywordModel->saveBKeyword($this->param['keyword'],$keywords);
  46 + DB::disconnect('custom_mysql');
  47 + }
37 } 48 }
38 return $this->success(['id'=>$id]); 49 return $this->success(['id'=>$id]);
39 } 50 }
  51 +
40 } 52 }
@@ -79,8 +79,8 @@ class KeywordLogic extends BaseLogic @@ -79,8 +79,8 @@ class KeywordLogic extends BaseLogic
79 if($info !== false){ 79 if($info !== false){
80 return $this->success(['id'=>$info['id']]); 80 return $this->success(['id'=>$info['id']]);
81 } 81 }
82 - $this->param = $this->addHandleParam($this->param);  
83 - $id = $this->model->insertGetId($this->param); 82 + $this->param['project_id'] = $this->user['project_id'];
  83 + $id = $this->model->addReturnId($this->param);
84 //路由映射 84 //路由映射
85 $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); 85 $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
86 $this->model->edit(['route'=>$route],['id'=>$id]); 86 $this->model->edit(['route'=>$route],['id'=>$id]);
@@ -93,20 +93,6 @@ class KeywordLogic extends BaseLogic @@ -93,20 +93,6 @@ class KeywordLogic extends BaseLogic
93 } 93 }
94 94
95 /** 95 /**
96 - * @remark :添加组装数据  
97 - * @name :addHandleParam  
98 - * @author :lyh  
99 - * @method :post  
100 - * @time :2023/11/30 15:00  
101 - */  
102 - public function addHandleParam($param){  
103 - $param['project_id'] = $this->user['project_id'];  
104 - $param['created_at'] = date('Y-m-d H:i:s');  
105 - $param['updated_at'] = $param['created_at'];  
106 - return $this->success($param);  
107 - }  
108 -  
109 - /**  
110 * @remark :保存数据时参数处理 96 * @remark :保存数据时参数处理
111 * @name :handleSaveParam 97 * @name :handleSaveParam
112 * @author :lyh 98 * @author :lyh
@@ -135,27 +121,11 @@ class KeywordLogic extends BaseLogic @@ -135,27 +121,11 @@ class KeywordLogic extends BaseLogic
135 if(!empty($param['seo_title'])){ 121 if(!empty($param['seo_title'])){
136 $param['seo_title'] = ucfirst($param['seo_title']); 122 $param['seo_title'] = ucfirst($param['seo_title']);
137 } 123 }
138 - $param['first_word'] = $this->first_word($param['title']); 124 + $param['first_word'] = $this->model->first_word($param['title']);
139 return $param; 125 return $param;
140 } 126 }
141 127
142 /** 128 /**
143 - * @remark :获取字符串首字符  
144 - * @name :first_word  
145 - * @author :lyh  
146 - * @method :post  
147 - * @time :2024/10/28 10:47  
148 - */  
149 - public function first_word($title){  
150 - $first_title = mb_substr(strtolower($title), 0, 1);  
151 - if (is_numeric($first_title)){  
152 - return 0;  
153 - }  
154 - $string_key = array_search($first_title, $this->model->firstNumWord);  
155 - return $string_key ?: 27;  
156 - }  
157 -  
158 - /**  
159 * @remark :批量添加关键词任务, 异步处理 129 * @remark :批量添加关键词任务, 异步处理
160 * @name :batchAdd 130 * @name :batchAdd
161 * @author :lyh 131 * @author :lyh
@@ -164,20 +134,7 @@ class KeywordLogic extends BaseLogic @@ -164,20 +134,7 @@ class KeywordLogic extends BaseLogic
164 */ 134 */
165 public function batchAdd(){ 135 public function batchAdd(){
166 try { 136 try {
167 - foreach ($this->param['title'] as $k=>$v){  
168 - if(empty($v)){  
169 - continue;  
170 - }  
171 - $info = $this->model->read(['title'=>$v],['id']);  
172 - if($info === false){  
173 - $param['project_id'] = $this->user['project_id'];  
174 - $param['created_at'] = date('Y-m-d H:i:s');  
175 - $param['updated_at'] = $param['created_at'];  
176 - $param['title'] = $v;  
177 - $param['first_word'] = $this->first_word($param['title']);  
178 - $this->model->insertGetId($param);  
179 - }  
180 - } 137 + $this->model->saveBKeyword($this->user['project_id'],$this->param['title']);
181 }catch (\Exception $e){ 138 }catch (\Exception $e){
182 $this->fail('保存失败,请联系管理员'); 139 $this->fail('保存失败,请联系管理员');
183 } 140 }
@@ -249,7 +206,7 @@ class KeywordLogic extends BaseLogic @@ -249,7 +206,7 @@ class KeywordLogic extends BaseLogic
249 if($v){ 206 if($v){
250 $keyword_info = $this->model->read(['title'=>$v]); 207 $keyword_info = $this->model->read(['title'=>$v]);
251 if(!$keyword_info){ 208 if(!$keyword_info){
252 - $k_id = $this->model->addReturnId(['title'=>$v,'first_word' => $this->first_word($v),'project_id'=>$project_id]); 209 + $k_id = $this->model->addReturnId(['title'=>$v,'first_word' => $this->model->first_word($v),'project_id'=>$project_id]);
253 $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $k_id, $project_id); 210 $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $k_id, $project_id);
254 $this->model->edit(['route'=>$route],['id'=>$k_id]); 211 $this->model->edit(['route'=>$route],['id'=>$k_id]);
255 }else{ 212 }else{
@@ -3,8 +3,13 @@ @@ -3,8 +3,13 @@
3 namespace App\Models\Product; 3 namespace App\Models\Product;
4 4
5 use App\Helper\Arr; 5 use App\Helper\Arr;
  6 +use App\Helper\Common;
6 use App\Models\Base; 7 use App\Models\Base;
  8 +use App\Models\Com\NoticeLog;
  9 +use App\Models\RouteMap\RouteMap;
  10 +use App\Services\ProjectServer;
7 use Illuminate\Database\Eloquent\SoftDeletes; 11 use Illuminate\Database\Eloquent\SoftDeletes;
  12 +use Illuminate\Support\Facades\DB;
8 13
9 class Keyword extends Base 14 class Keyword extends Base
10 { 15 {
@@ -149,4 +154,44 @@ class Keyword extends Base @@ -149,4 +154,44 @@ class Keyword extends Base
149 } 154 }
150 return $result; 155 return $result;
151 } 156 }
  157 +
  158 + /**
  159 + * @remark :保存到产品关键词中
  160 + * @name :saveBKeyword
  161 + * @author :lyh
  162 + * @method :post
  163 + * @time :2025/3/25 16:28
  164 + */
  165 + public function saveBKeyword($project_id,$keywords){
  166 + foreach ($keywords as $v){
  167 + if(empty($v)){
  168 + continue;
  169 + }
  170 + $info = $this->read(['title'=>$v],['id']);
  171 + if($info === false){
  172 + $param['project_id'] = $project_id;
  173 + $param['title'] = $v;
  174 + $param['first_word'] = $this->first_word($param['title']);
  175 + $this->addReturnId($param);
  176 + }
  177 + }
  178 + NoticeLog::createLog(NoticeLog::TYPE_INIT_KEYWORD, ['project_id' => $this->user['project_id']]);
  179 + return true;
  180 + }
  181 +
  182 + /**
  183 + * @remark :获取字符串首字符
  184 + * @name :first_word
  185 + * @author :lyh
  186 + * @method :post
  187 + * @time :2025/3/25 16:42
  188 + */
  189 + public function first_word($title){
  190 + $first_title = mb_substr(strtolower($title), 0, 1);
  191 + if (is_numeric($first_title)){
  192 + return 0;
  193 + }
  194 + $string_key = array_search($first_title, $this->model->firstNumWord);
  195 + return $string_key ?: 27;
  196 + }
152 } 197 }