|
...
|
...
|
@@ -43,10 +43,14 @@ class GoogleSearchKeyword extends Command |
|
|
|
protected $description = 'google搜索词';
|
|
|
|
|
|
|
|
public $googleService;
|
|
|
|
public $searchModel;
|
|
|
|
public $detailModel;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$googleService = new GoogleSearchService();
|
|
|
|
$this->googleService = new GoogleSearchService();
|
|
|
|
$this->searchModel = new GoogleSearch();
|
|
|
|
$this->detailModel = new GoogleSearchDetail();
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -84,15 +88,13 @@ class GoogleSearchKeyword extends Command |
|
|
|
* @time :2025/3/31 11:30
|
|
|
|
*/
|
|
|
|
public function _action($domain,$type,$project_id){
|
|
|
|
$googleService = new GoogleSearchService();
|
|
|
|
$data = $googleService->googleSearch($domain,$type);
|
|
|
|
$data = $this->googleService->googleSearch($domain,$type);
|
|
|
|
if(empty($data)){
|
|
|
|
echo '域名:'.$domain.'拉取数据为空.'.PHP_EOL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//保存一条主记录诗句
|
|
|
|
$searchModel = new GoogleSearch();
|
|
|
|
$searchModel->addReturnId(['date'=>date('Y-m-d'),'project_id'=>$project_id,'type'=>$type]);
|
|
|
|
$this->searchModel->addReturnId(['date'=>date('Y-m-d'),'project_id'=>$project_id,'type'=>$type]);
|
|
|
|
$saveData = [];
|
|
|
|
$clicksNum = array_sum(array_column($data, 'clicks'));
|
|
|
|
$impressionsNum = array_sum(array_column($data, 'impressions'));
|
|
...
|
...
|
@@ -103,9 +105,9 @@ class GoogleSearchKeyword extends Command |
|
|
|
'type'=>$type,
|
|
|
|
'keys'=>$val['keys'][0],
|
|
|
|
'clicks'=>$val['clicks'],
|
|
|
|
'click_rate'=>number_format($val['clicks'] / $clicksNum, 2),
|
|
|
|
'click_rate'=>number_format($val['clicks'] / ($clicksNum ?? 1), 2),
|
|
|
|
'impressions'=>$val['impressions'],
|
|
|
|
'impressions_rate'=>number_format($val['impressions'] / $impressionsNum, 2),
|
|
|
|
'impressions_rate'=>number_format($val['impressions'] / ($impressionsNum ?? 1), 2),
|
|
|
|
'ctr'=>$val['ctr'],
|
|
|
|
'position'=>$val['position'],
|
|
|
|
];
|
|
...
|
...
|
@@ -114,9 +116,8 @@ class GoogleSearchKeyword extends Command |
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
//清空以前的数据
|
|
|
|
$detailModel = new GoogleSearchDetail();
|
|
|
|
$detailModel->del(['project_id'=>$project_id,'type'=>$type]);
|
|
|
|
$detailModel->insertAll($saveData);
|
|
|
|
$this->detailModel->del(['project_id'=>$project_id,'type'=>$type]);
|
|
|
|
$this->detailModel->insertAll($saveData);
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::rollBack();
|
...
|
...
|
|