作者 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 @@ -38,7 +38,7 @@ abstract class BaseCommands extends Command
38 if($error){ 38 if($error){
39 echo 'error'; 39 echo 'error';
40 } 40 }
41 - $error && sleep(60); 41 + $error && sleep(10);
42 }while($error); 42 }while($error);
43 } 43 }
44 44
@@ -47,7 +47,7 @@ class ExternalLinks extends BaseCommands @@ -47,7 +47,7 @@ class ExternalLinks extends BaseCommands
47 continue; 47 continue;
48 } 48 }
49 $model = ExternalLinksModel::where('project_id', $project_id)->first(); 49 $model = ExternalLinksModel::where('project_id', $project_id)->first();
50 - if ($model && $model->updated_date == getThisWeekStarDate()) { 50 + if ($model && $model->updated_date >= getThisWeekStarDate()) {
51 continue; 51 continue;
52 } 52 }
53 if (!$model) { 53 if (!$model) {
@@ -42,7 +42,7 @@ class IndexedPages extends BaseCommands @@ -42,7 +42,7 @@ class IndexedPages extends BaseCommands
42 LogUtils::info('start rank_data_indexed_pages:' . count($list)); 42 LogUtils::info('start rank_data_indexed_pages:' . count($list));
43 foreach ($list as $project_id => $api_no) { 43 foreach ($list as $project_id => $api_no) {
44 $model = IndexedPagesModel::where('project_id', $project_id)->first(); 44 $model = IndexedPagesModel::where('project_id', $project_id)->first();
45 - if($model && $model->updated_date == getThisWeekStarDate()){ 45 + if($model && $model->updated_date >= getThisWeekStarDate()){
46 continue; 46 continue;
47 } 47 }
48 48
@@ -59,7 +59,7 @@ class RankDataTask extends Command @@ -59,7 +59,7 @@ class RankDataTask extends Command
59 $api = new QuanqiusouApi(); 59 $api = new QuanqiusouApi();
60 $site_res = $api->getSiteRes(); 60 $site_res = $api->getSiteRes();
61 61
62 - (new RankDataLogic())->syncRankData($item['data']['api_no'], $site_res); 62 + (new RankDataLogic())->syncRankData($item['data']['api_no'], $site_res, true);
63 63
64 $item->status = NoticeLog::STATUS_SUCCESS; 64 $item->status = NoticeLog::STATUS_SUCCESS;
65 $item->save(); 65 $item->save();
@@ -53,7 +53,7 @@ class RankWeek extends BaseCommands @@ -53,7 +53,7 @@ class RankWeek extends BaseCommands
53 LogUtils::info('start rank_data_week:' . count($list)); 53 LogUtils::info('start rank_data_week:' . count($list));
54 foreach ($list as $project_id => $api_no) { 54 foreach ($list as $project_id => $api_no) {
55 $rank_week = RankWeekModel::where('project_id', $project_id)->first(); 55 $rank_week = RankWeekModel::where('project_id', $project_id)->first();
56 - if ($rank_week && $rank_week->updated_date == getThisWeekStarDate()) { 56 + if ($rank_week && $rank_week->updated_date >= getThisWeekStarDate()) {
57 //本周数据已更新 57 //本周数据已更新
58 continue; 58 continue;
59 } 59 }
@@ -46,7 +46,7 @@ class RecommDomain extends BaseCommands @@ -46,7 +46,7 @@ class RecommDomain extends BaseCommands
46 continue; 46 continue;
47 } 47 }
48 $model = RecommDomainModel::where('project_id', $project_id)->first(); 48 $model = RecommDomainModel::where('project_id', $project_id)->first();
49 - if ($model && $model->updated_date == getThisWeekStarDate()) { 49 + if ($model && $model->updated_date >= getThisWeekStarDate()) {
50 continue; 50 continue;
51 } 51 }
52 if (!$model) { 52 if (!$model) {
@@ -47,7 +47,7 @@ class Speed extends BaseCommands @@ -47,7 +47,7 @@ class Speed extends BaseCommands
47 LogUtils::info('start rank_data_speed:' . count($list)); 47 LogUtils::info('start rank_data_speed:' . count($list));
48 foreach ($list as $project_id => $domain) { 48 foreach ($list as $project_id => $domain) {
49 $model = GoogleSpeedModel::where('project_id', $project_id)->first(); 49 $model = GoogleSpeedModel::where('project_id', $project_id)->first();
50 - if ($model && $model->updated_date == getThisWeekStarDate()) { 50 + if ($model && $model->updated_date >= getThisWeekStarDate()) {
51 //今周已更新 跳过 51 //今周已更新 跳过
52 continue; 52 continue;
53 } 53 }
@@ -19,11 +19,11 @@ class Kernel extends ConsoleKernel @@ -19,11 +19,11 @@ class Kernel extends ConsoleKernel
19 $schedule->command('remain_day')->dailyAt('03:00')->withoutOverlapping(1); // 项目剩余服务时长 19 $schedule->command('remain_day')->dailyAt('03:00')->withoutOverlapping(1); // 项目剩余服务时长
20 $schedule->command('rank_data_task')->everyMinute()->withoutOverlapping(1); // 排名数据更新任务 20 $schedule->command('rank_data_task')->everyMinute()->withoutOverlapping(1); // 排名数据更新任务
21 $schedule->command('rank_data')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每天凌晨执行一次 21 $schedule->command('rank_data')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每天凌晨执行一次
22 - $schedule->command('rank_data_speed')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-测速数据,每周一凌晨执行一次  
23 - $schedule->command('rank_data_external_links')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-外链,每周一凌晨执行一次  
24 - $schedule->command('rank_data_indexed_pages')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次  
25 - $schedule->command('rank_data_recomm_domain')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次  
26 - $schedule->command('rank_data_week')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次 22 + $schedule->command('rank_data_speed')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-测速数据,每周一凌晨执行一次
  23 + $schedule->command('rank_data_external_links')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-外链,每周一凌晨执行一次
  24 + $schedule->command('rank_data_indexed_pages')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次
  25 + $schedule->command('rank_data_recomm_domain')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次
  26 + $schedule->command('rank_data_week')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次
27 // $schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次 27 // $schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次
28 $schedule->command('count')->dailyAt('01:00')->withoutOverlapping(1); //每天凌晨1点执行一次 28 $schedule->command('count')->dailyAt('01:00')->withoutOverlapping(1); //每天凌晨1点执行一次
29 $schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次 29 $schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
@@ -34,7 +34,7 @@ class QuanqiusouApi @@ -34,7 +34,7 @@ class QuanqiusouApi
34 $res = HttpUtils::get($api_url, []); 34 $res = HttpUtils::get($api_url, []);
35 if($res){ 35 if($res){
36 $res = Arr::s2a($res); 36 $res = Arr::s2a($res);
37 - Cache::put($key, $res, 24 * 3600); 37 + Cache::put($key, $res, 2 * 3600);
38 } 38 }
39 } catch (\Exception | GuzzleException $e) { 39 } catch (\Exception | GuzzleException $e) {
40 errorLog('获取站点收录页面数', [], $e); 40 errorLog('获取站点收录页面数', [], $e);
@@ -60,7 +60,7 @@ class QuanqiusouApi @@ -60,7 +60,7 @@ class QuanqiusouApi
60 $res = HttpUtils::get($api_url, ['apino' => $api_no]); 60 $res = HttpUtils::get($api_url, ['apino' => $api_no]);
61 if($res){ 61 if($res){
62 $res = Arr::s2a($res); 62 $res = Arr::s2a($res);
63 - Cache::put($key, $res, 24 * 3600); 63 + Cache::put($key, $res, 2 * 3600);
64 } 64 }
65 } catch (\Exception | GuzzleException $e) { 65 } catch (\Exception | GuzzleException $e) {
66 errorLog('获取站点收录页面数', [], $e); 66 errorLog('获取站点收录页面数', [], $e);
@@ -80,11 +80,11 @@ class QuanqiusouApi @@ -80,11 +80,11 @@ class QuanqiusouApi
80 * @author zbj 80 * @author zbj
81 * @date 2023/5/11 81 * @date 2023/5/11
82 */ 82 */
83 - public function getGoogleRank($api_no, int $lang = 0, int $day = 7) 83 + public function getGoogleRank($api_no, int $lang = 0, int $day = 7, $force = true)
84 { 84 {
85 $key = "quanqiusou_api_rank_{$api_no}_{$lang}_{$day}_" . date('Y-m-d'); 85 $key = "quanqiusou_api_rank_{$api_no}_{$lang}_{$day}_" . date('Y-m-d');
86 $res = Cache::get($key); 86 $res = Cache::get($key);
87 - if (!$res) { 87 + if (!$res || $force) {
88 $param = [ 88 $param = [
89 'key' => '289c1fc81c89d79c04ed4fd72822948e', 89 'key' => '289c1fc81c89d79c04ed4fd72822948e',
90 'w' => $api_no, 90 'w' => $api_no,
@@ -100,7 +100,7 @@ class QuanqiusouApi @@ -100,7 +100,7 @@ class QuanqiusouApi
100 $res = HttpUtils::get($api_url, $param); 100 $res = HttpUtils::get($api_url, $param);
101 if($res){ 101 if($res){
102 $res = Arr::s2a($res); 102 $res = Arr::s2a($res);
103 - Cache::put($key, $res, 24 * 3600); 103 + Cache::put($key, $res, 2 * 3600);
104 } 104 }
105 } catch (\Exception | GuzzleException $e) { 105 } catch (\Exception | GuzzleException $e) {
106 errorLog('获取谷歌排名数据失败', $api_no, $e); 106 errorLog('获取谷歌排名数据失败', $api_no, $e);
@@ -127,7 +127,7 @@ class QuanqiusouApi @@ -127,7 +127,7 @@ class QuanqiusouApi
127 $res = HttpUtils::get($api_url, []); 127 $res = HttpUtils::get($api_url, []);
128 if($res){ 128 if($res){
129 $res = Arr::s2a($res); 129 $res = Arr::s2a($res);
130 - Cache::put($key, $res, 24 * 3600); 130 + Cache::put($key, $res, 2 * 3600);
131 } 131 }
132 } catch (\Exception | GuzzleException $e) { 132 } catch (\Exception | GuzzleException $e) {
133 errorLog('获取每周谷歌排名数据失败', [], $e); 133 errorLog('获取每周谷歌排名数据失败', [], $e);
@@ -162,7 +162,7 @@ class QuanqiusouApi @@ -162,7 +162,7 @@ class QuanqiusouApi
162 $res = HttpUtils::get($api_url, $param); 162 $res = HttpUtils::get($api_url, $param);
163 if($res){ 163 if($res){
164 $res = Arr::s2a($res); 164 $res = Arr::s2a($res);
165 - Cache::put($key, $res, 24 * 3600); 165 + Cache::put($key, $res, 2 * 3600);
166 } 166 }
167 } catch (\Exception | GuzzleException $e) { 167 } catch (\Exception | GuzzleException $e) {
168 errorLog('获取历史排名统计数据失败', [], $e); 168 errorLog('获取历史排名统计数据失败', [], $e);
@@ -221,7 +221,7 @@ class QuanqiusouApi @@ -221,7 +221,7 @@ class QuanqiusouApi
221 $res = HttpUtils::get($api_url, $param); 221 $res = HttpUtils::get($api_url, $param);
222 if($res){ 222 if($res){
223 $res = Arr::s2a($res); 223 $res = Arr::s2a($res);
224 - Cache::put($key, $res, 24 * 3600); 224 + Cache::put($key, $res, 2 * 3600);
225 } 225 }
226 } catch (\Exception | GuzzleException $e) { 226 } catch (\Exception | GuzzleException $e) {
227 errorLog('获取项目小语种数据失败', [], $e); 227 errorLog('获取项目小语种数据失败', [], $e);
@@ -249,7 +249,7 @@ class QuanqiusouApi @@ -249,7 +249,7 @@ class QuanqiusouApi
249 $res = HttpUtils::get($api_url, $param); 249 $res = HttpUtils::get($api_url, $param);
250 if($res){ 250 if($res){
251 $res = Arr::s2a($res); 251 $res = Arr::s2a($res);
252 - Cache::put($key, $res, 24 * 3600); 252 + Cache::put($key, $res, 2 * 3600);
253 } 253 }
254 } catch (\Exception | GuzzleException $e) { 254 } catch (\Exception | GuzzleException $e) {
255 errorLog('获取项目API_NO数据失败', [], $e); 255 errorLog('获取项目API_NO数据失败', [], $e);
@@ -35,9 +35,9 @@ class SemrushApi @@ -35,9 +35,9 @@ class SemrushApi
35 ]; 35 ];
36 try { 36 try {
37 $res = HttpUtils::get($url, $params); 37 $res = HttpUtils::get($url, $params);
38 - return $this->data($res)[0]; 38 + return $this->data($res)[0] ?? [];
39 }catch (\Exception|GuzzleException $e){ 39 }catch (\Exception|GuzzleException $e){
40 - errorLog('获取站点外链数据', $params, $e); 40 + errorLog('获取站点外链数据失败', $params, $e);
41 return false; 41 return false;
42 } 42 }
43 } 43 }
@@ -63,7 +63,7 @@ class SemrushApi @@ -63,7 +63,7 @@ class SemrushApi
63 $res = HttpUtils::get($url, $params); 63 $res = HttpUtils::get($url, $params);
64 return $this->data($res); 64 return $this->data($res);
65 }catch (\Exception|GuzzleException $e){ 65 }catch (\Exception|GuzzleException $e){
66 - errorLog('获取站点外链数据', $params, $e); 66 + errorLog('获取站点外链数据失败', $params, $e);
67 return false; 67 return false;
68 } 68 }
69 } 69 }
@@ -357,41 +357,43 @@ class RankDataLogic extends BaseLogic @@ -357,41 +357,43 @@ class RankDataLogic extends BaseLogic
357 * @author zbj 357 * @author zbj
358 * @date 2023/9/20 358 * @date 2023/9/20
359 */ 359 */
360 - public function syncRankData($api_no, $site_res){  
361 - $project_id = DeployOptimize::where('api_no', $api_no)->value('project_id');  
362 - $project = Project::find($project_id);  
363 - if(!$project){  
364 - throw new \Exception($api_no . '关联的项目不存在');  
365 - } 360 + public function syncRankData($api_no, $site_res, $force=false){
  361 + $project_ids = DeployOptimize::where('api_no', $api_no)->pluck('project_id');
  362 + foreach ($project_ids as $project_id) {
  363 + $project = Project::find($project_id);
  364 + if (!$project) {
  365 + throw new \Exception($api_no . '关联的项目不存在');
  366 + }
366 367
367 - $api = new QuanqiusouApi(); 368 + $api = new QuanqiusouApi();
368 369
369 - $model = RankData::where('project_id', $project_id)->where('lang', '')->first();  
370 - if (!$model || $model->updated_date != date('Y-m-d')) {  
371 - $res = $api->getGoogleRank($api_no);  
372 - if(!$res){  
373 - throw new \Exception('接口数据获取失败');  
374 - }  
375 - //收录数  
376 - $indexed_pages_num = $site_res[$api_no] ?? 0;  
377 - $this->save_rank($project_id, $res, $indexed_pages_num);  
378 - }  
379 - //有小语种的  
380 - $lang_list = $api->getLangList();  
381 - if(!empty($lang_list[$api_no])){  
382 - $model = RankData::where('project_id', $project_id)->where('lang', '<>', '')->first();  
383 - if (!$model || $model->updated_date != date('Y-m-d')) {  
384 - $res = $api->getGoogleRank($api_no, 1);  
385 - if(!$res){ 370 + $model = RankData::where('project_id', $project_id)->where('lang', '')->first();
  371 + if (!$model || $model->updated_date != date('Y-m-d') || $force) {
  372 + $res = $api->getGoogleRank($api_no, 0, 7, $force);
  373 + if (!$res) {
386 throw new \Exception('接口数据获取失败'); 374 throw new \Exception('接口数据获取失败');
387 } 375 }
388 - $data = [];  
389 - //不同的小语种取出来  
390 - foreach ($res as $keyword => $v){  
391 - $data[Arr::last($v)['lang']][$keyword] = $v;  
392 - }  
393 - foreach ($data as $lang => $rank){  
394 - $this->save_rank($project_id, $rank, 0, $lang); 376 + //收录数
  377 + $indexed_pages_num = $site_res[$api_no] ?? 0;
  378 + $this->save_rank($project_id, $res, $indexed_pages_num);
  379 + }
  380 + //有小语种的
  381 + $lang_list = $api->getLangList();
  382 + if (!empty($lang_list[$api_no])) {
  383 + $model = RankData::where('project_id', $project_id)->where('lang', '<>', '')->first();
  384 + if (!$model || $model->updated_date != date('Y-m-d') || $force) {
  385 + $res = $api->getGoogleRank($api_no, 1, 7, $force);
  386 + if (!$res) {
  387 + throw new \Exception('接口数据获取失败');
  388 + }
  389 + $data = [];
  390 + //不同的小语种取出来
  391 + foreach ($res as $keyword => $v) {
  392 + $data[Arr::last($v)['lang']][$keyword] = $v;
  393 + }
  394 + foreach ($data as $lang => $rank) {
  395 + $this->save_rank($project_id, $rank, 0, $lang);
  396 + }
395 } 397 }
396 } 398 }
397 } 399 }