Speed.php
1.8 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
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\GoogleSpeedApi;
use App\Models\Domain\DomainInfo;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\Speed as GoogleSpeedModel;
use App\Utils\LogUtils;
/**
* Class GoogleSpeed
* @package App\Console\Commands
* @author zbj
* @date 2023/5/10
*/
class Speed extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_speed';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-测速数据';
/**
* @author zbj
* @date 2023/5/10
*/
public function do()
{
$error = 0;
$googleSpeedApi = new GoogleSpeedApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray();
LogUtils::info('start rank_data_speed:' . count($list));
foreach ($list as $project_id => $domain) {
$model = GoogleSpeedModel::where('project_id', $project_id)->first();
if ($model && $model->updated_date == getThisWeekStarDate()) {
//今周已更新 跳过
continue;
}
$domain = (new DomainInfo())->getDomain($domain);
$res = $googleSpeedApi->run($domain);
if (!$res) {
$error++;
continue;
}
if (!$model) {
$model = new GoogleSpeedModel;
}
$model->project_id = $project_id;
$model->data = $res;
$model->updated_date = date('Y-m-d');
$model->save();
}
return !$error;
}
}