Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-server
正在显示
1 个修改的文件
包含
57 行增加
和
48 行删除
| @@ -3,20 +3,12 @@ | @@ -3,20 +3,12 @@ | ||
| 3 | namespace App\Console\Commands\Test; | 3 | namespace App\Console\Commands\Test; |
| 4 | 4 | ||
| 5 | use App\Helper\Arr; | 5 | use App\Helper\Arr; |
| 6 | -use App\Models\Collect\CollectTask; | ||
| 7 | use App\Models\Com\Notify; | 6 | use App\Models\Com\Notify; |
| 8 | -use App\Models\Com\UpdateLog; | ||
| 9 | -use App\Models\Com\UpdateVisit; | ||
| 10 | use App\Models\Devops\ServerConfig; | 7 | use App\Models\Devops\ServerConfig; |
| 8 | +use App\Models\Devops\ServersIp; | ||
| 11 | use App\Models\Domain\DomainInfo; | 9 | use App\Models\Domain\DomainInfo; |
| 12 | -use App\Models\Product\Product; | ||
| 13 | use App\Models\Project\Project; | 10 | use App\Models\Project\Project; |
| 14 | -use App\Services\ProjectServer; | ||
| 15 | -use App\Utils\HttpUtils; | ||
| 16 | -use GuzzleHttp\Exception\GuzzleException; | ||
| 17 | use Illuminate\Console\Command; | 11 | use Illuminate\Console\Command; |
| 18 | -use Illuminate\Support\Facades\DB; | ||
| 19 | -use Symfony\Component\Process\Process; | ||
| 20 | 12 | ||
| 21 | class Temp extends Command | 13 | class Temp extends Command |
| 22 | { | 14 | { |
| @@ -34,55 +26,72 @@ class Temp extends Command | @@ -34,55 +26,72 @@ class Temp extends Command | ||
| 34 | */ | 26 | */ |
| 35 | protected $description = '临时脚本'; | 27 | protected $description = '临时脚本'; |
| 36 | 28 | ||
| 37 | - public function handle(){ | ||
| 38 | - ProjectServer::useProject(1515); | ||
| 39 | - | ||
| 40 | - $products = Product::select(['id','content'])->get(); | 29 | + public function handle() |
| 30 | + { | ||
| 31 | + $notify_model = new Notify(); | ||
| 41 | 32 | ||
| 42 | - foreach ($products as $product){ | ||
| 43 | - $content = $product->content; | ||
| 44 | - $content = str_replace('<h1','<h2', $content); | ||
| 45 | - $content = str_replace('</h1','</h2', $content); | 33 | + $domain_list = DomainInfo::where('status', 1)->where('amp_status', 1)->get(); |
| 46 | 34 | ||
| 47 | - $product->content = $content; | ||
| 48 | - $product->save(); | 35 | + foreach ($domain_list as $domain) { |
| 36 | + $project_id = $domain->project_id; | ||
| 37 | + $domain = $domain->domain; | ||
| 49 | 38 | ||
| 50 | - $this->output('productID:'.$product->id.',success'); | ||
| 51 | - } | 39 | + $this->output('项目id:' . $project_id . ',start'); |
| 52 | 40 | ||
| 53 | - $this->output('end'); | ||
| 54 | - } | 41 | + //获取项目所在服务器 |
| 42 | + $project_model = new Project(); | ||
| 43 | + $project_info = $project_model->read(['id' => $project_id], ['serve_id']); | ||
| 44 | + if (!$project_info) { | ||
| 45 | + $this->output('未查询到项目数据'); | ||
| 46 | + } | ||
| 47 | + $serve_ip_model = new ServersIp(); | ||
| 48 | + $serve_ip_info = $serve_ip_model->read(['id' => $project_info['serve_id']], ['servers_id']); | ||
| 49 | + if (!$serve_ip_info) { | ||
| 50 | + $this->output('未查询到服务器数据'); | ||
| 51 | + } | ||
| 52 | + $servers_id = $serve_ip_info['servers_id']; | ||
| 55 | 53 | ||
| 56 | - public function check_cname($domain, $server_info) | ||
| 57 | - { | ||
| 58 | - $checkA = false; | ||
| 59 | - $checkCname = false; | 54 | + if ($servers_id == ServerConfig::SELF_SITE_ID) { |
| 55 | + //自建站服务器:如果项目已经上线,不请求C端接口,数据直接入库 | ||
| 56 | + //判断是否已有更新进行中 | ||
| 57 | + $data = [ | ||
| 58 | + 'project_id' => $project_id, | ||
| 59 | + 'type' => 3, | ||
| 60 | + 'route' => 1, | ||
| 61 | + 'server_id' => ServerConfig::SELF_SITE_ID, | ||
| 62 | + 'status' => ['!=', Notify::STATUS_FINISH_SITEMAP] | ||
| 63 | + ]; | ||
| 64 | + $notify = $notify_model->read($data, ['id']); | ||
| 60 | 65 | ||
| 61 | - $process = new Process(['nslookup', '-qt=a', $domain]); | ||
| 62 | - $process->run(); | ||
| 63 | - $output = explode(PHP_EOL, $process->getOutput()); | ||
| 64 | - foreach ($output as $line) { | ||
| 65 | - if ($line) { | ||
| 66 | - $checkA = strpos($line, $server_info['ip']) !== false; | ||
| 67 | - if ($checkA) { | ||
| 68 | - return $domain; | ||
| 69 | - } | ||
| 70 | - } | ||
| 71 | - } | 66 | + if (!$notify) { |
| 67 | + $domain_array = parse_url($domain); | ||
| 68 | + $host = $domain_array['host'] ?? $domain_array['path']; | ||
| 69 | + $host_array = explode('.', $host); | ||
| 70 | + if (count($host_array) <= 2) { | ||
| 71 | + array_unshift($host_array, 'm'); | ||
| 72 | + } else { | ||
| 73 | + $host_array[0] = 'm'; | ||
| 74 | + } | ||
| 75 | + $domain = implode('.', $host_array); | ||
| 72 | 76 | ||
| 73 | - //是否cname | ||
| 74 | - $process = new Process(['nslookup', '-qt=cname', $domain]); | ||
| 75 | - $process->run(); | ||
| 76 | - $output = explode(PHP_EOL, $process->getOutput()); | ||
| 77 | - foreach ($output as $line) { | ||
| 78 | - if ($line) { | ||
| 79 | - $checkCname = (strpos($line, $server_info['domain']) !== false); | ||
| 80 | - if ($checkCname) { | ||
| 81 | - return $domain; | 77 | + $data['data'] = Arr::a2s(['domain' => $domain, 'url' => [], 'language' => []]); |
| 78 | + $data['status'] = Notify::STATUS_INIT; | ||
| 79 | + $notify_model->add($data); | ||
| 82 | } | 80 | } |
| 81 | + } else { | ||
| 82 | + //其他服务器:请求对应C端接口 | ||
| 83 | + $c_url = $domain . '/api/update_page/'; | ||
| 84 | + $param = [ | ||
| 85 | + 'project_id' => $project_id, | ||
| 86 | + 'type' => 3, | ||
| 87 | + 'route' => 1, | ||
| 88 | + 'url' => [], | ||
| 89 | + 'language' => [] | ||
| 90 | + ]; | ||
| 91 | + http_post($c_url, json_encode($param)); | ||
| 83 | } | 92 | } |
| 93 | + $this->output('项目id:' . $project_id . ',end'); | ||
| 84 | } | 94 | } |
| 85 | - return false; | ||
| 86 | } | 95 | } |
| 87 | 96 | ||
| 88 | public function output($msg) | 97 | public function output($msg) |
-
请 注册 或 登录 后发表评论