作者 zhl

添加指令

@@ -409,6 +409,7 @@ class UpdateSeoTdk extends Command @@ -409,6 +409,7 @@ class UpdateSeoTdk extends Command
409 } 409 }
410 410
411 public function getPrompt($project_id, $prompt, $table, $data){ 411 public function getPrompt($project_id, $prompt, $table, $data){
  412 + // topic
412 if(strpos($prompt, '{topic}') !== false){ 413 if(strpos($prompt, '{topic}') !== false){
413 $topic = $data[$this->topic_fields[$table]] ?? ''; 414 $topic = $data[$this->topic_fields[$table]] ?? '';
414 if(!$topic){ 415 if(!$topic){
@@ -417,6 +418,7 @@ class UpdateSeoTdk extends Command @@ -417,6 +418,7 @@ class UpdateSeoTdk extends Command
417 } 418 }
418 $prompt = str_replace('{topic}', $topic, $prompt); 419 $prompt = str_replace('{topic}', $topic, $prompt);
419 } 420 }
  421 + // keyword
420 if(strpos($prompt, '{keyword}') !== false) { 422 if(strpos($prompt, '{keyword}') !== false) {
421 $keyword = $this->mainKeywords($project_id, 1); 423 $keyword = $this->mainKeywords($project_id, 1);
422 if(!$keyword){ 424 if(!$keyword){
@@ -425,6 +427,7 @@ class UpdateSeoTdk extends Command @@ -425,6 +427,7 @@ class UpdateSeoTdk extends Command
425 } 427 }
426 $prompt = str_replace('{keyword}', $keyword, $prompt); 428 $prompt = str_replace('{keyword}', $keyword, $prompt);
427 } 429 }
  430 + // company name
428 if(strpos($prompt, '{company name}') !== false) { 431 if(strpos($prompt, '{company name}') !== false) {
429 $company_name = $this->companyName($project_id); 432 $company_name = $this->companyName($project_id);
430 if(!$company_name){ 433 if(!$company_name){
@@ -433,17 +436,71 @@ class UpdateSeoTdk extends Command @@ -433,17 +436,71 @@ class UpdateSeoTdk extends Command
433 } 436 }
434 $prompt = str_replace('{company name}', $company_name, $prompt); 437 $prompt = str_replace('{company name}', $company_name, $prompt);
435 } 438 }
  439 + // company detail
  440 + if(strpos($prompt, '{company detail}') !== false) {
  441 + $company_detail = $this->companyName($project_id, 'company_detail');
  442 + if(!$company_detail){
  443 + echo '公司英文描述为空 跳过' . PHP_EOL;
  444 + return false;
  445 + }
  446 + $prompt = str_replace('{company detail}', $company_detail, $prompt);
  447 + }
  448 + // 前缀关键词
  449 + if(preg_match_all("/\{qz_(\d+)\}/", $prompt, $matches)) {
  450 + foreach ($matches[0] as $key=>$val) {
  451 + $keyword = $this->getPrefixKeyword($project_id, 'prefix', $matches[1][$key]);
  452 + if(!$keyword){
  453 + echo '前缀关键词为空 跳过' . PHP_EOL;
  454 + return false;
  455 + }
  456 + $prompt = str_replace($val, $keyword, $prompt);
  457 + }
  458 + }
  459 + // 后缀关键词
  460 + if(preg_match_all("/\{hz_(\d+)\}/", $prompt, $matches)) {
  461 + foreach ($matches[0] as $key=>$val) {
  462 + $keyword = $this->getPrefixKeyword($project_id, 'suffix', $matches[1][$key]);
  463 + if(!$keyword){
  464 + echo '前缀关键词为空 跳过' . PHP_EOL;
  465 + return false;
  466 + }
  467 + $prompt = str_replace($val, $keyword, $prompt);
  468 + }
  469 + }
436 $prompt .= '.Please answer in ' . $this->getLang(); 470 $prompt .= '.Please answer in ' . $this->getLang();
437 return $prompt; 471 return $prompt;
438 } 472 }
439 473
  474 + /**
  475 + * 获取前后缀
  476 + * @param $project_id
  477 + * @param $type
  478 + * @param $num
  479 + * @return string
  480 + */
  481 + public function getPrefixKeyword($project_id, $type, $num)
  482 + {
  483 + $str = '';
  484 + $info = $this->getDeployOptimize($project_id);
  485 + if (!empty($info['keyword_' . $type])) {
  486 + $fix_keyword = explode(",", $info['keyword_' . $type]);
  487 + //随机取
  488 + shuffle($fix_keyword);
  489 + if (count($fix_keyword) < $num)
  490 + return $str;
  491 + $keyword = array_slice($fix_keyword, 0, $num);
  492 + $str = implode(", ", $keyword);
  493 + }
  494 + return $str;
  495 + }
  496 +
440 497
441 public function getDeployOptimize($project_id){ 498 public function getDeployOptimize($project_id){
442 $cache_key = 'project_deploy_optimize_info_' . $project_id; 499 $cache_key = 'project_deploy_optimize_info_' . $project_id;
443 $info = Cache::get($cache_key); 500 $info = Cache::get($cache_key);
444 if(!$info){ 501 if(!$info){
445 $projectOptimizeModel = new DeployOptimize(); 502 $projectOptimizeModel = new DeployOptimize();
446 - $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description']); 503 + $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'keyword_prefix', 'keyword_suffix']);
447 $projectKeywordModel = new ProjectKeyword(); 504 $projectKeywordModel = new ProjectKeyword();
448 $keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]); 505 $keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]);
449 $info['main_keyword'] = ''; 506 $info['main_keyword'] = '';
@@ -466,6 +523,7 @@ class UpdateSeoTdk extends Command @@ -466,6 +523,7 @@ class UpdateSeoTdk extends Command
466 { 523 {
467 $data = [ 524 $data = [
468 'product_long_description', 525 'product_long_description',
  526 + 'company_detail'
469 ]; 527 ];
470 $info = $this->getDeployOptimize($project_id); 528 $info = $this->getDeployOptimize($project_id);
471 if (in_array($key, $data)) { 529 if (in_array($key, $data)) {
@@ -56,6 +56,10 @@ class AiCommandLogic extends BaseLogic @@ -56,6 +56,10 @@ class AiCommandLogic extends BaseLogic
56 $prompt = ''; 56 $prompt = '';
57 } 57 }
58 } 58 }
  59 + if(strpos($prompt, '{company detail}') !== false) {
  60 + $company_introduction = $this->getDeployOptimize('company_en_description');
  61 + $prompt = str_replace('{company detail}', $company_introduction, $prompt);
  62 + }
59 63
60 if(trim($ai_command->ai) == '{core keywords 8}'){ 64 if(trim($ai_command->ai) == '{core keywords 8}'){
61 $ai_send = false; 65 $ai_send = false;
@@ -100,7 +104,7 @@ class AiCommandLogic extends BaseLogic @@ -100,7 +104,7 @@ class AiCommandLogic extends BaseLogic
100 $info = Cache::get($cache_key); 104 $info = Cache::get($cache_key);
101 if(!$info){ 105 if(!$info){
102 $projectOptimizeModel = new DeployOptimize(); 106 $projectOptimizeModel = new DeployOptimize();
103 - $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description']); 107 + $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'keyword_prefix', 'keyword_suffix']);
104 $projectKeywordModel = new ProjectKeyword(); 108 $projectKeywordModel = new ProjectKeyword();
105 $keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]); 109 $keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]);
106 $info['main_keyword'] = ''; 110 $info['main_keyword'] = '';