作者 lyh

gx

@@ -61,17 +61,19 @@ class UpdateSeoTdk extends Command @@ -61,17 +61,19 @@ class UpdateSeoTdk extends Command
61 try { 61 try {
62 ProjectServer::useProject($project_id); 62 ProjectServer::useProject($project_id);
63 $this->updateProduct($project_id); 63 $this->updateProduct($project_id);
  64 + $this->updateProductCate($project_id);
64 $this->updateBlogs($project_id); 65 $this->updateBlogs($project_id);
  66 + $this->updateBlogCate($project_id);
65 $this->updateNews($project_id); 67 $this->updateNews($project_id);
  68 + $this->updateNewsCate($project_id);
  69 + $this->updatePage($project_id);
66 DB::disconnect('custom_mysql'); 70 DB::disconnect('custom_mysql');
67 }catch (\Exception $e){ 71 }catch (\Exception $e){
68 echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL; 72 echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
69 } 73 }
70 -  
71 echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL; 74 echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
72 } 75 }
73 } 76 }
74 -  
75 /** 77 /**
76 * @remark :更新产品tdk 78 * @remark :更新产品tdk
77 * @name :updateProduct 79 * @name :updateProduct
@@ -112,6 +114,44 @@ class UpdateSeoTdk extends Command @@ -112,6 +114,44 @@ class UpdateSeoTdk extends Command
112 } 114 }
113 115
114 /** 116 /**
  117 + * @remark :更新产品tdk
  118 + * @name :updateProduct
  119 + * @author :lyh
  120 + * @method :post
  121 + * @time :2023/8/19 9:25
  122 + */
  123 + public function updateProductCate($project_id){
  124 + $list = DB::connection('custom_mysql')->table('gl_product_category')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
  125 + if(!empty($list)){
  126 + foreach ($list as $v){
  127 + $v = (array)$v;
  128 + $data = [];
  129 + if(empty($v['seo_title'])){
  130 + $setting = DB::connection('custom_mysql')->table('gl_web_setting_seo')->where(['project_id'=>$project_id])->first()->toArray();
  131 + //生成seo_title
  132 + if(!empty($setting['product_cate_prefix']) && !empty($setting['product_cate_suffix'])){
  133 + $data['seo_title'] = $setting['product_cate_prefix'] . '-' . $v['title'] . '-' . $setting['product_cate_suffix'];
  134 + }else{
  135 + $data['seo_title'] = $this->ai_send('seo_title',$v['title']);
  136 + }
  137 + }
  138 + if(empty($v['seo_keywords'])){
  139 + $data['seo_keywords'] = $this->ai_send('seo_keywords',$v['title']);
  140 + }
  141 + if(empty($v['seo_des'])){
  142 + $name = $this->companyName($project_id);
  143 + $data['seo_des'] = $this->ai_send('page_meta_description',$v['title'],$name);
  144 + }
  145 + if(!$data){
  146 + continue;
  147 + }
  148 + DB::connection('custom_mysql')->table('gl_news')->where(['id'=>$v['id']])->update($data);
  149 + }
  150 + }
  151 + return true;
  152 + }
  153 +
  154 + /**
115 * @remark :更新新闻Tdk 155 * @remark :更新新闻Tdk
116 * @name :updateNews 156 * @name :updateNews
117 * @author :lyh 157 * @author :lyh
@@ -149,6 +189,44 @@ class UpdateSeoTdk extends Command @@ -149,6 +189,44 @@ class UpdateSeoTdk extends Command
149 } 189 }
150 190
151 /** 191 /**
  192 + * @remark :更新新闻Tdk
  193 + * @name :updateNews
  194 + * @author :lyh
  195 + * @method :post
  196 + * @time :2023/8/19 10:06
  197 + */
  198 + public function updateNewsCate($project_id){
  199 + $list = DB::connection('custom_mysql')->table('gl_news_category')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
  200 + if(!empty($list)){
  201 + foreach ($list as $k => $v){
  202 + $v = (array)$v;
  203 + $data = [];
  204 + if(empty($v['seo_title'])){
  205 + $setting = DB::connection('custom_mysql')->table('gl_web_setting_seo')->where(['project_id'=>$project_id])->first()->toArray();
  206 + //生成seo_title
  207 + if(!empty($setting['single_page_suffix'])){
  208 + $data['seo_title'] = $v['name'] . '-' . $setting['single_page_suffix'];
  209 + }else{
  210 + $data['seo_title'] = $this->ai_send('seo_title',$v['name']);
  211 + }
  212 + }
  213 + if(empty($v['seo_keywords'])){
  214 + $data['seo_keywords'] = $this->ai_send('seo_keywords',$v['name']);
  215 + }
  216 + if(empty($v['seo_des'])){
  217 + $name = $this->companyName($project_id);
  218 + $data['seo_des'] = $this->ai_send('page_meta_description',$v['title'],$name);
  219 + }
  220 + if(!$data){
  221 + continue;
  222 + }
  223 + DB::connection('custom_mysql')->table('gl_news')->where(['id'=>$v['id']])->update($data);
  224 + }
  225 + }
  226 + return true;
  227 + }
  228 +
  229 + /**
152 * @remark :更新blogTdk 230 * @remark :更新blogTdk
153 * @name :updateBlogs 231 * @name :updateBlogs
154 * @author :lyh 232 * @author :lyh
@@ -186,6 +264,44 @@ class UpdateSeoTdk extends Command @@ -186,6 +264,44 @@ class UpdateSeoTdk extends Command
186 } 264 }
187 265
188 /** 266 /**
  267 + * @remark :更新新闻Tdk
  268 + * @name :updateNews
  269 + * @author :lyh
  270 + * @method :post
  271 + * @time :2023/8/19 10:06
  272 + */
  273 + public function updateBlogCate($project_id){
  274 + $list = DB::connection('custom_mysql')->table('gl_blog_category')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
  275 + if(!empty($list)){
  276 + foreach ($list as $k => $v){
  277 + $v = (array)$v;
  278 + $data = [];
  279 + if(empty($v['seo_title'])){
  280 + $setting = DB::connection('custom_mysql')->table('gl_web_setting_seo')->where(['project_id'=>$project_id])->first()->toArray();
  281 + //生成seo_title
  282 + if(!empty($setting['single_page_suffix'])){
  283 + $data['seo_title'] = $v['name'] . '-' . $setting['single_page_suffix'];
  284 + }else{
  285 + $data['seo_title'] = $this->ai_send('seo_title',$v['name']);
  286 + }
  287 + }
  288 + if(empty($v['seo_keywords'])){
  289 + $data['seo_keywords'] = $this->ai_send('seo_keywords',$v['name']);
  290 + }
  291 + if(empty($v['seo_des'])){
  292 + $name = $this->companyName($project_id);
  293 + $data['seo_des'] = $this->ai_send('page_meta_description',$v['title'],$name);
  294 + }
  295 + if(!$data){
  296 + continue;
  297 + }
  298 + DB::connection('custom_mysql')->table('gl_news')->where(['id'=>$v['id']])->update($data);
  299 + }
  300 + }
  301 + return true;
  302 + }
  303 +
  304 + /**
189 * @remark :单页面更新tdk 305 * @remark :单页面更新tdk
190 * @name :updatePage 306 * @name :updatePage
191 * @author :lyh 307 * @author :lyh
@@ -208,11 +324,17 @@ class UpdateSeoTdk extends Command @@ -208,11 +324,17 @@ class UpdateSeoTdk extends Command
208 } 324 }
209 } 325 }
210 if(empty($v['keywords'])){ 326 if(empty($v['keywords'])){
211 - // 327 + //获取核心关键词
  328 + $main_keyword = $this->mainKeywords($project_id);
  329 + if(!empty($main_keyword)){
  330 + $data['keywords'] = $this->ai_send('seo_keywords',$main_keyword);
  331 + }else{
212 $data['keywords'] = $this->ai_send('seo_keywords',$v['title']); 332 $data['keywords'] = $this->ai_send('seo_keywords',$v['title']);
213 } 333 }
  334 + }
214 if(empty($v['description'])){ 335 if(empty($v['description'])){
215 - $data['description'] = $this->ai_send('page_meta_description',$v['title']); 336 + $name = $this->companyName($project_id);
  337 + $data['description'] = $this->ai_send('page_meta_description',$v['title'],$name);
216 } 338 }
217 if(!$data){ 339 if(!$data){
218 continue; 340 continue;
@@ -237,16 +359,20 @@ class UpdateSeoTdk extends Command @@ -237,16 +359,20 @@ class UpdateSeoTdk extends Command
237 359
238 /** 360 /**
239 * @remark :获取公司核心关键词 361 * @remark :获取公司核心关键词
240 - * @name :companyName 362 + * @name :mainKeywords
241 * @author :lyh 363 * @author :lyh
242 * @method :post 364 * @method :post
243 * @time :2023/10/30 11:22 365 * @time :2023/10/30 11:22
244 */ 366 */
245 public function mainKeywords($project_id){ 367 public function mainKeywords($project_id){
  368 + $str = '';
246 $projectOptimizeModel = new DeployOptimize(); 369 $projectOptimizeModel = new DeployOptimize();
247 $info = $projectOptimizeModel->read(['project_id'=>$project_id],['id','main_keywords']); 370 $info = $projectOptimizeModel->read(['project_id'=>$project_id],['id','main_keywords']);
248 - explode(',',$info[])  
249 - return $info['company']; 371 + if($info === false){
  372 + $arr = explode(',',$info['main_keywords']);
  373 + $str = $arr[0];
  374 + }
  375 + return $str;
250 } 376 }
251 377
252 /** 378 /**
@@ -256,13 +382,13 @@ class UpdateSeoTdk extends Command @@ -256,13 +382,13 @@ class UpdateSeoTdk extends Command
256 * @method :post 382 * @method :post
257 * @time :2023/8/19 10:40 383 * @time :2023/8/19 10:40
258 */ 384 */
259 - public function ai_send($key,$keywords){ 385 + public function ai_send($key,$keywords,$name = ''){
260 $chat_url = 'v2/openai_chat_qqs'; 386 $chat_url = 'v2/openai_chat_qqs';
261 $param = [ 387 $param = [
262 'key'=>$key, 388 'key'=>$key,
263 'keywords'=>$keywords, 389 'keywords'=>$keywords,
264 ]; 390 ];
265 - $data = Common::send_openai_msg($chat_url,$param); 391 + $data = Common::send_openai_msg($chat_url,$param,$name);
266 return $data['text']; 392 return $data['text'];
267 } 393 }
268 394
@@ -186,4 +186,38 @@ class Common @@ -186,4 +186,38 @@ class Common
186 return $crypt->decrypt($string); 186 return $crypt->decrypt($string);
187 } 187 }
188 188
  189 + //处理关键词
  190 + public function deal_keywords($data){
  191 + $str = ['1. ','2. ','3. ','4. ','5. ','6. ','7. ','8. ','1) ','2) ','3) ','4) ','5) ','6) ','7) ','7) ','8) '];
  192 + $ar_keywords_t = explode("\n",$data);
  193 + $ar_keywords = [];
  194 + foreach ($ar_keywords_t as $v){
  195 + if(trim($v)){
  196 + $keyword = trim($v);
  197 + if(strpos($keyword,'search keyword') !== false){
  198 + $tmp_first = explode('1. ',$keyword);
  199 + if(count($tmp_first) > 1){
  200 + $keyword = $tmp_first[1];
  201 + }else{
  202 + $tmp_first = explode('1) ',$keyword);
  203 + if(count($tmp_first) > 1){
  204 + $keyword = $tmp_first[1];
  205 + }
  206 + }
  207 + }
  208 + $keyword = str_replace($str,'',$keyword);
  209 + $keyword = trim($keyword,'.');
  210 + if(strpos(strtolower($keyword),'hope') === false && strpos(strtolower($keyword),'remember') === false && strpos(strtolower($keyword),'help') === false && strpos(strtolower($keyword),'website') === false && strpos(strtolower($keyword),'search keywords') === false && strpos(strtolower($keyword),'here are 8') === false && strpos(strtolower($keyword),'search keywords') === false && strpos(strtolower($keyword),'thank you') === false && strpos(strtolower($keyword),'thanks') === false && strpos(strtolower($keyword),'copywriter') === false ){
  211 + $ar_keywords[] = $keyword;
  212 + }
  213 + }
  214 + }
  215 + return implode(',',$ar_keywords);
  216 + }
  217 +
  218 +
  219 +//过滤特殊字符
  220 + public function deal_str($str){
  221 + return str_replace(['{','}','”','“','"'],'',$str);
  222 + }
