作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

... ... @@ -38,7 +38,7 @@ abstract class BaseCommands extends Command
if($error){
echo 'error';
}
$error && sleep(60);
$error && sleep(10);
}while($error);
}
... ...
... ... @@ -47,7 +47,7 @@ class ExternalLinks extends BaseCommands
continue;
}
$model = ExternalLinksModel::where('project_id', $project_id)->first();
if ($model && $model->updated_date == getThisWeekStarDate()) {
if ($model && $model->updated_date >= getThisWeekStarDate()) {
continue;
}
if (!$model) {
... ...
... ... @@ -42,7 +42,7 @@ class IndexedPages extends BaseCommands
LogUtils::info('start rank_data_indexed_pages:' . count($list));
foreach ($list as $project_id => $api_no) {
$model = IndexedPagesModel::where('project_id', $project_id)->first();
if($model && $model->updated_date == getThisWeekStarDate()){
if($model && $model->updated_date >= getThisWeekStarDate()){
continue;
}
... ...
... ... @@ -59,7 +59,7 @@ class RankDataTask extends Command
$api = new QuanqiusouApi();
$site_res = $api->getSiteRes();
(new RankDataLogic())->syncRankData($item['data']['api_no'], $site_res);
(new RankDataLogic())->syncRankData($item['data']['api_no'], $site_res, true);
$item->status = NoticeLog::STATUS_SUCCESS;
$item->save();
... ...
... ... @@ -53,7 +53,7 @@ class RankWeek extends BaseCommands
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()) {
if ($rank_week && $rank_week->updated_date >= getThisWeekStarDate()) {
//本周数据已更新
continue;
}
... ...
... ... @@ -46,7 +46,7 @@ class RecommDomain extends BaseCommands
continue;
}
$model = RecommDomainModel::where('project_id', $project_id)->first();
if ($model && $model->updated_date == getThisWeekStarDate()) {
if ($model && $model->updated_date >= getThisWeekStarDate()) {
continue;
}
if (!$model) {
... ...
... ... @@ -47,7 +47,7 @@ class Speed extends BaseCommands
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()) {
if ($model && $model->updated_date >= getThisWeekStarDate()) {
//今周已更新 跳过
continue;
}
... ...
... ... @@ -19,11 +19,11 @@ class Kernel extends ConsoleKernel
$schedule->command('remain_day')->dailyAt('03:00')->withoutOverlapping(1); // 项目剩余服务时长
$schedule->command('rank_data_task')->everyMinute()->withoutOverlapping(1); // 排名数据更新任务
$schedule->command('rank_data')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每天凌晨执行一次
$schedule->command('rank_data_speed')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-测速数据,每周一凌晨执行一次
$schedule->command('rank_data_external_links')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-外链,每周一凌晨执行一次
$schedule->command('rank_data_indexed_pages')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次
$schedule->command('rank_data_recomm_domain')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次
$schedule->command('rank_data_week')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次
$schedule->command('rank_data_speed')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-测速数据,每周一凌晨执行一次
$schedule->command('rank_data_external_links')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-外链,每周一凌晨执行一次
$schedule->command('rank_data_indexed_pages')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次
$schedule->command('rank_data_recomm_domain')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次
$schedule->command('rank_data_week')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次
// $schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次
$schedule->command('count')->dailyAt('01:00')->withoutOverlapping(1); //每天凌晨1点执行一次
$schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
... ...
... ... @@ -34,7 +34,7 @@ class QuanqiusouApi
$res = HttpUtils::get($api_url, []);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取站点收录页面数', [], $e);
... ... @@ -60,7 +60,7 @@ class QuanqiusouApi
$res = HttpUtils::get($api_url, ['apino' => $api_no]);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取站点收录页面数', [], $e);
... ... @@ -80,11 +80,11 @@ class QuanqiusouApi
* @author zbj
* @date 2023/5/11
*/
public function getGoogleRank($api_no, int $lang = 0, int $day = 7)
public function getGoogleRank($api_no, int $lang = 0, int $day = 7, $force = true)
{
$key = "quanqiusou_api_rank_{$api_no}_{$lang}_{$day}_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
if (!$res || $force) {
$param = [
'key' => '289c1fc81c89d79c04ed4fd72822948e',
'w' => $api_no,
... ... @@ -100,7 +100,7 @@ class QuanqiusouApi
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取谷歌排名数据失败', $api_no, $e);
... ... @@ -127,7 +127,7 @@ class QuanqiusouApi
$res = HttpUtils::get($api_url, []);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取每周谷歌排名数据失败', [], $e);
... ... @@ -162,7 +162,7 @@ class QuanqiusouApi
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取历史排名统计数据失败', [], $e);
... ... @@ -221,7 +221,7 @@ class QuanqiusouApi
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取项目小语种数据失败', [], $e);
... ... @@ -249,7 +249,7 @@ class QuanqiusouApi
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取项目API_NO数据失败', [], $e);
... ...
... ... @@ -35,9 +35,9 @@ class SemrushApi
];
try {
$res = HttpUtils::get($url, $params);
return $this->data($res)[0];
return $this->data($res)[0] ?? [];
}catch (\Exception|GuzzleException $e){
errorLog('获取站点外链数据', $params, $e);
errorLog('获取站点外链数据失败', $params, $e);
return false;
}
}
... ... @@ -63,7 +63,7 @@ class SemrushApi
$res = HttpUtils::get($url, $params);
return $this->data($res);
}catch (\Exception|GuzzleException $e){
errorLog('获取站点外链数据', $params, $e);
errorLog('获取站点外链数据失败', $params, $e);
return false;
}
}
... ...
... ... @@ -357,19 +357,20 @@ class RankDataLogic extends BaseLogic
* @author zbj
* @date 2023/9/20
*/
public function syncRankData($api_no, $site_res){
$project_id = DeployOptimize::where('api_no', $api_no)->value('project_id');
public function syncRankData($api_no, $site_res, $force=false){
$project_ids = DeployOptimize::where('api_no', $api_no)->pluck('project_id');
foreach ($project_ids as $project_id) {
$project = Project::find($project_id);
if(!$project){
if (!$project) {
throw new \Exception($api_no . '关联的项目不存在');
}
$api = new QuanqiusouApi();
$model = RankData::where('project_id', $project_id)->where('lang', '')->first();
if (!$model || $model->updated_date != date('Y-m-d')) {
$res = $api->getGoogleRank($api_no);
if(!$res){
if (!$model || $model->updated_date != date('Y-m-d') || $force) {
$res = $api->getGoogleRank($api_no, 0, 7, $force);
if (!$res) {
throw new \Exception('接口数据获取失败');
}
//收录数
... ... @@ -378,24 +379,25 @@ class RankDataLogic extends BaseLogic
}
//有小语种的
$lang_list = $api->getLangList();
if(!empty($lang_list[$api_no])){
if (!empty($lang_list[$api_no])) {
$model = RankData::where('project_id', $project_id)->where('lang', '<>', '')->first();
if (!$model || $model->updated_date != date('Y-m-d')) {
$res = $api->getGoogleRank($api_no, 1);
if(!$res){
if (!$model || $model->updated_date != date('Y-m-d') || $force) {
$res = $api->getGoogleRank($api_no, 1, 7, $force);
if (!$res) {
throw new \Exception('接口数据获取失败');
}
$data = [];
//不同的小语种取出来
foreach ($res as $keyword => $v){
foreach ($res as $keyword => $v) {
$data[Arr::last($v)['lang']][$keyword] = $v;
}
foreach ($data as $lang => $rank){
foreach ($data as $lang => $rank) {
$this->save_rank($project_id, $rank, 0, $lang);
}
}
}
}
}
/**
* @param $project_id
... ...