|
...
|
...
|
@@ -13,6 +13,7 @@ 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 :谷歌洞察数据
|
|
...
|
...
|
@@ -41,4 +42,86 @@ class GoogleKeywordInsightController extends BaseController |
|
|
|
$data = $detailModel->lists(['search'=>$this->param['keyword']],$this->page,$this->row);
|
|
|
|
$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']],['main_keyword','customer_keywords']);
|
|
|
|
if($info === false){
|
|
|
|
$this->response('success');
|
|
|
|
}
|
|
|
|
$main_keyword = explode("\n", $info[$this->param['field']]);
|
|
|
|
$detailModel = new GoogleKeywordInsightDetail();
|
|
|
|
$resultData = [];
|
|
|
|
if(!empty($main_keyword)){
|
|
|
|
$result = [];
|
|
|
|
$resultData = $this->paginateArray($main_keyword,$this->page,$this->row);
|
|
|
|
$detailList = $detailModel->read(['search'=>['in',$resultData['data']]]);
|
|
|
|
foreach ($resultData['data'] as $key => $item){
|
|
|
|
$result[]['keyword'] = $item;
|
|
|
|
$searchKeyword = $this->getSearchDetail($item,$detailList);
|
|
|
|
if($searchKeyword === false){
|
|
|
|
$result[]['data'] = [];
|
|
|
|
}else{
|
|
|
|
$result[]['data'] = $searchKeyword;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$resultData['data'] = $result;
|
|
|
|
}
|
|
|
|
$this->response('success',Code::SUCCESS,$resultData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :查看当前数据是否存在数组中
|
|
|
|
* @name :getSearchDetail
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/4/1 9:56
|
|
|
|
*/
|
|
|
|
public function getSearchDetail($keyword,$detailList){
|
|
|
|
if(!empty($detailList)){
|
|
|
|
foreach ($detailList as $value){
|
|
|
|
if($keyword == $value['search']){
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :返回分页数据
|
|
|
|
* @name :paginateArray
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/4/1 9:41
|
|
|
|
*/
|
|
|
|
public function paginateArray($array, $page = 1, $pageSize = 20) {
|
|
|
|
$totalItems = count($array);
|
|
|
|
$totalPages = ceil($totalItems / $pageSize);
|
|
|
|
// 确保页码有效
|
|
|
|
$page = max(1, min($page, $totalPages));
|
|
|
|
$offset = ($page - 1) * $pageSize;
|
|
|
|
$data = array_slice($array, $offset, $pageSize);
|
|
|
|
return [
|
|
|
|
'list'=>[
|
|
|
|
'page' => $page,
|
|
|
|
'size' => $pageSize,
|
|
|
|
'total_page' => $totalPages,
|
|
|
|
'total' => $totalItems,
|
|
|
|
],
|
|
|
|
'data' => $data
|
|
|
|
];
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|