RankData.php
2.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
<?php
namespace App\Console\Commands\RankData;
use App\Helper\QuanqiusouApi;
use App\Models\RankData\RankDataLog as RankDataLogModel;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
/**
* Class GoogleRank
* @package App\Console\Commands
* @author zbj
* @date 2023/5/6
*/
class RankData extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data';
/**
* The console command description.
* The console command description.
*
* @var string
*/
protected $description = '分发任务';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
try {
Log::channel('rank_data')->info('开始-排名数据');
//所有项目 今日是否达标 重置
//有失败会重跑任务,导致达标又被重置 加缓存一天只重置一次
if (!Cache::get('clear_remain_today_' . date('Y-m-d'))) {
Project::where('is_remain_today', 1)->update(['is_remain_today' => 0]);
Cache::set('clear_remain_today_' . date('Y-m-d'), 1, 24 * 3600);
}
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->select('api_no', 'project_id')->orderBy('project_id', 'asc')->get();
Log::channel('rank_data')->info('开始-排名数据-' . count($list));
foreach ($list as $item){
RankDataLogModel::addTask($item['project_id'], $item['api_no']);
}
//小语种
$api = new QuanqiusouApi();
$lang_list = $api->getLangList();
foreach ($list as $item){
$langs = $lang_list[$item['api_no']] ?? [];
foreach ($langs as $lang){
RankDataLogModel::addTask($item['project_id'], $item['api_no'], $lang);
}
}
} catch (\Exception|\Throwable $e) {
Log::channel('rank_data')->error('排名数据任务失败 ' . $e->getMessage());
}
return true;
}
}