|
...
|
...
|
@@ -88,12 +88,21 @@ class GeoQuestionRes extends Command |
|
|
|
if ($error_num >= 3) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($platform == 'Google AI Overview') {
|
|
|
|
// overview 数据结构不确定, 需要单独处理数据
|
|
|
|
$data = $geo_service->getGooglePlatformResult($question);
|
|
|
|
$result = $this->dealGoogleData($data);
|
|
|
|
} else {
|
|
|
|
$result = $geo_service->getAiPlatformResult($question, $platform);
|
|
|
|
switch ($platform){
|
|
|
|
// case 'google_ai_overview':
|
|
|
|
// // overview 数据结构不确定, 需要单独处理数据
|
|
|
|
// $data = $geo_service->getGooglePlatformResult($question);
|
|
|
|
// $result = $this->dealGoogleData($data);
|
|
|
|
// break;
|
|
|
|
case 'deep_seek':
|
|
|
|
$data = $geo_service->getDeepSeekResult($question);
|
|
|
|
dd($data);
|
|
|
|
$result = $this->dealDeepSeek($data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
$result = $geo_service->getAiPlatformResult($question, $platform);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (empty($result['text'])){
|
|
|
|
goto GET_RESULT;
|
|
...
|
...
|
@@ -109,22 +118,21 @@ class GeoQuestionRes extends Command |
|
|
|
$title = array_column(array_column($result['annotations'], 'url_citation'), 'title');
|
|
|
|
$hit_data = array_merge($url, $title, $hit_data);
|
|
|
|
}
|
|
|
|
// 命中关键词和路由
|
|
|
|
$hit_keyword = $hit_url = [];
|
|
|
|
$hit = 0;
|
|
|
|
if (!empty($taskInfo['keywords'])) {
|
|
|
|
$hit_keyword = $this->getKeywords($taskInfo['keywords'],$hit_data);
|
|
|
|
if (!empty($hit_keyword)) {
|
|
|
|
$hit++;
|
|
|
|
}
|
|
|
|
$hit_keyword = $this->getKeywords($taskInfo['keywords'],$hit_data);
|
|
|
|
if (!empty($hit_keyword['keywords'])) {
|
|
|
|
$hit++;
|
|
|
|
}
|
|
|
|
if (!empty($taskInfo['url'])) {
|
|
|
|
$hit_url = $this->getUrl($taskInfo['url'],$hit_data);
|
|
|
|
if (!empty($hit_url)) {
|
|
|
|
$hit++;
|
|
|
|
}
|
|
|
|
if(!empty($hit_keyword['keywords_num'])){
|
|
|
|
$keyword_num = json_encode($hit_keyword['keywords_num'],true);
|
|
|
|
}
|
|
|
|
$hit_url = $this->getUrl($taskInfo['url'],$hit_data);
|
|
|
|
if (!empty($hit_url['url'])) {
|
|
|
|
$hit++;
|
|
|
|
}
|
|
|
|
if (!empty($hit_url['url_num'])) {
|
|
|
|
$url_num = json_encode($hit_url['url'],true);
|
|
|
|
}
|
|
|
|
echo 'MZ-url->'.json_encode($hit_url).PHP_EOL;
|
|
|
|
// 保存数据结果
|
|
|
|
$geo_result = $geoResultModel->read(['project_id' => $taskInfo['project_id'],'type' => $taskInfo['type'], 'question_id' => $task_id, 'platform' => $platform, 'question' => $question],['id']);
|
|
|
|
$save_data = [
|
|
...
|
...
|
@@ -134,16 +142,18 @@ class GeoQuestionRes extends Command |
|
|
|
'platform' => $platform,
|
|
|
|
'question' => $question,
|
|
|
|
'en_question'=> $en_question,
|
|
|
|
'keywords' => json_encode($hit_keyword,true),//命中的关键词
|
|
|
|
'url' => json_encode($hit_url,true),//命中的网址
|
|
|
|
'text' => json_encode($result,true),
|
|
|
|
'hit' => $hit,
|
|
|
|
'keywords' => json_encode($hit_keyword['keywords'] ?? [],true),//命中的关键词
|
|
|
|
'url' => json_encode($hit_url['url'] ?? [],true),//命中的网址
|
|
|
|
'text' => json_encode($result ?? [],true),
|
|
|
|
'hit' => $hit ?? 0,
|
|
|
|
'keywords_num'=>$keyword_num ?? [],
|
|
|
|
'url_num'=>$url_num ?? [],
|
|
|
|
'created_at'=>date('Y-m-d H:i:s'),
|
|
|
|
'updated_at'=>date('Y-m-d H:i:s'),
|
|
|
|
];
|
|
|
|
// echo '当前数据INFO:'.json_encode($save_data,true).PHP_EOL;
|
|
|
|
if($geo_result === false){
|
|
|
|
$id= $geoResultModel->insertGetId($save_data);
|
|
|
|
$geoResultModel->insertGetId($save_data);
|
|
|
|
}else{
|
|
|
|
$geoResultModel->edit($save_data, ['id' => $geo_result['id']]);
|
|
|
|
}
|
|
...
|
...
|
@@ -167,15 +177,18 @@ class GeoQuestionRes extends Command |
|
|
|
*/
|
|
|
|
public function getUrl($urlArr = [],$result_annotations = []){
|
|
|
|
$url = [];
|
|
|
|
$url_num = [];
|
|
|
|
if(!empty($urlArr)){
|
|
|
|
$str = implode(',',$result_annotations);
|
|
|
|
foreach ($urlArr as $u_item){
|
|
|
|
$count = substr_count($result_annotations, $u_item);
|
|
|
|
$url_num[$u_item] = $count;
|
|
|
|
if (str_contains($str, $u_item)) {
|
|
|
|
$url[] = $u_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array_values(array_unique($url));
|
|
|
|
return ['url'=>$url,'url_num'=>$url_num];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -187,15 +200,43 @@ class GeoQuestionRes extends Command |
|
|
|
*/
|
|
|
|
public function getKeywords($keywordArr = [],$result_text = []){
|
|
|
|
$keywords = [];
|
|
|
|
$keywords_num = [];
|
|
|
|
if(!empty($keywordArr) && !empty($result_text)){
|
|
|
|
$str = implode(',',$result_text);
|
|
|
|
foreach ($keywordArr as $k_item){
|
|
|
|
$count = substr_count($result_text, $k_item);
|
|
|
|
$keywords_num[$k_item] = $count;
|
|
|
|
if (str_contains($str, $k_item)) {
|
|
|
|
$keywords[] = $k_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $keywords;
|
|
|
|
return ['keywords'=>$keywords,'keywords_num'=>$keywords_num];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :整合deepSeek
|
|
|
|
* @name :requestDeepSeek
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/7/15 10:58
|
|
|
|
*/
|
|
|
|
public function dealDeepSeek($data){
|
|
|
|
$result = [
|
|
|
|
'code' => 200,
|
|
|
|
'model' => 'DeepSeek',
|
|
|
|
'text' => '',
|
|
|
|
];
|
|
|
|
$texts = [];
|
|
|
|
if(!empty($data['text'])){
|
|
|
|
array_unshift($texts, $data['text']);
|
|
|
|
}
|
|
|
|
if(!empty($data['reasoning_content'])){
|
|
|
|
array_unshift($texts, $data['reasoning_content']);
|
|
|
|
}
|
|
|
|
$text = implode(PHP_EOL, $texts);
|
|
|
|
$result['text'] = $text;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -279,6 +320,7 @@ class GeoQuestionRes extends Command |
|
|
|
return $task_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 输出日志
|
|
|
|
* @param $message
|
...
|
...
|
|