作者 赵彬吉

update

@@ -37,7 +37,7 @@ class SemrushApi @@ -37,7 +37,7 @@ class SemrushApi
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 }
@@ -358,9 +358,10 @@ class RankDataLogic extends BaseLogic @@ -358,9 +358,10 @@ class RankDataLogic extends BaseLogic
358 * @date 2023/9/20 358 * @date 2023/9/20
359 */ 359 */
360 public function syncRankData($api_no, $site_res){ 360 public function syncRankData($api_no, $site_res){
361 - $project_id = DeployOptimize::where('api_no', $api_no)->value('project_id'); 361 + $project_ids = DeployOptimize::where('api_no', $api_no)->pluck('project_id');
  362 + foreach ($project_ids as $project_id) {
362 $project = Project::find($project_id); 363 $project = Project::find($project_id);
363 - if(!$project){ 364 + if (!$project) {
364 throw new \Exception($api_no . '关联的项目不存在'); 365 throw new \Exception($api_no . '关联的项目不存在');
365 } 366 }
366 367
@@ -369,7 +370,7 @@ class RankDataLogic extends BaseLogic @@ -369,7 +370,7 @@ class RankDataLogic extends BaseLogic
369 $model = RankData::where('project_id', $project_id)->where('lang', '')->first(); 370 $model = RankData::where('project_id', $project_id)->where('lang', '')->first();
370 if (!$model || $model->updated_date != date('Y-m-d')) { 371 if (!$model || $model->updated_date != date('Y-m-d')) {
371 $res = $api->getGoogleRank($api_no); 372 $res = $api->getGoogleRank($api_no);
372 - if(!$res){ 373 + if (!$res) {
373 throw new \Exception('接口数据获取失败'); 374 throw new \Exception('接口数据获取失败');
374 } 375 }
375 //收录数 376 //收录数
@@ -378,24 +379,25 @@ class RankDataLogic extends BaseLogic @@ -378,24 +379,25 @@ class RankDataLogic extends BaseLogic
378 } 379 }
379 //有小语种的 380 //有小语种的
380 $lang_list = $api->getLangList(); 381 $lang_list = $api->getLangList();
381 - if(!empty($lang_list[$api_no])){ 382 + if (!empty($lang_list[$api_no])) {
382 $model = RankData::where('project_id', $project_id)->where('lang', '<>', '')->first(); 383 $model = RankData::where('project_id', $project_id)->where('lang', '<>', '')->first();
383 if (!$model || $model->updated_date != date('Y-m-d')) { 384 if (!$model || $model->updated_date != date('Y-m-d')) {
384 $res = $api->getGoogleRank($api_no, 1); 385 $res = $api->getGoogleRank($api_no, 1);
385 - if(!$res){ 386 + if (!$res) {
386 throw new \Exception('接口数据获取失败'); 387 throw new \Exception('接口数据获取失败');
387 } 388 }
388 $data = []; 389 $data = [];
389 //不同的小语种取出来 390 //不同的小语种取出来
390 - foreach ($res as $keyword => $v){ 391 + foreach ($res as $keyword => $v) {
391 $data[Arr::last($v)['lang']][$keyword] = $v; 392 $data[Arr::last($v)['lang']][$keyword] = $v;
392 } 393 }
393 - foreach ($data as $lang => $rank){ 394 + foreach ($data as $lang => $rank) {
394 $this->save_rank($project_id, $rank, 0, $lang); 395 $this->save_rank($project_id, $rank, 0, $lang);
395 } 396 }
396 } 397 }
397 } 398 }
398 } 399 }
  400 + }
399 401
400 /** 402 /**
401 * @param $project_id 403 * @param $project_id