作者 刘锟

update

@@ -10,6 +10,7 @@ use App\Models\Domain\DomainInfo; @@ -10,6 +10,7 @@ use App\Models\Domain\DomainInfo;
10 use App\Models\Product\KeywordRelated; 10 use App\Models\Product\KeywordRelated;
11 use App\Models\Product\Product; 11 use App\Models\Product\Product;
12 use App\Models\Project\Project; 12 use App\Models\Project\Project;
  13 +use App\Models\WebSetting\WebLanguage;
13 use App\Services\BatchExportService; 14 use App\Services\BatchExportService;
14 use App\Services\ProjectServer; 15 use App\Services\ProjectServer;
15 use Illuminate\Console\Command; 16 use Illuminate\Console\Command;
@@ -32,9 +33,81 @@ class Temp extends Command @@ -32,9 +33,81 @@ class Temp extends Command
32 33
33 public function handle() 34 public function handle()
34 { 35 {
35 - $this->check_zb_complete_project_site(); 36 + $this->check_server_minor_site();
36 } 37 }
37 38
  39 + /**
  40 + * 判断指定服务器项目小语种是否正常访问
  41 + * @author Akun
  42 + * @date 2024/12/11 10:15
  43 + */
  44 + public function check_server_minor_site()
  45 + {
  46 + $server_id = 15;
  47 + $server_name = '美服1';
  48 +
  49 + $server_ip_model = new ServersIp();
  50 +
  51 + $server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
  52 +
  53 + $project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
  54 +
  55 + $domain_model = new DomainInfo();
  56 + $notify_model = new Notify();
  57 + $data = [];
  58 + foreach ($project_list as $value) {
  59 + $domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
  60 + if (!$domain_info) {
  61 + //过滤未绑定正式域名的项目
  62 + continue;
  63 + }
  64 + $domain = $domain_info['domain'];
  65 +
  66 + //获取最新一条小语种生成任务
  67 + $notify = $notify_model->read(['project_id' => $value->id, 'type' => 2, 'status' => 3, 'route' => 1], ['data']);
  68 + if (!$notify) {
  69 + //过滤未生成过小语种的项目
  70 + continue;
  71 + }
  72 + $notify_data = json_decode($notify['data'], true);
  73 + $language_id = 0;
  74 + foreach ($notify_data['language'] as $vl) {
  75 + if ($vl > 1) {
  76 + $language_id = $vl;
  77 + }
  78 + }
  79 + if (!$language_id) {
  80 + continue;
  81 + }
  82 + $language_info = WebLanguage::getLangById($language_id);
  83 + $lan = $language_info->short;
  84 + $code = check_curl_status('https://' . $domain . '/' . $lan);
  85 + $html = curl_c('https://' . $domain . '/' . $lan, false);
  86 + $is_404 = false;
  87 + if (strpos($html, 'Sorry. The page has either moved or cannot be found.') !== false) {
  88 + $is_404 = true;
  89 + }
  90 + $data[] = [
  91 + $value->id,
  92 + $value->title,
  93 + 'https://' . $domain . '/' . $lan,
  94 + $code,
  95 + $is_404
  96 + ];
  97 + }
  98 + $map = ['项目id', '名称', '访问地址', '访问状态', '是否404'];
  99 + if ($data) {
  100 + $table = new BatchExportService($server_name . '站点小语种页面访问状态');
  101 + $file = $table->head($map)->data($data)->save();
  102 + if (!$file) {
  103 + $this->output('文件生成失败,请重试');
  104 + } else {
  105 + $this->output('export success');
  106 + }
  107 + } else {
  108 + $this->output('no data');
  109 + }
  110 + }
38 111
39 /** 112 /**
40 * 创建指定服务器所有项目主站生成任务 113 * 创建指定服务器所有项目主站生成任务
@@ -100,7 +173,7 @@ class Temp extends Command @@ -100,7 +173,7 @@ class Temp extends Command
100 * @author Akun 173 * @author Akun
101 * @date 2024/12/11 10:15 174 * @date 2024/12/11 10:15
102 */ 175 */
103 - public function check_zb_complete_project_site() 176 + public function check_server_project_site()
104 { 177 {
105 $server_id = 15; 178 $server_id = 15;
106 $server_name = '美服1'; 179 $server_name = '美服1';