作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -482,6 +482,19 @@ class RelayInquiry extends Command @@ -482,6 +482,19 @@ class RelayInquiry extends Command
482 $this->output('转发内容'); 482 $this->output('转发内容');
483 $form_message = $message; 483 $form_message = $message;
484 $message_id = 0; 484 $message_id = 0;
  485 +
  486 + // TODO 当原始询盘内容长度大于15个字符, 直接发送原始内容。
  487 + if (strlen($message) >= 15) {
  488 + //原内容非英语,转为对应语种
  489 + if (is_numeric($form_message)) { //数字会被识别为中文
  490 + $lang = 'en';
  491 + } else {
  492 + $translateSl = Translate::translateSl($form_message);
  493 + $lang = $translateSl['texts']['sl'] ?? 'en';
  494 + }
  495 + return [$message, $message_id, $lang??''];
  496 + }
  497 +
485 //开启文案替换 498 //开启文案替换
486 if ($task['is_replace_text'] == 2) { 499 if ($task['is_replace_text'] == 2) {
487 //AI生成 500 //AI生成
@@ -82,9 +82,9 @@ class DownloadProject extends Command @@ -82,9 +82,9 @@ class DownloadProject extends Command
82 if($v['type'] == 1){ 82 if($v['type'] == 1){
83 $status = '建站中'; 83 $status = '建站中';
84 }elseif ($v['type'] == 2){ 84 }elseif ($v['type'] == 2){
85 - $status = '建站后';  
86 - }elseif ($v['type'] == 3){  
87 $status = '优化中'; 85 $status = '优化中';
  86 + }elseif ($v['type'] == 3){
  87 + $status = '建站后';
88 }else{ 88 }else{
89 $status = ''; 89 $status = '';
90 } 90 }
@@ -252,7 +252,7 @@ class UpdateSeoTdk extends Command @@ -252,7 +252,7 @@ class UpdateSeoTdk extends Command
252 if($table == 'gl_product'){ 252 if($table == 'gl_product'){
253 foreach ($map as $field){ 253 foreach ($map as $field){
254 $field_arr = explode('.', $field); 254 $field_arr = explode('.', $field);
255 - $query->orWhereRaw('JSON_CONTAINS('.$field_arr[0].', "null", "$.'.$field_arr[1].'") OR JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") = ""'); 255 + $query->whereNull('seo_mate')->orWhereRaw('JSON_CONTAINS('.$field_arr[0].', "null", "$.'.$field_arr[1].'") OR JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") = ""');
256 } 256 }
257 }else{ 257 }else{
258 foreach ($map as $field){ 258 foreach ($map as $field){
@@ -213,7 +213,16 @@ class Common @@ -213,7 +213,16 @@ class Common
213 } 213 }
214 $keyword = str_replace($str,'',$keyword); 214 $keyword = str_replace($str,'',$keyword);
215 $keyword = trim($keyword,'.'); 215 $keyword = trim($keyword,'.');
216 - 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 ){ 216 + if(strpos(strtolower($keyword),'hope') === false
  217 + && (strpos(strtolower($keyword),'remember') === false || strpos(strtolower($keyword),'rememberance') !== false)
  218 + && strpos(strtolower($keyword),'help') === false
  219 + && strpos(strtolower($keyword),'website') === false
  220 + && strpos(strtolower($keyword),'search keywords') === false
  221 + && strpos(strtolower($keyword),'here are 8') === false
  222 + && strpos(strtolower($keyword),'search keywords') === false
  223 + && strpos(strtolower($keyword),'thank you') === false
  224 + && (strpos(strtolower($keyword),'thanks') === false || strpos(strtolower($keyword),'thanksgiving') !== false)
  225 + && strpos(strtolower($keyword),'copywriter') === false ){
217 $ar_keywords[] = $keyword; 226 $ar_keywords[] = $keyword;
218 } 227 }
219 } 228 }
@@ -224,6 +233,7 @@ class Common @@ -224,6 +233,7 @@ class Common
224 233
225 //过滤特殊字符 234 //过滤特殊字符
226 public static function deal_str($str){ 235 public static function deal_str($str){
  236 + $str = str_replace([',,'],',',$str);
227 return str_replace(['{','}','”','“','"'],'',$str); 237 return str_replace(['{','}','”','“','"'],'',$str);
228 } 238 }
229 239
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 2
3 use App\Models\File\Image; 3 use App\Models\File\Image;
4 use App\Models\File\File as FileModel; 4 use App\Models\File\File as FileModel;
  5 +use App\Models\Project\DeployOptimize;
  6 +use App\Models\Project\ProjectKeyword;
5 use App\Models\RouteMap\RouteMap; 7 use App\Models\RouteMap\RouteMap;
6 use App\Services\CosService; 8 use App\Services\CosService;
7 use App\Utils\EncryptUtils; 9 use App\Utils\EncryptUtils;
@@ -9,6 +11,7 @@ use App\Utils\LogUtils; @@ -9,6 +11,7 @@ use App\Utils\LogUtils;
9 use GuzzleHttp\Client; 11 use GuzzleHttp\Client;
10 use GuzzleHttp\Exception\GuzzleException; 12 use GuzzleHttp\Exception\GuzzleException;
11 use Illuminate\Support\Carbon; 13 use Illuminate\Support\Carbon;
  14 +use Illuminate\Support\Facades\Cache;
12 use Illuminate\Support\Facades\Redis; 15 use Illuminate\Support\Facades\Redis;
13 16
14 define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/'); 17 define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
@@ -1081,5 +1084,50 @@ function getRandByRatio($proArr){ @@ -1081,5 +1084,50 @@ function getRandByRatio($proArr){
1081 } 1084 }
1082 1085
1083 1086
  1087 +/**
  1088 + * @remark :随机获取前后缀
  1089 + * @name :getPrefixKeyword
  1090 + * @author :lyh
  1091 + * @method :post
  1092 + * @time :2025/2/11 14:41
  1093 + */
  1094 +function getPrefixKeyword($project_id, $type, $num)
  1095 +{
  1096 + $str = '';
  1097 + $info = getDeployOptimize($project_id);
  1098 + if (!empty($info['keyword_' . $type])) {
  1099 + $fix_keyword = explode(",", $info['keyword_' . $type]);
  1100 + //随机取
  1101 + shuffle($fix_keyword);
  1102 + if (count($fix_keyword) < $num)
  1103 + return $str;
  1104 + $keyword = array_slice($fix_keyword, 0, $num);
  1105 + $str = implode(", ", $keyword);
  1106 + }
  1107 + return $str;
  1108 +}
1084 1109
  1110 +/**
  1111 + * @remark :获取客户选择的关键词
  1112 + * @name :getDeployOptimize
  1113 + * @author :lyh
  1114 + * @method :post
  1115 + * @time :2025/2/11 14:58
  1116 + */
  1117 +function getDeployOptimize($project_id){
  1118 + $cache_key = 'project_deploy_optimize_info_' . $project_id;
  1119 + $info = Cache::get($cache_key);
  1120 + if(!$info){
  1121 + $projectOptimizeModel = new DeployOptimize();
  1122 + $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'keyword_prefix', 'keyword_suffix']);
  1123 + $projectKeywordModel = new ProjectKeyword();
  1124 + $keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]);
  1125 + $info['main_keyword'] = '';
  1126 + if(!empty($keywordInfo['main_keyword'])){
  1127 + $info['main_keyword'] = $keywordInfo['main_keyword'];
  1128 + }
  1129 + Cache::put($cache_key, $info, 600);
  1130 + }
  1131 + return $info;
  1132 +}
