作者 lyh
  1 +<?php
  2 +
  3 +
  4 +namespace App\Console\Commands\RankData;
  5 +
  6 +
  7 +use App\Helper\Arr;
  8 +use App\Utils\HttpUtils;
  9 +use GuzzleHttp\Exception\GuzzleException;
  10 +use Illuminate\Console\Command;
  11 +
  12 +class updateAiProjects extends Command
  13 +{
  14 + protected $signature = 'updateAiProjects';
  15 +
  16 + protected $description = '更新AI站点域名数据';
  17 +
  18 +
  19 + public function handle()
  20 + {
  21 + $api_url = 'https://demosite5.globalso.com/api/domain';
  22 + try {
  23 + $data = HttpUtils::get($api_url, []);
  24 + if ($data) {
  25 + $data = Arr::s2a($data);
  26 + $file_path = public_path('ai_domains.txt');
  27 + file_put_contents($file_path, json_encode($data['data']));
  28 + }
  29 + } catch (\Exception | GuzzleException $e) {
  30 + errorLog('AI站点项目获取失败', [], $e);
  31 + return false;
  32 + }
  33 + }
  34 +
  35 +}
@@ -40,6 +40,9 @@ class Kernel extends ConsoleKernel @@ -40,6 +40,9 @@ class Kernel extends ConsoleKernel
40 $schedule->command('delete_template_log')->monthlyOn(15, '00:01')->withoutOverlapping(); 40 $schedule->command('delete_template_log')->monthlyOn(15, '00:01')->withoutOverlapping();
41 // 每日推送已完成视频任务项目生成对应界面 41 // 每日推送已完成视频任务项目生成对应界面
42 $schedule->command('notice_c')->dailyAt('04:00')->withoutOverlapping(1); 42 $schedule->command('notice_c')->dailyAt('04:00')->withoutOverlapping(1);
  43 +
  44 + //更新AI站点数据
  45 + $schedule->command('updateAiProjects')->everyFourHours()->withoutOverlapping(1);
43 } 46 }
44 47
45 /** 48 /**
@@ -531,24 +531,12 @@ class OptimizationReportController extends BaseController @@ -531,24 +531,12 @@ class OptimizationReportController extends BaseController
531 */ 531 */
532 public function getAiProjects($domain = null) 532 public function getAiProjects($domain = null)
533 { 533 {
534 - $key = 'ai_projects_list';  
535 - $data = Cache::get($key);  
536 - if (!$data) {  
537 - $api_url = 'https://demosite5.globalso.com/api/domain';  
538 - try {  
539 - $data = HttpUtils::get($api_url, []);  
540 - if ($data) {  
541 - $data = Arr::s2a($data);  
542 - Cache::put($key, $data, 4 * 3600);  
543 - }  
544 - } catch (\Exception | GuzzleException $e) {  
545 - errorLog('AI站点项目获取失败', [], $e);  
546 - return false;  
547 - }  
548 - } 534 + $file_path = public_path('ai_domains.txt');
  535 + $data = file_get_contents($file_path);
  536 + $data = json_decode($data, true);
549 if ($domain !== null) { 537 if ($domain !== null) {
550 $domain = parse_url($domain); 538 $domain = parse_url($domain);
551 - $data = collect($data['data'])->where('bind_domain', $domain['host'] ?? $domain['path'])->first(); 539 + $data = collect($data)->where('bind_domain', $domain['host'] ?? $domain['path'])->first();
552 return $data ?: []; 540 return $data ?: [];
553 } 541 }
554 return $data; 542 return $data;
@@ -314,20 +314,7 @@ class RankDataLogic extends BaseLogic @@ -314,20 +314,7 @@ class RankDataLogic extends BaseLogic
314 public function getAiProjects($domain = null) 314 public function getAiProjects($domain = null)
315 { 315 {
316 $file_path = public_path('ai_domains.txt'); 316 $file_path = public_path('ai_domains.txt');
317 - $update_time = filemtime($file_path);  
318 $data = file_get_contents($file_path); 317 $data = file_get_contents($file_path);
319 - if (time() - $update_time > 4 * 3600) {  
320 - $api_url = 'https://demosite5.globalso.com/api/domain';  
321 - try {  
322 - $data = HttpUtils::get($api_url, []);  
323 - if ($data) {  
324 - file_put_contents($file_path, $data);  
325 - }  
326 - } catch (\Exception | GuzzleException $e) {  
327 - errorLog('AI站点项目获取失败', [], $e);  
328 - file_put_contents($file_path, $data);  
329 - }  
330 - }  
331 $data = json_decode($data, true); 318 $data = json_decode($data, true);
332 if ($domain !== null) { 319 if ($domain !== null) {
333 $domain = parse_url($domain); 320 $domain = parse_url($domain);