作者 李宇航

合并分支 'lyh-server' 到 'master'

geo设置



查看合并请求 !2370
@@ -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
@@ -12,6 +12,7 @@ namespace App\Http\Controllers\Aside\Geo; @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Aside\Geo;
12 use App\Enums\Common\Code; 12 use App\Enums\Common\Code;
13 use App\Http\Controllers\Aside\BaseController; 13 use App\Http\Controllers\Aside\BaseController;
14 use App\Http\Logic\Aside\Geo\GeoArticleLogic; 14 use App\Http\Logic\Aside\Geo\GeoArticleLogic;
  15 +use Illuminate\Http\Request;
15 16
16 /** 17 /**
17 * @remark :GEO文章列表数据 18 * @remark :GEO文章列表数据
@@ -62,11 +63,34 @@ class GeoArticleController extends BaseController @@ -62,11 +63,34 @@ class GeoArticleController extends BaseController
62 } 63 }
63 64
64 /** 65 /**
  66 + * @remark :更新单个数据
  67 + * @name :edit
  68 + * @author :lyh
  69 + * @method :post
  70 + * @time :2025/7/15 10:31
  71 + */
  72 + public function edit(){
  73 + $this->request->validate([
  74 + 'id'=>'required',
  75 + 'url'=>'required',
  76 + 'filename'=>'required',
  77 + ],[
  78 + 'id.required' => 'ID不能为空',
  79 + 'url.required' => '链接不能为空',
  80 + 'filename.required' => '文件名称不能为空',
  81 + ]);
  82 + $data = $this->logic->editArticle();
  83 + $this->response('success',Code::SUCCESS,$data);
  84 + }
  85 +
  86 + /**
65 * @remark :保存数据 87 * @remark :保存数据
66 * @name :save 88 * @name :save
67 * @author :lyh 89 * @author :lyh
68 * @method :post 90 * @method :post
69 * @time :2025/7/14 17:05 91 * @time :2025/7/14 17:05
  92 + * @param :data->数组(filename:文件名称 url:链接)
  93 + * @json :测试数据 {"project_id": 1,"data": [{"url": "/upload/m/file/2023-09/6513d00870e0821127.pdf","filename": "测试文件1"}]}
70 */ 94 */
71 public function save(){ 95 public function save(){
72 $this->request->validate([ 96 $this->request->validate([
@@ -9,8 +9,10 @@ @@ -9,8 +9,10 @@
9 9
10 namespace App\Http\Controllers\Aside\Geo; 10 namespace App\Http\Controllers\Aside\Geo;
11 11
  12 +use App\Enums\Common\Code;
12 use App\Http\Controllers\Aside\BaseController; 13 use App\Http\Controllers\Aside\BaseController;
13 - 14 +use App\Http\Logic\Aside\Geo\GeoLinkLogic;
  15 +use Illuminate\Http\Request;
14 /** 16 /**
15 * @remark :geo权威新闻(链接数据) 17 * @remark :geo权威新闻(链接数据)
16 * @name :GeoLinkController 18 * @name :GeoLinkController
@@ -20,5 +22,80 @@ use App\Http\Controllers\Aside\BaseController; @@ -20,5 +22,80 @@ use App\Http\Controllers\Aside\BaseController;
20 */ 22 */
21 class GeoLinkController extends BaseController 23 class GeoLinkController extends BaseController
22 { 24 {
  25 + public function __construct(Request $request)
  26 + {
  27 + parent::__construct($request);
  28 + $this->logic = new GeoLinkLogic();
  29 + }
  30 +
  31 + /**
  32 + * @remark :获取链接数据列表
  33 + * @name :lists
  34 + * @author :lyh
  35 + * @method :post
  36 + * @time :2025/7/15 9:14
  37 + */
  38 + public function lists(){
  39 + $this->request->validate([
  40 + 'project_id'=>'required',
  41 + ],[
  42 + 'project_id.required' => '项目ID不能为空',
  43 + ]);
  44 + $lists = $this->logic->getLinkList($this->map,$this->page,$this->row,$this->order);
  45 + $this->response('success',Code::SUCCESS,$lists);
  46 + }
  47 +
  48 + /**
  49 + * @remark :获取数据详情
  50 + * @name :info
  51 + * @author :lyh
  52 + * @method :post
  53 + * @time :2025/7/15 9:15
  54 + */
  55 + public function info(){
  56 + $this->request->validate([
  57 + 'id'=>'required',
  58 + ],[
  59 + 'id.required' => 'ID不能为空',
  60 + ]);
  61 + $data = $this->logic->getLinkInfo();
  62 + $this->response('success',Code::SUCCESS,$data);
  63 + }
  64 +
  65 + /**
  66 + * @remark :保存数据
  67 + * @name :save
  68 + * @author :lyh
  69 + * @method :post
  70 + * @time :2025/7/15 9:17
  71 + */
  72 + public function save(){
  73 + $this->request->validate([
  74 + 'project_id'=>'required',
  75 + 'data'=>'required|array'
  76 + ],[
  77 + 'project_id.required' => '项目ID不能为空',
  78 + 'data.required' => '数据详情不能为空',
  79 + 'data.array' => '数据详情为数组',
  80 + ]);
  81 + $data = $this->logic->saveLink();
  82 + $this->response('success',Code::SUCCESS,$data);
  83 + }
23 84
  85 + /**
  86 + * @remark :删除数据
  87 + * @name :del
  88 + * @author :lyh
  89 + * @method :post
  90 + * @time :2025/7/15 9:17
  91 + */
  92 + public function del(){
  93 + $this->request->validate([
  94 + 'id'=>'required',
  95 + ],[
  96 + 'id.required' => 'ID不能为空',
  97 + ]);
  98 + $data = $this->logic->delLink();
  99 + $this->response('success',Code::SUCCESS,$data);
  100 + }
24 } 101 }
@@ -41,6 +41,13 @@ class GeoArticleLogic extends BaseLogic @@ -41,6 +41,13 @@ class GeoArticleLogic extends BaseLogic
41 } 41 }
42 $filed = ['*']; 42 $filed = ['*'];
43 $lists = $this->model->lists($map,$page,$row,$order,$filed); 43 $lists = $this->model->lists($map,$page,$row,$order,$filed);
  44 + if(!empty($lists) && !empty($lists['list'])){
  45 + foreach ($lists['list'] as $key => $item){
  46 + $item['download_url'] = url('a/download_files?path='.$item['url']);
  47 + $item['url_link'] = getFileUrl($item['url']);
  48 + $lists['list'][$key] = $item;
  49 + }
  50 + }
44 return $this->success($lists); 51 return $this->success($lists);
45 } 52 }
46 53
@@ -56,10 +63,24 @@ class GeoArticleLogic extends BaseLogic @@ -56,10 +63,24 @@ class GeoArticleLogic extends BaseLogic
56 if($info === false){ 63 if($info === false){
57 $this->fail('当前数据不存在或者已被删除'); 64 $this->fail('当前数据不存在或者已被删除');
58 } 65 }
  66 + $info['url'] = getFileUrl($info['url']);
59 return $this->success($info); 67 return $this->success($info);
60 } 68 }
61 69
62 /** 70 /**
  71 + * @remark :更新单个数据
  72 + * @name :editArticle
  73 + * @author :lyh
  74 + * @method :post
  75 + * @time :2025/7/15 10:29
  76 + */
  77 + public function editArticle(){
  78 + $this->param['url'] = str_replace_url($this->param['url']);
  79 + $this->model->edit($this->param,['id'=>$this->param['id']]);
  80 + return $this->success(['id'=>$this->param['id']]);
  81 + }
  82 +
  83 + /**
63 * @remark :保存数据 84 * @remark :保存数据
64 * @name :saveArticle 85 * @name :saveArticle
65 * @author :lyh 86 * @author :lyh
@@ -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 }
@@ -563,6 +563,21 @@ Route::middleware(['aloginauth'])->group(function () { @@ -563,6 +563,21 @@ Route::middleware(['aloginauth'])->group(function () {
563 Route::any('/saveGeoQuestion', [Aside\Geo\GeoQuestionController::class, 'saveGeoQuestion'])->name('admin.geo_question_saveGeoQuestion'); 563 Route::any('/saveGeoQuestion', [Aside\Geo\GeoQuestionController::class, 'saveGeoQuestion'])->name('admin.geo_question_saveGeoQuestion');
564 Route::any('/delGeoQuestion', [Aside\Geo\GeoQuestionController::class, 'delGeoQuestion'])->name('admin.geo_question_delGeoQuestion'); 564 Route::any('/delGeoQuestion', [Aside\Geo\GeoQuestionController::class, 'delGeoQuestion'])->name('admin.geo_question_delGeoQuestion');
565 }); 565 });
  566 + //文章列表
  567 + Route::prefix('article')->group(function () {
  568 + Route::any('/lists', [Aside\Geo\GeoArticleController::class, 'lists'])->name('admin.geo_article_lists');
  569 + Route::any('/save', [Aside\Geo\GeoArticleController::class, 'save'])->name('admin.geo_article_save');
  570 + Route::any('/edit', [Aside\Geo\GeoArticleController::class, 'edit'])->name('admin.geo_article_edit');
  571 + Route::any('/info', [Aside\Geo\GeoArticleController::class, 'info'])->name('admin.geo_article_info');
  572 + Route::any('/del', [Aside\Geo\GeoArticleController::class, 'del'])->name('admin.geo_article_del');
  573 + });
  574 + //权威文章链接
  575 + Route::prefix('link')->group(function () {
  576 + Route::any('/lists', [Aside\Geo\GeoLinkController::class, 'lists'])->name('admin.geo_link_lists');
  577 + Route::any('/save', [Aside\Geo\GeoLinkController::class, 'save'])->name('admin.geo_link_save');
  578 + Route::any('/info', [Aside\Geo\GeoLinkController::class, 'info'])->name('admin.geo_link_info');
  579 + Route::any('/del', [Aside\Geo\GeoLinkController::class, 'del'])->name('admin.geo_link_del');
  580 + });
566 }); 581 });
567 // 任务相关 582 // 任务相关
568 Route::prefix('task')->group(function () { 583 Route::prefix('task')->group(function () {