1085 1133
@@ -12,6 +12,8 @@ use App\Models\Ai\AiCommand; @@ -12,6 +12,8 @@ use App\Models\Ai\AiCommand;
12 use App\Models\Ai\AiLog; 12 use App\Models\Ai\AiLog;
13 use App\Models\Project\DeployOptimize; 13 use App\Models\Project\DeployOptimize;
14 use App\Models\Project\Project; 14 use App\Models\Project\Project;
  15 +use App\Models\Project\ProjectKeyword;
  16 +use Illuminate\Support\Facades\Cache;
15 17
16 class AiCommandController extends BaseController 18 class AiCommandController extends BaseController
17 { 19 {
@@ -27,12 +29,21 @@ class AiCommandController extends BaseController @@ -27,12 +29,21 @@ class AiCommandController extends BaseController
27 'keywords.required' => '关键字不能为空', 29 'keywords.required' => '关键字不能为空',
28 'key.required' => '场景不能为空', 30 'key.required' => '场景不能为空',
29 ]); 31 ]);
30 -  
31 - $text = AiCommandLogic::instance()->ai_send();  
32 - $data = [  
33 - 'code' => $text ? 200 : 500,  
34 - 'text' => $text  
35 - ]; 32 + if($this->param['key'] == 'keyword_seo_title'){
  33 + $prefix = getPrefixKeyword($this->user['project_id'], 'prefix', 1);
  34 + $suffix = getPrefixKeyword($this->user['project_id'], 'suffix', 2);
  35 + $text = $prefix . ' ' . $this->param['keywords']. ' ' . $suffix;
  36 + $data = [
  37 + 'code' => 200,
  38 + 'text' => $text
  39 + ];
  40 + }else{
  41 + $text = AiCommandLogic::instance()->ai_send();
  42 + $data = [
  43 + 'code' => $text ? 200 : 500,
  44 + 'text' => $text
  45 + ];
  46 + }
