正在显示
1 个修改的文件
包含
9 行增加
和
8 行删除
| @@ -43,10 +43,14 @@ class GoogleSearchKeyword extends Command | @@ -43,10 +43,14 @@ class GoogleSearchKeyword extends Command | ||
| 43 | protected $description = 'google搜索词'; | 43 | protected $description = 'google搜索词'; |
| 44 | 44 | ||
| 45 | public $googleService; | 45 | public $googleService; |
| 46 | + public $searchModel; | ||
| 47 | + public $detailModel; | ||
| 46 | 48 | ||
| 47 | public function __construct() | 49 | public function __construct() |
| 48 | { | 50 | { |
| 49 | - $googleService = new GoogleSearchService(); | 51 | + $this->googleService = new GoogleSearchService(); |
| 52 | + $this->searchModel = new GoogleSearch(); | ||
| 53 | + $this->detailModel = new GoogleSearchDetail(); | ||
| 50 | parent::__construct(); | 54 | parent::__construct(); |
| 51 | } | 55 | } |
| 52 | 56 | ||
| @@ -84,15 +88,13 @@ class GoogleSearchKeyword extends Command | @@ -84,15 +88,13 @@ class GoogleSearchKeyword extends Command | ||
| 84 | * @time :2025/3/31 11:30 | 88 | * @time :2025/3/31 11:30 |
| 85 | */ | 89 | */ |
| 86 | public function _action($domain,$type,$project_id){ | 90 | public function _action($domain,$type,$project_id){ |
| 87 | - $googleService = new GoogleSearchService(); | ||
| 88 | - $data = $googleService->googleSearch($domain,$type); | 91 | + $data = $this->googleService->googleSearch($domain,$type); |
| 89 | if(empty($data)){ | 92 | if(empty($data)){ |
| 90 | echo '域名:'.$domain.'拉取数据为空.'.PHP_EOL; | 93 | echo '域名:'.$domain.'拉取数据为空.'.PHP_EOL; |
| 91 | return false; | 94 | return false; |
| 92 | } | 95 | } |
| 93 | //保存一条主记录诗句 | 96 | //保存一条主记录诗句 |
| 94 | - $searchModel = new GoogleSearch(); | ||
| 95 | - $searchModel->addReturnId(['date'=>date('Y-m-d'),'project_id'=>$project_id,'type'=>$type]); | 97 | + $this->searchModel->addReturnId(['date'=>date('Y-m-d'),'project_id'=>$project_id,'type'=>$type]); |
| 96 | $saveData = []; | 98 | $saveData = []; |
| 97 | $clicksNum = array_sum(array_column($data, 'clicks')); | 99 | $clicksNum = array_sum(array_column($data, 'clicks')); |
| 98 | $impressionsNum = array_sum(array_column($data, 'impressions')); | 100 | $impressionsNum = array_sum(array_column($data, 'impressions')); |
| @@ -114,9 +116,8 @@ class GoogleSearchKeyword extends Command | @@ -114,9 +116,8 @@ class GoogleSearchKeyword extends Command | ||
| 114 | DB::beginTransaction(); | 116 | DB::beginTransaction(); |
| 115 | try { | 117 | try { |
| 116 | //清空以前的数据 | 118 | //清空以前的数据 |
| 117 | - $detailModel = new GoogleSearchDetail(); | ||
| 118 | - $detailModel->del(['project_id'=>$project_id,'type'=>$type]); | ||
| 119 | - $detailModel->insertAll($saveData); | 119 | + $this->detailModel->del(['project_id'=>$project_id,'type'=>$type]); |
| 120 | + $this->detailModel->insertAll($saveData); | ||
| 120 | DB::commit(); | 121 | DB::commit(); |
| 121 | }catch (\Exception $e){ | 122 | }catch (\Exception $e){ |
| 122 | DB::rollBack(); | 123 | DB::rollBack(); |
-
请 注册 或 登录 后发表评论