189 } 223 }
@@ -54,38 +54,4 @@ class AiCommandController extends BaseController @@ -54,38 +54,4 @@ class AiCommandController extends BaseController
54 return $aiLog->add($param); 54 return $aiLog->add($param);
55 } 55 }
56 56
57 - //处理关键词  
58 - public function deal_keywords($data){  
59 - $str = ['1. ','2. ','3. ','4. ','5. ','6. ','7. ','8. ','1) ','2) ','3) ','4) ','5) ','6) ','7) ','7) ','8) '];  
60 - $ar_keywords_t = explode("\n",$data);  
61 - $ar_keywords = [];  
62 - foreach ($ar_keywords_t as $v){  
63 - if(trim($v)){  
64 - $keyword = trim($v);  
65 - if(strpos($keyword,'search keyword') !== false){  
66 - $tmp_first = explode('1. ',$keyword);  
67 - if(count($tmp_first) > 1){  
68 - $keyword = $tmp_first[1];  
69 - }else{  
70 - $tmp_first = explode('1) ',$keyword);  
71 - if(count($tmp_first) > 1){  
72 - $keyword = $tmp_first[1];  
73 - }  
74 - }  
75 - }  
76 - $keyword = str_replace($str,'',$keyword);  
77 - $keyword = trim($keyword,'.');  
78 - if(strpos(strtolower($keyword),'hope') === false && strpos(strtolower($keyword),'remember') === false && strpos(strtolower($keyword),'help') === false && strpos(strtolower($keyword),'website') === false && strpos(strtolower($keyword),'search keywords') === false && strpos(strtolower($keyword),'here are 8') === false && strpos(strtolower($keyword),'search keywords') === false && strpos(strtolower($keyword),'thank you') === false && strpos(strtolower($keyword),'thanks') === false && strpos(strtolower($keyword),'copywriter') === false ){  
79 - $ar_keywords[] = $keyword;  
80 - }  
81 - }  
82 - }  
83 - return implode(',',$ar_keywords);  
84 - }  
85 -  
86 -  
87 -//过滤特殊字符  
88 - public function deal_str($str){  
89 - return str_replace(['{','}','”','“','"'],'',$str);  
90 - }  
91 } 57 }