|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name :GeoQuestionResult.php
|
|
|
|
* @name :GeoQuestionRes.php
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/7/3 15:13
|
|
...
|
...
|
@@ -11,11 +11,13 @@ namespace App\Console\Commands\Geo; |
|
|
|
|
|
|
|
use App\Models\Geo\GeoPlatform;
|
|
|
|
use App\Models\Geo\GeoQuestion;
|
|
|
|
use App\Models\Geo\GeoQuestionResult;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Services\Geo\GeoService;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
|
|
class GeoQuestionResult extends Command
|
|
|
|
class GeoQuestionRes extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
...
|
...
|
@@ -36,10 +38,17 @@ class GeoQuestionResult extends Command |
|
|
|
$task_id = $this->getTaskId();
|
|
|
|
$questionModel = new GeoQuestion();//问题
|
|
|
|
$info = $questionModel->read(['id'=>$task_id]);
|
|
|
|
//获取当前项目的执行频率
|
|
|
|
$projectModel = new Project();
|
|
|
|
$projectInfo = $projectModel->read(['id'=>$info['project_id']],['geo_status','geo_frequency']);
|
|
|
|
if($projectInfo['geo_status'] == 0){
|
|
|
|
$questionModel->edit(['status'=>0],['id'=>$task_id]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$questionArr = $info['question'];
|
|
|
|
if(empty($questionArr)){
|
|
|
|
echo date('Y-m-d H:i:s').'当前任务不存在问题。'.PHP_EOL;
|
|
|
|
$questionModel->edit(['status'=>2],['id'=>$task_id]);
|
|
|
|
$questionModel->edit(['status'=>0],['id'=>$task_id]);
|
|
|
|
}
|
|
|
|
//获取平台信息
|
|
|
|
$platformModel = new GeoPlatform();//平台
|
|
...
|
...
|
@@ -49,13 +58,74 @@ class GeoQuestionResult extends Command |
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$geoService = new GeoService();
|
|
|
|
$keywordArr = $info['keywords'] ?? [];
|
|
|
|
$urlArr = $info['url'] ?? [];
|
|
|
|
$geoResultModel = new GeoQuestionResult();
|
|
|
|
foreach ($questionArr as $q_item){
|
|
|
|
foreach ($platformArr as $p_item){
|
|
|
|
$data = $geoService->setWebSearchChatAction($q_item,$p_item);
|
|
|
|
dd($data);
|
|
|
|
$keywords = [];//命中的关键词
|
|
|
|
$urls = [];//命中的网址
|
|
|
|
$result_data = $geoService->setWebSearchChatAction($q_item,$p_item);
|
|
|
|
if(isset($result_data) && $result_data['code'] == 200){
|
|
|
|
$keywords = $this->getKeywords($keywordArr,$result_data['text'] ?? []);
|
|
|
|
$urls = $this->getUrl($urlArr,$result_data['annotations'] ?? []);
|
|
|
|
}
|
|
|
|
//保存一条结果记录
|
|
|
|
$data = [
|
|
|
|
'project_id'=>$info['project_id'],
|
|
|
|
'question_id'=>$info['id'],
|
|
|
|
'platform'=>$p_item,
|
|
|
|
'question'=>$q_item,
|
|
|
|
'keywords'=>json_encode($keywords ?? [],true),//命中的关键词
|
|
|
|
'text'=>json_encode($result_data ?? [],true),
|
|
|
|
'url'=>json_encode($urls ?? [],true),//命中的网址
|
|
|
|
];
|
|
|
|
$geoResultModel->addReturnId($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//更新下次执行时间
|
|
|
|
$questionModel->edit(['current_time'=>date('Y-m-d'),'next_time'=>date('Y-m-d', strtotime(date('Y-m-d') . ' +5 days'))],['id'=>$info['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取命中的url
|
|
|
|
* @name :getUrl
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/7/3 16:38
|
|
|
|
*/
|
|
|
|
public function getUrl($urlArr = [],$result_annotations = []){
|
|
|
|
$url = [];
|
|
|
|
if(!empty($urlArr) && !empty($result_annotations)){
|
|
|
|
foreach ($urlArr as $u_item){
|
|
|
|
foreach ($result_annotations as $a_item){
|
|
|
|
if (str_contains($a_item['url_citation']['url'], $u_item)) {
|
|
|
|
$url[] = $u_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取命中的关键词
|
|
|
|
* @name :getKeywords
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/7/3 16:26
|
|
|
|
*/
|
|
|
|
public function getKeywords($keywordArr = [],$result_text = []){
|
|
|
|
$keywords = [];
|
|
|
|
if(!empty($keywordArr) && !empty($result_text)){
|
|
|
|
foreach ($keywordArr as $k_item){
|
|
|
|
if (str_contains($result_text, $k_item)) {
|
|
|
|
$keywords[] = $k_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $keywords;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|