36 $param = [ 47 $param = [
37 'key' => $this->param['key'], 48 'key' => $this->param['key'],
38 'keywords' => $this->param['keywords'], 49 'keywords' => $this->param['keywords'],
@@ -7,6 +7,8 @@ use App\Exceptions\BsideGlobalException; @@ -7,6 +7,8 @@ use App\Exceptions\BsideGlobalException;
7 use App\Helper\Common; 7 use App\Helper\Common;
8 use App\Http\Controllers\Controller; 8 use App\Http\Controllers\Controller;
9 use App\Http\Requests\Scene; 9 use App\Http\Requests\Scene;
  10 +use App\Models\Project\DeployOptimize;
  11 +use App\Models\Project\ProjectKeyword;
10 use App\Models\Template\BTemplate; 12 use App\Models\Template\BTemplate;
11 use App\Models\Template\Setting; 13 use App\Models\Template\Setting;
12 use Illuminate\Http\JsonResponse; 14 use Illuminate\Http\JsonResponse;
@@ -29,30 +29,17 @@ class KeywordPrefixLogic extends BaseLogic @@ -29,30 +29,17 @@ class KeywordPrefixLogic extends BaseLogic
29 * @time :2023/9/6 14:42 29 * @time :2023/9/6 14:42
30 */ 30 */
31 public function prefixSave(){ 31 public function prefixSave(){
32 - if(isset($this->param['id']) && !empty($this->param['id'])){  
33 - $condition = [  
34 - 'keyword'=>$this->param['keyword'],  
35 - 'id'=>['!=',$this->param['id']]  
36 - ];  
37 - $prefixInfo = $this->model->read($condition);  
38 - if($prefixInfo !== false){  
39 - $this->fail('当前关键字已存在');  
40 - }  
41 - $data = [  
42 - 'keyword'=>$this->param['keyword']  
43 - ];  
44 - $this->model->edit($data,['id'=>$this->param['id']]);  
45 - }else{ 32 + $keyword_arr = explode(',',$this->param['keyword']);
  33 + foreach ($keyword_arr as $v){
46 $data = [ 34 $data = [
47 'project_id'=>$this->param['project_id'] ?? 0, 35 'project_id'=>$this->param['project_id'] ?? 0,
48 - 'keyword'=>$this->param['keyword'], 36 + 'keyword'=>$v,
49 'type'=>$this->param['type'] 37 'type'=>$this->param['type']
50 ]; 38 ];
51 $prefixInfo = $this->model->read($data); 39 $prefixInfo = $this->model->read($data);
52 - if($prefixInfo !== false){  
53 - $this->fail('当前关键字已存在'); 40 + if($prefixInfo == false){
  41 + $this->model->add($data);
54 } 42 }
55 - $this->model->add($data);  
56 } 43 }
57 return $this->success(); 44 return $this->success();
58 } 45 }
@@ -31,7 +31,6 @@ class AiCommandLogic extends BaseLogic @@ -31,7 +31,6 @@ class AiCommandLogic extends BaseLogic
31 $this->fail('指令不存在'); 31 $this->fail('指令不存在');
32 } 32 }
33 $prompt = $ai_command->ai; 33 $prompt = $ai_command->ai;
34 -  
35 if(strpos($prompt, '{keyword}') !== false) { 34 if(strpos($prompt, '{keyword}') !== false) {
36 $prompt = str_replace('{keyword}', $this->param['keywords'], $prompt); 35 $prompt = str_replace('{keyword}', $this->param['keywords'], $prompt);
37 } 36 }
@@ -56,6 +55,24 @@ class AiCommandLogic extends BaseLogic @@ -56,6 +55,24 @@ class AiCommandLogic extends BaseLogic
56 $prompt = ''; 55 $prompt = '';
57 } 56 }
58 } 57 }
  58 + // 前缀关键词
  59 + if(preg_match_all("/\{qz_(\d+)\}/", $prompt, $matches)) {
  60 + foreach ($matches[0] as $key=>$val) {
  61 + $keyword = getPrefixKeyword($this->user['project_id'], 'prefix', $matches[1][$key]);
  62 + if($keyword){
  63 + $prompt = str_replace($val, $keyword, $prompt);
  64 + }
  65 + }
  66 + }
  67 + // 后缀关键词
  68 + if(preg_match_all("/\{hz_(\d+)\}/", $prompt, $matches)) {
  69 + foreach ($matches[0] as $key=>$val) {
  70 + $keyword = getPrefixKeyword($this->user['project_id'], 'suffix', $matches[1][$key]);
  71 + if($keyword){
  72 + $prompt = str_replace($val, $keyword, $prompt);
  73 + }
  74 + }
  75 + }
