|
@@ -10,6 +10,7 @@ |
|
@@ -10,6 +10,7 @@ |
|
10
|
namespace App\Console\Commands\GoogleSearch;
|
10
|
namespace App\Console\Commands\GoogleSearch;
|
|
11
|
|
11
|
|
|
12
|
use App\Models\Com\NoticeLog;
|
12
|
use App\Models\Com\NoticeLog;
|
|
|
|
13
|
+use App\Models\Domain\DomainInfo;
|
|
13
|
use App\Models\GoogleSearch\GoogleSearch;
|
14
|
use App\Models\GoogleSearch\GoogleSearch;
|
|
14
|
use App\Models\GoogleSearch\GoogleSearchDetail;
|
15
|
use App\Models\GoogleSearch\GoogleSearchDetail;
|
|
15
|
use App\Models\Project\Project;
|
16
|
use App\Models\Project\Project;
|
|
@@ -49,23 +50,19 @@ class GoogleSearchKeyword extends Command |
|
@@ -49,23 +50,19 @@ class GoogleSearchKeyword extends Command |
|
49
|
* @time :2025/3/31 11:37
|
50
|
* @time :2025/3/31 11:37
|
|
50
|
*/
|
51
|
*/
|
|
51
|
public function handle(){
|
52
|
public function handle(){
|
|
52
|
- $noticeModel = new NoticeLog();
|
|
|
|
53
|
- while (true){
|
|
|
|
54
|
- $list = $noticeModel->list(['type'=>['like',NoticeLog::GOOGLE_SEARCH.'_%'],'status'=>NoticeLog::STATUS_PENDING]);;
|
|
|
|
55
|
- if(empty($list)){
|
|
|
|
56
|
- sleep(50);
|
|
|
|
57
|
- return true;
|
53
|
+ $projectModel = new Project();
|
|
|
|
54
|
+ $lists = $projectModel->list(['delete_status' => 0,'type'=>['!=',$projectModel::TYPE_ONE]], 'id', ['id']);
|
|
|
|
55
|
+ $domainModel = new DomainInfo();
|
|
|
|
56
|
+ foreach ($lists as $val) {
|
|
|
|
57
|
+ echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
|
|
|
|
58
|
+ $domainInfo = $domainModel->read(['project_id'=>$val['id']]);
|
|
|
|
59
|
+ if($domainInfo === false){
|
|
|
|
60
|
+ echo '域名不存在。'.PHP_EOL;
|
|
|
|
61
|
+ continue;
|
|
58
|
}
|
62
|
}
|
|
59
|
- foreach ($list as $val){
|
|
|
|
60
|
- $data = $val['data'];
|
|
|
|
61
|
- echo '执行的任务id:'.$val['id'].',项目id:'.$data['project_id']??''.PHP_EOL;
|
|
|
|
62
|
- $result = $this->_action($data['domain'],$data['type'],$data['project_id']);
|
|
|
|
63
|
- $status = NoticeLog::STATUS_SUCCESS;
|
|
|
|
64
|
- if($result === false){
|
|
|
|
65
|
- $status = NoticeLog::STATUS_FAIL;
|
|
|
|
66
|
- }
|
|
|
|
67
|
- $noticeModel->edit(['status'=>$status],['id'=>$val['id']]);
|
|
|
|
68
|
- echo '任务结束'.PHP_EOL;
|
63
|
+ $typeData = [1=>'date', 2=>'query', 3=>'page', 4=>'device', 5=>'country'];
|
|
|
|
64
|
+ foreach ($typeData as $valT){
|
|
|
|
65
|
+ $this->_action($domainInfo['domain'],$valT,$val['id']);
|
|
69
|
}
|
66
|
}
|
|
70
|
}
|
67
|
}
|
|
71
|
return true;
|
68
|
return true;
|
|
@@ -87,7 +84,7 @@ class GoogleSearchKeyword extends Command |
|
@@ -87,7 +84,7 @@ class GoogleSearchKeyword extends Command |
|
87
|
}
|
84
|
}
|
|
88
|
//保存一条主记录诗句
|
85
|
//保存一条主记录诗句
|
|
89
|
$searchModel = new GoogleSearch();
|
86
|
$searchModel = new GoogleSearch();
|
|
90
|
- $searchModel->addReturnId(['date'=>date('Y-m-d'),'project_id'=>$project_id,'type'=>$type,'text'=>json_encode($data,true)]);
|
87
|
+ $searchModel->addReturnId(['date'=>date('Y-m-d'),'project_id'=>$project_id,'type'=>$type]);
|
|
91
|
$saveData = [];
|
88
|
$saveData = [];
|
|
92
|
$clicksNum = array_sum(array_column($data, 'clicks'));
|
89
|
$clicksNum = array_sum(array_column($data, 'clicks'));
|
|
93
|
$impressionsNum = array_sum(array_column($data, 'impressions'));
|
90
|
$impressionsNum = array_sum(array_column($data, 'impressions'));
|
|
@@ -98,7 +95,9 @@ class GoogleSearchKeyword extends Command |
|
@@ -98,7 +95,9 @@ class GoogleSearchKeyword extends Command |
|
98
|
'type'=>$type,
|
95
|
'type'=>$type,
|
|
99
|
'keys'=>$val['keys'][0],
|
96
|
'keys'=>$val['keys'][0],
|
|
100
|
'clicks'=>$val['clicks'],
|
97
|
'clicks'=>$val['clicks'],
|
|
|
|
98
|
+ 'click_rate'=>number_format($val['clicks'] / $clicksNum, 2),
|
|
101
|
'impressions'=>$val['impressions'],
|
99
|
'impressions'=>$val['impressions'],
|
|
|
|
100
|
+ 'impressions_rate'=>number_format($val['impressions'] / $impressionsNum, 2),
|
|
102
|
'ctr'=>$val['ctr'],
|
101
|
'ctr'=>$val['ctr'],
|
|
103
|
'position'=>$val['position'],
|
102
|
'position'=>$val['position'],
|
|
104
|
];
|
103
|
];
|