作者 lyh

gx

@@ -88,12 +88,21 @@ class GeoQuestionRes extends Command @@ -88,12 +88,21 @@ class GeoQuestionRes extends Command
88 if ($error_num >= 3) { 88 if ($error_num >= 3) {
89 continue; 89 continue;
90 } 90 }
91 - if ($platform == 'Google AI Overview') {  
92 - // overview 数据结构不确定, 需要单独处理数据  
93 - $data = $geo_service->getGooglePlatformResult($question);  
94 - $result = $this->dealGoogleData($data);  
95 - } else {  
96 - $result = $geo_service->getAiPlatformResult($question, $platform); 91 + switch ($platform){
  92 +// case 'google_ai_overview':
  93 +// // overview 数据结构不确定, 需要单独处理数据
  94 +// $data = $geo_service->getGooglePlatformResult($question);
  95 +// $result = $this->dealGoogleData($data);
  96 +// break;
  97 + case 'deep_seek':
  98 + $data = $geo_service->getDeepSeekResult($question);
  99 + dd($data);
  100 + $result = $this->dealDeepSeek($data);
  101 + break;
  102 + default:
  103 + continue;
  104 + $result = $geo_service->getAiPlatformResult($question, $platform);
  105 + break;
97 } 106 }
98 if (empty($result['text'])){ 107 if (empty($result['text'])){
99 goto GET_RESULT; 108 goto GET_RESULT;
@@ -109,22 +118,21 @@ class GeoQuestionRes extends Command @@ -109,22 +118,21 @@ class GeoQuestionRes extends Command
109 $title = array_column(array_column($result['annotations'], 'url_citation'), 'title'); 118 $title = array_column(array_column($result['annotations'], 'url_citation'), 'title');
110 $hit_data = array_merge($url, $title, $hit_data); 119 $hit_data = array_merge($url, $title, $hit_data);
111 } 120 }
112 - // 命中关键词和路由  
113 - $hit_keyword = $hit_url = [];  
114 $hit = 0; 121 $hit = 0;
115 - if (!empty($taskInfo['keywords'])) {  
116 - $hit_keyword = $this->getKeywords($taskInfo['keywords'],$hit_data);  
117 - if (!empty($hit_keyword)) {  
118 - $hit++;  
119 - } 122 + $hit_keyword = $this->getKeywords($taskInfo['keywords'],$hit_data);
  123 + if (!empty($hit_keyword['keywords'])) {
  124 + $hit++;
120 } 125 }
121 - if (!empty($taskInfo['url'])) {  
122 - $hit_url = $this->getUrl($taskInfo['url'],$hit_data);  
123 - if (!empty($hit_url)) {  
124 - $hit++;  
125 - } 126 + if(!empty($hit_keyword['keywords_num'])){
  127 + $keyword_num = json_encode($hit_keyword['keywords_num'],true);
  128 + }
  129 + $hit_url = $this->getUrl($taskInfo['url'],$hit_data);
  130 + if (!empty($hit_url['url'])) {
  131 + $hit++;
  132 + }
  133 + if (!empty($hit_url['url_num'])) {
  134 + $url_num = json_encode($hit_url['url'],true);
126 } 135 }
127 - echo 'MZ-url->'.json_encode($hit_url).PHP_EOL;  
128 // 保存数据结果 136 // 保存数据结果
129 $geo_result = $geoResultModel->read(['project_id' => $taskInfo['project_id'],'type' => $taskInfo['type'], 'question_id' => $task_id, 'platform' => $platform, 'question' => $question],['id']); 137 $geo_result = $geoResultModel->read(['project_id' => $taskInfo['project_id'],'type' => $taskInfo['type'], 'question_id' => $task_id, 'platform' => $platform, 'question' => $question],['id']);
130 $save_data = [ 138 $save_data = [
@@ -134,16 +142,18 @@ class GeoQuestionRes extends Command @@ -134,16 +142,18 @@ class GeoQuestionRes extends Command
134 'platform' => $platform, 142 'platform' => $platform,
135 'question' => $question, 143 'question' => $question,
136 'en_question'=> $en_question, 144 'en_question'=> $en_question,
137 - 'keywords' => json_encode($hit_keyword,true),//命中的关键词  
138 - 'url' => json_encode($hit_url,true),//命中的网址  
139 - 'text' => json_encode($result,true),  
140 - 'hit' => $hit, 145 + 'keywords' => json_encode($hit_keyword['keywords'] ?? [],true),//命中的关键词
  146 + 'url' => json_encode($hit_url['url'] ?? [],true),//命中的网址
  147 + 'text' => json_encode($result ?? [],true),
  148 + 'hit' => $hit ?? 0,
  149 + 'keywords_num'=>$keyword_num ?? [],
  150 + 'url_num'=>$url_num ?? [],
141 'created_at'=>date('Y-m-d H:i:s'), 151 'created_at'=>date('Y-m-d H:i:s'),
142 'updated_at'=>date('Y-m-d H:i:s'), 152 'updated_at'=>date('Y-m-d H:i:s'),
143 ]; 153 ];
144 // echo '当前数据INFO:'.json_encode($save_data,true).PHP_EOL; 154 // echo '当前数据INFO:'.json_encode($save_data,true).PHP_EOL;
145 if($geo_result === false){ 155 if($geo_result === false){
146 - $id= $geoResultModel->insertGetId($save_data); 156 + $geoResultModel->insertGetId($save_data);
147 }else{ 157 }else{
148 $geoResultModel->edit($save_data, ['id' => $geo_result['id']]); 158 $geoResultModel->edit($save_data, ['id' => $geo_result['id']]);
149 } 159 }
@@ -167,15 +177,18 @@ class GeoQuestionRes extends Command @@ -167,15 +177,18 @@ class GeoQuestionRes extends Command
167 */ 177 */
168 public function getUrl($urlArr = [],$result_annotations = []){ 178 public function getUrl($urlArr = [],$result_annotations = []){
169 $url = []; 179 $url = [];
  180 + $url_num = [];
170 if(!empty($urlArr)){ 181 if(!empty($urlArr)){
171 $str = implode(',',$result_annotations); 182 $str = implode(',',$result_annotations);
172 foreach ($urlArr as $u_item){ 183 foreach ($urlArr as $u_item){
  184 + $count = substr_count($result_annotations, $u_item);
  185 + $url_num[$u_item] = $count;
173 if (str_contains($str, $u_item)) { 186 if (str_contains($str, $u_item)) {
174 $url[] = $u_item; 187 $url[] = $u_item;
175 } 188 }
176 } 189 }
177 } 190 }
178 - return array_values(array_unique($url)); 191 + return ['url'=>$url,'url_num'=>$url_num];
179 } 192 }
180 193
181 /** 194 /**
@@ -187,15 +200,43 @@ class GeoQuestionRes extends Command @@ -187,15 +200,43 @@ class GeoQuestionRes extends Command
187 */ 200 */
188 public function getKeywords($keywordArr = [],$result_text = []){ 201 public function getKeywords($keywordArr = [],$result_text = []){
189 $keywords = []; 202 $keywords = [];
  203 + $keywords_num = [];
190 if(!empty($keywordArr) && !empty($result_text)){ 204 if(!empty($keywordArr) && !empty($result_text)){
191 $str = implode(',',$result_text); 205 $str = implode(',',$result_text);
192 foreach ($keywordArr as $k_item){ 206 foreach ($keywordArr as $k_item){
  207 + $count = substr_count($result_text, $k_item);
  208 + $keywords_num[$k_item] = $count;
193 if (str_contains($str, $k_item)) { 209 if (str_contains($str, $k_item)) {
194 $keywords[] = $k_item; 210 $keywords[] = $k_item;
195 } 211 }
196 } 212 }
197 } 213 }
198 - return $keywords; 214 + return ['keywords'=>$keywords,'keywords_num'=>$keywords_num];
  215 + }
  216 +
  217 + /**
  218 + * @remark :整合deepSeek
  219 + * @name :requestDeepSeek
  220 + * @author :lyh
  221 + * @method :post
  222 + * @time :2025/7/15 10:58
  223 + */
  224 + public function dealDeepSeek($data){
  225 + $result = [
  226 + 'code' => 200,
  227 + 'model' => 'DeepSeek',
  228 + 'text' => '',
  229 + ];
  230 + $texts = [];
  231 + if(!empty($data['text'])){
  232 + array_unshift($texts, $data['text']);
  233 + }
  234 + if(!empty($data['reasoning_content'])){
  235 + array_unshift($texts, $data['reasoning_content']);
  236 + }
  237 + $text = implode(PHP_EOL, $texts);
  238 + $result['text'] = $text;
  239 + return $result;
199 } 240 }
200 241
201 /** 242 /**
@@ -279,6 +320,7 @@ class GeoQuestionRes extends Command @@ -279,6 +320,7 @@ class GeoQuestionRes extends Command
279 return $task_id; 320 return $task_id;
280 } 321 }
281 322
  323 +
282 /** 324 /**
283 * 输出日志 325 * 输出日志
284 * @param $message 326 * @param $message
@@ -11,7 +11,7 @@ namespace App\Services\Geo; @@ -11,7 +11,7 @@ namespace App\Services\Geo;
11 11
12 class GeoService 12 class GeoService
13 { 13 {
14 - public $api_key = '7yn!We6$&NnVA38bpGy*A@4TQ5iYLJcW'; 14 + public $api_key = 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6';
15 15
16 public $api_url = 'https://api.cmer.com/'; 16 public $api_url = 'https://api.cmer.com/';
17 17
@@ -68,4 +68,34 @@ class GeoService @@ -68,4 +68,34 @@ class GeoService
68 $url = $url . '?' . http_build_query($param); 68 $url = $url . '?' . http_build_query($param);
69 return http_get($url, $header); 69 return http_get($url, $header);
70 } 70 }
  71 +
  72 + /**
  73 + * @remark :请求deepSeek数据
  74 + * @name :getDeepSeek
  75 + * @author :lyh
  76 + * @method :post
  77 + * @time :2025/7/15 10:59
  78 + */
  79 + public function getDeepSeekResult($content){
  80 + $url = $this->api_url . 'v1/chat';
  81 + $header = [
  82 + 'accept: application/json',
  83 + 'X-CmerApi-Host: llm-chat.p.cmer.com',
  84 + 'apikey: '.$this->api_key,
  85 + 'Content-Type: application/json'
  86 + ];
  87 + $message = [
  88 + 'messages'=>[
  89 + [
  90 + 'content'=>$content,
  91 + 'role'=>'user'
  92 + ],
  93 + ],
  94 + 'model' => 'deepseek-r1',
  95 + "supplier"=> "bailian",
  96 + 'security_check' => true
  97 + ];
  98 + $data = http_post($url,json_encode($message,true),$header);
  99 + return $data;
  100 + }
71 } 101 }