AiDomainTask.php
2.6 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
96
97
<?php
/**
* @remark :
* @name :AiDomainTask.php
* @author :lyh
* @method :post
* @time :2025/6/19 10:53
*/
namespace App\Console\Commands\Ai;
use App\Models\Domain\DomainInfo;
use Illuminate\Console\Command;
/**
* @remark :拉取项目Ai域名
* @name :AiDomainTask
* @author :lyh
* @method :post
* @time :2025/6/19 10:54
*/
class AiDomainTask extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ai_domain';
/**
* The console command description.
*
* @var string
*/
protected $description = '获取对应域名的ai复制站域名';
public $url = 'https://www.cmer.site/api/globalso_site';
/**
* @remark :执行方法
* @name :handle
* @author :lyh
* @method :post
* @time :2025/6/19 11:32
*/
public function handle(){
$pageSize = 300;
$page = 1;
$res = http_get($this->url.'?pagesize='.$pageSize.'&page='.$page);
if($res['status'] != 200){
echo date('Y-m-d H:i:s').'请求失败,状态码错误'.PHP_EOL;
return false;
}
if(empty($res['data']['data'])){
echo date('Y-m-d H:i:s').'请求失败,未拉取到数据'.PHP_EOL;
return false;
}
$data = $res['data']['data'];
while($page <= $res['data']['last_page']){
$res = http_get($this->url.'?pagesize='.$pageSize.'&page='.$page);
if($res['status'] != 200){
echo date('Y-m-d H:i:s').'第'.$page.'请求失败,未拉取到数据'.PHP_EOL;
return false;
}
$data = array_values(array_merge($data,$res['data']['data']));
$page++;
}
//处理数据
$this->handleData($data);
echo 'end'.PHP_EOL;
return true;
}
/**
* @remark :处理数据
* @name :handleData
* @author :lyh
* @method :post
* @time :2025/6/19 11:21
*/
public function handleData($data){
$domainInfoModel = new DomainInfo();
foreach ($data as $item){
$info = $domainInfoModel->read(['domain'=>$item['domain']],'id');
if($info === false){
$info = $domainInfoModel->read(['domain'=>$item['globalso_domain']],'id');
if($info !== false){
$domainInfoModel->edit(['ai_domain'=>$item['domain']],['id'=>$info['id']]);
}
}else{
$domainInfoModel->edit(['ai_domain'=>$item['globalso_domain']],['id'=>$info['id']]);
}
}
return true;
}
}