RankWeek.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
72
73
74
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\QuanqiusouApi;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\RankWeek as RankWeekModel;
use App\Utils\LogUtils;
/**
* Class WeekRank
* @package App\Console\Commands
* @author zbj
* @date 2023/5/11
*/
class RankWeek extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_week';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-每周排名数据';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
$error = 0;
//获取每周排名数据
$api = new QuanqiusouApi();
$res = $api->getGoogleRankWeek();
if (!$res) {
return false;
}
$res = Arr::s2a($res);
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('api_no', 'project_id')->toArray();
LogUtils::info('start rank_data_week:' . count($list));
foreach ($list as $project_id => $api_no) {
$rank_week = RankWeekModel::where('project_id', $project_id)->first();
if ($rank_week && $rank_week->updated_date >= getThisWeekStarDate()) {
//本周数据已更新
continue;
}
if (!$rank_week) {
$rank_week = new RankWeekModel();
}
$rank_week->project_id = $project_id;
$rank_week->data = $res['data'][$api_no];
$rank_week->date = $res['date'];
$rank_week->updated_date = date('Y-m-d');
$rank_week->save();
}
return !$error;
}
}