正在显示
1 个修改的文件
包含
78 行增加
和
0 行删除
| @@ -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("\n", $info[$this->param['field']]); | ||
| 60 | + $detailModel = new GoogleKeywordInsightDetail(); | ||
| 61 | + $resultData = []; | ||
| 62 | + if(!empty($main_keyword)){ | ||
| 63 | + $result = []; | ||
| 64 | + $resultData = $this->paginateArray($main_keyword,$this->page,$this->row); | ||
| 65 | + $detailList = $detailModel->read(['search'=>['in',$resultData['data']]]); | ||
| 66 | + foreach ($resultData['data'] as $key => $item){ | ||
| 67 | + $result[]['keyword'] = $item; | ||
| 68 | + $searchKeyword = $this->getSearchDetail($item,$detailList); | ||
| 69 | + if($searchKeyword === false){ | ||
| 70 | + $result[]['data'] = []; | ||
| 71 | + }else{ | ||
| 72 | + $result[]['data'] = $searchKeyword; | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + $resultData['data'] = $result; | ||
| 76 | + } | ||
| 77 | + $this->response('success',Code::SUCCESS,$resultData); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * @remark :查看当前数据是否存在数组中 | ||
| 82 | + * @name :getSearchDetail | ||
| 83 | + * @author :lyh | ||
| 84 | + * @method :post | ||
| 85 | + * @time :2025/4/1 9:56 | ||
| 86 | + */ | ||
| 87 | + public function getSearchDetail($keyword,$detailList){ | ||
| 88 | + if(!empty($detailList)){ | ||
| 89 | + foreach ($detailList as $value){ | ||
| 90 | + if($keyword == $value['search']){ | ||
| 91 | + return $value; | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + return []; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * @remark :返回分页数据 | ||
| 100 | + * @name :paginateArray | ||
| 101 | + * @author :lyh | ||
| 102 | + * @method :post | ||
| 103 | + * @time :2025/4/1 9:41 | ||
| 104 | + */ | ||
| 105 | + public function paginateArray($array, $page = 1, $pageSize = 20) { | ||
| 106 | + $totalItems = count($array); | ||
| 107 | + $totalPages = ceil($totalItems / $pageSize); | ||
| 108 | + // 确保页码有效 | ||
| 109 | + $page = max(1, min($page, $totalPages)); | ||
| 110 | + $offset = ($page - 1) * $pageSize; | ||
| 111 | + $data = array_slice($array, $offset, $pageSize); | ||
| 112 | + return [ | ||
| 113 | + 'list'=>[ | ||
| 114 | + 'page' => $page, | ||
| 115 | + 'size' => $pageSize, | ||
| 116 | + 'total_page' => $totalPages, | ||
| 117 | + 'total' => $totalItems, | ||
| 118 | + ], | ||
| 119 | + 'data' => $data | ||
| 120 | + ]; | ||
| 121 | + } | ||
| 44 | } | 122 | } |
-
请 注册 或 登录 后发表评论