Temp.php
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace App\Console\Commands\Test;
use App\Helper\Arr;
use App\Models\Com\Notify;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use Illuminate\Console\Command;
class Temp extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test_temp';
/**
* The console command description.
*
* @var string
*/
protected $description = '临时脚本';
public function handle()
{
$notify_model = new Notify();
$project_model = new Project();
$serve_ip_model = new ServersIp();
$domain_list = DomainInfo::where('status', 1)->where('amp_status', 1)->get();
foreach ($domain_list as $domain_info) {
$project_id = $domain_info->project_id;
$domain = $domain_info->domain;
$this->output('项目id:' . $project_id . ',start');
//获取项目所在服务器
$project_info = $project_model->read(['id' => $project_id], ['serve_id']);
if (!$project_info) {
$this->output('未查询到项目数据');
}
$serve_ip_info = $serve_ip_model->read(['id' => $project_info['serve_id']], ['servers_id']);
if (!$serve_ip_info) {
$this->output('未查询到服务器数据');
}
$servers_id = $serve_ip_info['servers_id'];
if ($servers_id == ServerConfig::SELF_SITE_ID) {
//自建站服务器:如果项目已经上线,不请求C端接口,数据直接入库
//判断是否已有更新进行中
$data = [
'project_id' => $project_id,
'type' => 3,
'route' => 1,
'server_id' => ServerConfig::SELF_SITE_ID,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data, ['id']);
if (!$notify) {
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$domain = implode('.', $host_array);
$data['data'] = Arr::a2s(['domain' => $domain, 'url' => [], 'language' => []]);
$data['status'] = Notify::STATUS_INIT;
$notify_model->add($data);
}
} else {
//其他服务器:请求对应C端接口
$c_url = $domain . '/api/update_page/?project_id=' . $project_id . '&type=3';
$re = http_get($c_url);
$this->output($re['message'] ?? '');
}
$this->output('项目id:' . $project_id . ',end');
}
}
public function output($msg)
{
echo $msg . PHP_EOL;
}
}