|
|
|
1
|
+<?php
|
|
|
|
2
|
+/**
|
|
|
|
3
|
+ * @remark :
|
|
|
|
4
|
+ * @name :GoogleKeywordInsightLogic.php
|
|
|
|
5
|
+ * @author :lyh
|
|
|
|
6
|
+ * @method :post
|
|
|
|
7
|
+ * @time :2025/3/25 14:31
|
|
|
|
8
|
+ */
|
|
|
|
9
|
+
|
|
|
|
10
|
+namespace App\Http\Logic\Bside\GoogleKeywordInsight;
|
|
|
|
11
|
+
|
|
|
|
12
|
+use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
13
|
+use App\Models\GoogleKeywordInsight\GoogleKeywordInsight;
|
|
|
|
14
|
+use App\Services\GoogleKeywordInsightService;
|
|
|
|
15
|
+
|
|
|
|
16
|
+class GoogleKeywordInsightLogic extends BaseLogic
|
|
|
|
17
|
+{
|
|
|
|
18
|
+ public $service;
|
|
|
|
19
|
+
|
|
|
|
20
|
+ public function __construct()
|
|
|
|
21
|
+ {
|
|
|
|
22
|
+ parent::__construct();
|
|
|
|
23
|
+ $this->model = new GoogleKeywordInsight();
|
|
|
|
24
|
+ $this->param = $this->requestAll;
|
|
|
|
25
|
+ }
|
|
|
|
26
|
+
|
|
|
|
27
|
+ /**
|
|
|
|
28
|
+ * @remark :获取google洞察数据
|
|
|
|
29
|
+ * @name :saveGoogleKeywordInsight
|
|
|
|
30
|
+ * @author :lyh
|
|
|
|
31
|
+ * @method :post
|
|
|
|
32
|
+ * @time :2025/3/25 14:36
|
|
|
|
33
|
+ */
|
|
|
|
34
|
+ public function getGoogleInsight(){
|
|
|
|
35
|
+ $data = $this->model->read(['project_id'=>$this->user['project_id'],'search'=>$this->param['keyword']]);
|
|
|
|
36
|
+ if($data === false){
|
|
|
|
37
|
+ $this->service = new GoogleKeywordInsightService();
|
|
|
|
38
|
+ $data = $this->service->requestUrl($this->param['keyword']);
|
|
|
|
39
|
+ if(!empty($data)){
|
|
|
|
40
|
+ //保存数据库
|
|
|
|
41
|
+ $this->saveInsight($this->param['keyword'],$data);
|
|
|
|
42
|
+ $this->saveInsightDetail($this->param['keyword'],$data);
|
|
|
|
43
|
+ }
|
|
|
|
44
|
+ }
|
|
|
|
45
|
+ return $this->success($data);
|
|
|
|
46
|
+ }
|
|
|
|
47
|
+
|
|
|
|
48
|
+ /**
|
|
|
|
49
|
+ * @remark :保存洞察总数据
|
|
|
|
50
|
+ * @name :saveInsight
|
|
|
|
51
|
+ * @author :lyh
|
|
|
|
52
|
+ * @method :post
|
|
|
|
53
|
+ * @time :2025/3/25 14:45
|
|
|
|
54
|
+ */
|
|
|
|
55
|
+ public function saveInsight($keyword,$data){
|
|
|
|
56
|
+ $saveData = [
|
|
|
|
57
|
+ 'search'=>$keyword,
|
|
|
|
58
|
+ 'project_id'=>$this->user['project_id'],
|
|
|
|
59
|
+ 'data'=>json_encode($data,true),
|
|
|
|
60
|
+ ];
|
|
|
|
61
|
+ return $this->model->addReturnId($saveData);
|
|
|
|
62
|
+ }
|
|
|
|
63
|
+
|
|
|
|
64
|
+ /**
|
|
|
|
65
|
+ * @remark :保存洞察数据详情
|
|
|
|
66
|
+ * @name :saveInsightDetail
|
|
|
|
67
|
+ * @author :lyh
|
|
|
|
68
|
+ * @method :post
|
|
|
|
69
|
+ * @time :2025/3/25 14:45
|
|
|
|
70
|
+ */
|
|
|
|
71
|
+ public function saveInsightDetail($keyword,$data){
|
|
|
|
72
|
+ $saveData = [];
|
|
|
|
73
|
+ foreach ($data as $val){
|
|
|
|
74
|
+ $saveData[] = [
|
|
|
|
75
|
+ 'search'=>$keyword,
|
|
|
|
76
|
+ 'text'=>$val['text'],
|
|
|
|
77
|
+ 'project_id'=>$this->user['project_id'],
|
|
|
|
78
|
+ 'volume'=>$val['volume'],
|
|
|
|
79
|
+ 'competition_level'=>$val['competition_level'],
|
|
|
|
80
|
+ 'competition_index'=>$val['competition_index'],
|
|
|
|
81
|
+ 'low_bid'=>$val['low_bid'],
|
|
|
|
82
|
+ 'high_bid'=>$val['high_bid'],
|
|
|
|
83
|
+ 'trend'=>$val['trend'],
|
|
|
|
84
|
+ ];
|
|
|
|
85
|
+ }
|
|
|
|
86
|
+ return $this->model->insertAll($saveData);
|
|
|
|
87
|
+ }
|
|
|
|
88
|
+} |