作者 lyh

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

@@ -7,6 +7,7 @@ use App\Helper\SemrushApi; @@ -7,6 +7,7 @@ use App\Helper\SemrushApi;
7 use App\Models\Domain\DomainInfo; 7 use App\Models\Domain\DomainInfo;
8 use App\Models\RankData\ExternalLinks as ExternalLinksModel; 8 use App\Models\RankData\ExternalLinks as ExternalLinksModel;
9 use App\Models\Project\DeployOptimize; 9 use App\Models\Project\DeployOptimize;
  10 +use App\Utils\HttpUtils;
10 use App\Utils\LogUtils; 11 use App\Utils\LogUtils;
11 12
12 /** 13 /**
@@ -40,9 +41,12 @@ class ExternalLinks extends BaseCommands @@ -40,9 +41,12 @@ class ExternalLinks extends BaseCommands
40 $error = 0; 41 $error = 0;
41 $semrushApi = new SemrushApi(); 42 $semrushApi = new SemrushApi();
42 //有排名api编号的项目 43 //有排名api编号的项目
43 - $list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray(); 44 + $list = DeployOptimize::where('api_no', '>', 0)->select('domain', 'api_no', 'project_id')->get()->toArray();
44 LogUtils::info('start rank_data_external_links:' . count($list)); 45 LogUtils::info('start rank_data_external_links:' . count($list));
45 - foreach ($list as $project_id => $domain) { 46 + foreach ($list as $item) {
  47 + $project_id = $item['project_id'];
  48 + $api_no = $item['api_no'];
  49 + $domain = $item['domain'];
46 if(!$domain){ 50 if(!$domain){
47 continue; 51 continue;
48 } 52 }
@@ -54,6 +58,16 @@ class ExternalLinks extends BaseCommands @@ -54,6 +58,16 @@ class ExternalLinks extends BaseCommands
54 $model = new ExternalLinksModel(); 58 $model = new ExternalLinksModel();
55 } 59 }
56 60
  61 +
  62 + //5.0
  63 + try {
  64 + $data = HttpUtils::get("https://www.quanqiusou.cn/semrush-api/data_json/{$api_no}.json", []);
  65 + $data = Arr::s2a($data);
  66 + }catch (\Exception $e){
  67 + $data = [];
  68 + }
  69 +
  70 + if(!$data){
57 //外链数据 71 //外链数据
58 $domain = (new DomainInfo())->getDomain($domain); 72 $domain = (new DomainInfo())->getDomain($domain);
59 $res = $semrushApi->backlinks_overview($domain); 73 $res = $semrushApi->backlinks_overview($domain);
@@ -63,6 +77,7 @@ class ExternalLinks extends BaseCommands @@ -63,6 +77,7 @@ class ExternalLinks extends BaseCommands
63 } 77 }
64 78
65 $data = $this->_data($project_id, $res['total']); 79 $data = $this->_data($project_id, $res['total']);
  80 + }
66 81
67 $model->project_id = $project_id; 82 $model->project_id = $project_id;
68 $model->total = $data['total']; 83 $model->total = $data['total'];
@@ -2,10 +2,12 @@ @@ -2,10 +2,12 @@
2 2
3 namespace App\Console\Commands\RankData; 3 namespace App\Console\Commands\RankData;
4 4
  5 +use App\Helper\Arr;
5 use App\Helper\SemrushApi; 6 use App\Helper\SemrushApi;
6 use App\Models\Domain\DomainInfo; 7 use App\Models\Domain\DomainInfo;
7 use App\Models\RankData\RecommDomain as RecommDomainModel; 8 use App\Models\RankData\RecommDomain as RecommDomainModel;
8 use App\Models\Project\DeployOptimize; 9 use App\Models\Project\DeployOptimize;
  10 +use App\Utils\HttpUtils;
9 use App\Utils\LogUtils; 11 use App\Utils\LogUtils;
10 12
11 /** 13 /**
@@ -39,9 +41,12 @@ class RecommDomain extends BaseCommands @@ -39,9 +41,12 @@ class RecommDomain extends BaseCommands
39 $error = 0; 41 $error = 0;
40 $semrushApi = new SemrushApi(); 42 $semrushApi = new SemrushApi();
41 //有排名api编号的项目 43 //有排名api编号的项目
42 - $list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray(); 44 + $list = DeployOptimize::where('api_no', '>', 0)->select('domain', 'api_no', 'project_id')->get()->toArray();
43 LogUtils::info('start rank_data_recomm_domain:' . count($list)); 45 LogUtils::info('start rank_data_recomm_domain:' . count($list));
44 - foreach ($list as $project_id => $domain) { 46 + foreach ($list as $item) {
  47 + $project_id = $item['project_id'];
  48 + $api_no = $item['api_no'];
  49 + $domain = $item['domain'];
45 if(!$domain){ 50 if(!$domain){
46 continue; 51 continue;
47 } 52 }
@@ -53,9 +58,20 @@ class RecommDomain extends BaseCommands @@ -53,9 +58,20 @@ class RecommDomain extends BaseCommands
53 $model = new RecommDomainModel(); 58 $model = new RecommDomainModel();
54 } 59 }
55 60
  61 + //5.0
  62 + try {
  63 + $data = HttpUtils::get("https://www.quanqiusou.cn/semrush-api/data_json/{$api_no}.json", []);
  64 + $data = Arr::s2a($data)['list'];
  65 + }catch (\Exception $e){
  66 + $data = [];
  67 + }
  68 +
  69 + if(!$data){
56 //外链引荐域名 70 //外链引荐域名
57 $domain = (new DomainInfo())->getDomain($domain); 71 $domain = (new DomainInfo())->getDomain($domain);
58 $data = $semrushApi->backlinks_refdomains($domain); 72 $data = $semrushApi->backlinks_refdomains($domain);
  73 + }
  74 +
59 if (!$data) { 75 if (!$data) {
60 $error++; 76 $error++;
61 continue; 77 continue;
@@ -31,6 +31,10 @@ class NoticeController extends BaseController @@ -31,6 +31,10 @@ class NoticeController extends BaseController
31 $referrer_url = $request->input('referrer_url'); 31 $referrer_url = $request->input('referrer_url');
32 $user_agent = $request->input('user_agent'); 32 $user_agent = $request->input('user_agent');
33 33
  34 + // 数据占时不入库, 些日志分析数据
  35 + file_put_contents(storage_path('logs/trafficVisit.log'), var_export($request->all(), true) . PHP_EOL, FILE_APPEND);
  36 +// return $this->success([]);
  37 +
34 if (empty($ip)) 38 if (empty($ip))
35 return $this->error('IP不能为空'); 39 return $this->error('IP不能为空');
36 if (empty($url)) 40 if (empty($url))
@@ -38,7 +42,6 @@ class NoticeController extends BaseController @@ -38,7 +42,6 @@ class NoticeController extends BaseController
38 if (empty($user_agent)) 42 if (empty($user_agent))
39 return $this->error('请求头信息user_agent不能为空'); 43 return $this->error('请求头信息user_agent不能为空');
40 44
41 - //  
42 $url_array = parse_url($url); 45 $url_array = parse_url($url);
43 $array = [ 46 $array = [
44 'ip' => $ip, 47 'ip' => $ip,
@@ -76,22 +76,23 @@ class UpdateController extends BaseController @@ -76,22 +76,23 @@ class UpdateController extends BaseController
76 $this->fail('非升级无法进行采集操作'); 76 $this->fail('非升级无法进行采集操作');
77 } 77 }
78 78
79 - if ($this->param['test_domain']) {  
80 - $test_domain_arr = parse_url($this->param['test_domain']);  
81 - $this->param['test_domain'] = $test_domain_arr['host'] ?? ''; 79 + $test_domain = $this->param['test_domain'] ?? '';
  80 + if ($test_domain) {
  81 + $test_domain_arr = parse_url($test_domain);
  82 + $test_domain = $test_domain_arr['host'] ?? '';
82 } 83 }
83 84
84 //查看项目是否已上线 85 //查看项目是否已上线
85 $domain_info = DomainInfo::where('project_id', $this->param['project_id'])->first(); 86 $domain_info = DomainInfo::where('project_id', $this->param['project_id'])->first();
86 87
87 - if ($domain_info && !$this->param['test_domain']) { 88 + if ($domain_info && !$test_domain) {
88 $this->fail('已上线项目需填写采集的测试站域名'); 89 $this->fail('已上线项目需填写采集的测试站域名');
89 } 90 }
90 91
91 try { 92 try {
92 DB::connection('custom_mysql')->statement("DELETE FROM `gl_collect_source` WHERE `origin` LIKE '%.css%' OR `origin` LIKE '%.js%'"); 93 DB::connection('custom_mysql')->statement("DELETE FROM `gl_collect_source` WHERE `origin` LIKE '%.css%' OR `origin` LIKE '%.js%'");
93 if ($domain_info) { 94 if ($domain_info) {
94 - DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0,`domain` = '" . $this->param['test_domain'] . "' WHERE `language` = ''"); 95 + DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0,`domain` = '" . $test_domain . "' WHERE `language` = ''");
95 } else { 96 } else {
96 DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0 WHERE `language` = ''"); 97 DB::connection('custom_mysql')->statement("UPDATE `gl_collect_task` SET `status` = 0 WHERE `language` = ''");
97 } 98 }