|
@@ -13,6 +13,7 @@ use App\Enums\Common\Code; |
|
@@ -13,6 +13,7 @@ use App\Enums\Common\Code; |
|
13
|
use App\Http\Controllers\Bside\BaseController;
|
13
|
use App\Http\Controllers\Bside\BaseController;
|
|
14
|
use App\Http\Logic\Bside\GoogleKeywordInsight\GoogleKeywordInsightLogic;
|
14
|
use App\Http\Logic\Bside\GoogleKeywordInsight\GoogleKeywordInsightLogic;
|
|
15
|
use App\Models\GoogleKeywordInsight\GoogleKeywordInsightDetail;
|
15
|
use App\Models\GoogleKeywordInsight\GoogleKeywordInsightDetail;
|
|
|
|
16
|
+use App\Models\Project\ProjectKeyword;
|
|
16
|
|
17
|
|
|
17
|
/**
|
18
|
/**
|
|
18
|
* @remark :谷歌洞察数据
|
19
|
* @remark :谷歌洞察数据
|
|
@@ -41,4 +42,81 @@ class GoogleKeywordInsightController extends BaseController |
|
@@ -41,4 +42,81 @@ class GoogleKeywordInsightController extends BaseController |
|
41
|
$data = $detailModel->lists(['search'=>$this->param['keyword']],$this->page,$this->row);
|
42
|
$data = $detailModel->lists(['search'=>$this->param['keyword']],$this->page,$this->row);
|
|
42
|
$this->response('success',Code::SUCCESS,$data);
|
43
|
$this->response('success',Code::SUCCESS,$data);
|
|
43
|
}
|
44
|
}
|
|
|
|
45
|
+
|
|
|
|
46
|
+ /**
|
|
|
|
47
|
+ * @remark :获取优化关键词列表
|
|
|
|
48
|
+ * @name :getOptimizeList
|
|
|
|
49
|
+ * @author :lyh
|
|
|
|
50
|
+ * @method :post
|
|
|
|
51
|
+ * @time :2025/4/1 9:12
|
|
|
|
52
|
+ */
|
|
|
|
53
|
+ public function getOptimizeList(){
|
|
|
|
54
|
+ $projectKeywordModel = new ProjectKeyword();
|
|
|
|
55
|
+ $info = $projectKeywordModel->read(['project_id'=>$this->user['project_id']],['main_keyword','customer_keywords']);
|
|
|
|
56
|
+ if($info === false){
|
|
|
|
57
|
+ $this->response('success');
|
|
|
|
58
|
+ }
|
|
|
|
59
|
+ $main_keyword = explode("\r\n", $info['main_keyword']);
|
|
|
|
60
|
+ $customer_keywords = explode("\r\n", $info['customer_keywords']);
|
|
|
|
61
|
+ $array = array_merge($main_keyword, $customer_keywords);
|
|
|
|
62
|
+ $detailModel = new GoogleKeywordInsightDetail();
|
|
|
|
63
|
+ $resultData = [];
|
|
|
|
64
|
+ if(!empty($array)){
|
|
|
|
65
|
+ $resultData = $this->paginateArray($array,$this->page,$this->row);
|
|
|
|
66
|
+ $detailList = $detailModel->read(['search'=>['in',$resultData['list']]]);
|
|
|
|
67
|
+ foreach ($resultData['list'] as $key => $item){
|
|
|
|
68
|
+ $result['keyword'] = $item;
|
|
|
|
69
|
+ $searchKeyword = $this->getSearchDetail($item,$detailList);
|
|
|
|
70
|
+ if($searchKeyword === false){
|
|
|
|
71
|
+ $result['data'] = [];
|
|
|
|
72
|
+ }else{
|
|
|
|
73
|
+ $result['data'] = $searchKeyword;
|
|
|
|
74
|
+ }
|
|
|
|
75
|
+ $resultData['list'][$key] = $result;
|
|
|
|
76
|
+ }
|
|
|
|
77
|
+
|
|
|
|
78
|
+ }
|
|
|
|
79
|
+ $this->response('success',Code::SUCCESS,$resultData);
|
|
|
|
80
|
+ }
|
|
|
|
81
|
+
|
|
|
|
82
|
+ /**
|
|
|
|
83
|
+ * @remark :查看当前数据是否存在数组中
|
|
|
|
84
|
+ * @name :getSearchDetail
|
|
|
|
85
|
+ * @author :lyh
|
|
|
|
86
|
+ * @method :post
|
|
|
|
87
|
+ * @time :2025/4/1 9:56
|
|
|
|
88
|
+ */
|
|
|
|
89
|
+ public function getSearchDetail($keyword,$detailList){
|
|
|
|
90
|
+ if(!empty($detailList)){
|
|
|
|
91
|
+ foreach ($detailList as $value){
|
|
|
|
92
|
+ if($keyword == $value['search']){
|
|
|
|
93
|
+ return $value;
|
|
|
|
94
|
+ }
|
|
|
|
95
|
+ }
|
|
|
|
96
|
+ }
|
|
|
|
97
|
+ return [];
|
|
|
|
98
|
+ }
|
|
|
|
99
|
+
|
|
|
|
100
|
+ /**
|
|
|
|
101
|
+ * @remark :返回分页数据
|
|
|
|
102
|
+ * @name :paginateArray
|
|
|
|
103
|
+ * @author :lyh
|
|
|
|
104
|
+ * @method :post
|
|
|
|
105
|
+ * @time :2025/4/1 9:41
|
|
|
|
106
|
+ */
|
|
|
|
107
|
+ public function paginateArray($array, $page = 1, $pageSize = 20) {
|
|
|
|
108
|
+ $totalItems = count($array);
|
|
|
|
109
|
+ $totalPages = ceil($totalItems / $pageSize);
|
|
|
|
110
|
+ // 确保页码有效
|
|
|
|
111
|
+ $page = max(1, min($page, $totalPages));
|
|
|
|
112
|
+ $offset = ($page - 1) * $pageSize;
|
|
|
|
113
|
+ $data = array_slice($array, $offset, $pageSize);
|
|
|
|
114
|
+ return [
|
|
|
|
115
|
+ 'list' => $data,
|
|
|
|
116
|
+ 'page' => $page,
|
|
|
|
117
|
+ 'size' => $pageSize,
|
|
|
|
118
|
+ 'total_page' => $totalPages,
|
|
|
|
119
|
+ 'total' => $totalItems,
|
|
|
|
120
|
+ ];
|
|
|
|
121
|
+ }
|
|
44
|
} |
122
|
} |