59 if(strpos($prompt, '{company detail}') !== false) { 76 if(strpos($prompt, '{company detail}') !== false) {
60 $company_introduction = $this->getDeployOptimize('company_en_description'); 77 $company_introduction = $this->getDeployOptimize('company_en_description');
61 $prompt = str_replace('{company detail}', $company_introduction, $prompt); 78 $prompt = str_replace('{company detail}', $company_introduction, $prompt);
@@ -68,7 +85,6 @@ class AiCommandLogic extends BaseLogic @@ -68,7 +85,6 @@ class AiCommandLogic extends BaseLogic
68 $prompt .= '.Please answer in ' . $lang; 85 $prompt .= '.Please answer in ' . $lang;
69 $ai_send = true; 86 $ai_send = true;
70 } 87 }
71 -  
72 return [ 88 return [
73 'prompt' => $prompt, 89 'prompt' => $prompt,
74 'scene' => $ai_command->scene, 90 'scene' => $ai_command->scene,
@@ -130,6 +130,9 @@ class KeywordLogic extends BaseLogic @@ -130,6 +130,9 @@ class KeywordLogic extends BaseLogic
130 if(!isset($param['is_video_keyword']) || $param['is_video_keyword'] == null){ 130 if(!isset($param['is_video_keyword']) || $param['is_video_keyword'] == null){
131 $param['is_video_keyword'] = 0; 131 $param['is_video_keyword'] = 0;
132 } 132 }
  133 + if(!empty($param['seo_title'])){
  134 + $param['seo_title'] = ucfirst($param['seo_title']);
  135 + }
133 $param['first_word'] = $this->first_word($param['title']); 136 $param['first_word'] = $this->first_word($param['title']);
134 return $param; 137 return $param;
135 } 138 }
@@ -67,14 +67,14 @@ class TranslateLogic extends BaseLogic @@ -67,14 +67,14 @@ class TranslateLogic extends BaseLogic
67 $data_read = json_decode($info && $info['translate_data'] ? $info['translate_data']['data'] : '',JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); 67 $data_read = json_decode($info && $info['translate_data'] ? $info['translate_data']['data'] : '',JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
68 if(!empty($data_read)){ 68 if(!empty($data_read)){
69 foreach ($data_read as $k => $v){ 69 foreach ($data_read as $k => $v){
70 - $k = urldecode($k); 70 + $k = rawurldecode($k);
71 $old_key[] = $k; 71 $old_key[] = $k;
72 $data[] = [$k => $v]; 72 $data[] = [$k => $v];
73 } 73 }
74 } 74 }
75 $arr2 = []; 75 $arr2 = [];
76 foreach ($text_array as $val) { 76 foreach ($text_array as $val) {
77 - $val = urldecode($val); 77 + $val = rawurldecode($val);
78 $val = str_replace(' ','',$val);//处理特殊字符 78 $val = str_replace(' ','',$val);//处理特殊字符
79 $val = trim(str_replace(' ','',$val)); 79 $val = trim(str_replace(' ','',$val));
80 if($val == ' ' || $val == ''){ 80 if($val == ' ' || $val == ''){