GoogleKeywordInsightController.php
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* @remark :
* @name :GoogleKeywordInsightController.php
* @author :lyh
* @method :post
* @time :2025/3/25 14:23
*/
namespace App\Http\Controllers\Bside\GoogleKeyword;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\GoogleKeywordInsight\GoogleKeywordInsightLogic;
use App\Models\GoogleKeywordInsight\GoogleKeywordInsightDetail;
use App\Models\Project\ProjectKeyword;
/**
* @remark :谷歌洞察数据
* @name :GoogleKeywordInsightController
* @author :lyh
* @method :post
* @time :2025/3/25 14:24
*/
class GoogleKeywordInsightController extends BaseController
{
/**
* @remark :保存数据
* @name :saveKeywordInsight
* @author :lyh
* @method :post
* @time :2025/3/25 14:30
*/
public function getKeywordInsight(GoogleKeywordInsightLogic $logic){
$this->request->validate([
'keyword' => 'required'
],[
'keyword.required' => '关键词不能为空',
]);
$logic->getGoogleInsight();
$detailModel = new GoogleKeywordInsightDetail();
$data = $detailModel->lists(['search'=>$this->param['keyword']],$this->page,$this->row,'id',['*'],'asc');
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :获取优化关键词列表
* @name :getOptimizeList
* @author :lyh
* @method :post
* @time :2025/4/1 9:12
*/
public function getOptimizeList(){
$this->request->validate([
'field' => 'required'
],[
'field.required' => 'field不能为空',
]);
$projectKeywordModel = new ProjectKeyword();
$info = $projectKeywordModel->read(['project_id'=>$this->user['project_id']],[$this->param['field']]);
if($info === false || empty($info[$this->param['field']])){
$this->response('success');
}
$array = explode("\r\n", $info[$this->param['field']]);
$detailModel = new GoogleKeywordInsightDetail();
$resultData = [];
if(!empty($array)){
$resultData = paginateArray($array,$this->page,$this->row);
$detailList = $detailModel->list(['search'=>['in',$resultData['list']]]);
foreach ($resultData['list'] as $key => $item){
$result['keyword'] = $item;
$searchKeyword = $detailModel->getSearchDetail($item,$detailList);
if($searchKeyword === false){
$result['data'] = [];
}else{
$result['data'] = $searchKeyword;
}
$resultData['list'][$key] = $result;
}
}
$this->response('success',Code::SUCCESS,$resultData);
}
/**
* @remark :保存一条关键字数据
* @name :getKeywordInsightDetail
* @author :lyh
* @method :post
* @time :2025/4/1 11:23
*/
public function getKeywordInsightDetail(GoogleKeywordInsightLogic $logic){
$this->request->validate([
'keyword' => 'required'
],[
'keyword.required' => '关键词不能为空',
]);
$result = $logic->getGoogleInsightDetail();
$detailModel = new GoogleKeywordInsightDetail();
$data = $detailModel->read(['id'=>$result['id']]);
$this->response('success',Code::SUCCESS,$data);
}
}