作者 lyh

gx ai指令生成

@@ -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 - 32 + if($this->param['key'] == 'keyword_seo_title'){
  33 + $prefix = $this->getPrefixKeyword($this->user['project_id'], 'prefix', 1);
  34 + $suffix = $this->getPrefixKeyword($this->user['project_id'], 'suffix', 2);
  35 + $text = $prefix . ' ' . $this->project['keyword']. ' ' . $suffix;
  36 + $data = [
  37 + 'code' => 200,
  38 + 'text' => $text
  39 + ];
  40 + }else{
31 $text = AiCommandLogic::instance()->ai_send(); 41 $text = AiCommandLogic::instance()->ai_send();
32 $data = [ 42 $data = [
33 'code' => $text ? 200 : 500, 43 'code' => $text ? 200 : 500,
34 'text' => $text 44 'text' => $text
35 ]; 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;
@@ -287,4 +289,51 @@ class BaseController extends Controller @@ -287,4 +289,51 @@ class BaseController extends Controller
287 return http_post($c_url, json_encode($param)); 289 return http_post($c_url, json_encode($param));
288 } 290 }
289 291
  292 +
  293 + /**
  294 + * @remark :随机获取前后缀
  295 + * @name :getPrefixKeyword
  296 + * @author :lyh
  297 + * @method :post
  298 + * @time :2025/2/11 14:41
  299 + */
  300 + public function getPrefixKeyword($project_id, $type, $num)
  301 + {
  302 + $str = '';
  303 + $info = $this->getDeployOptimize($project_id);
  304 + if (!empty($info['keyword_' . $type])) {
  305 + $fix_keyword = explode(",", $info['keyword_' . $type]);
  306 + //随机取
  307 + shuffle($fix_keyword);
  308 + if (count($fix_keyword) < $num)
  309 + return $str;
  310 + $keyword = array_slice($fix_keyword, 0, $num);
  311 + $str = implode(", ", $keyword);
  312 + }
  313 + return $str;
  314 + }
  315 +
  316 + /**
  317 + * @remark :获取客户选择的关键词
  318 + * @name :getDeployOptimize
  319 + * @author :lyh
  320 + * @method :post
  321 + * @time :2025/2/11 14:58
  322 + */
  323 + public function getDeployOptimize($project_id){
  324 + $cache_key = 'project_deploy_optimize_info_' . $project_id;
  325 + $info = Cache::get($cache_key);
  326 + if(!$info){
  327 + $projectOptimizeModel = new DeployOptimize();
  328 + $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'keyword_prefix', 'keyword_suffix']);
  329 + $projectKeywordModel = new ProjectKeyword();
  330 + $keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]);
  331 + $info['main_keyword'] = '';
  332 + if(!empty($keywordInfo['main_keyword'])){
  333 + $info['main_keyword'] = $keywordInfo['main_keyword'];
  334 + }
  335 + Cache::put($cache_key, $info, 600);
  336 + }
  337 + return $info;
  338 + }
290 } 339 }
@@ -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 }