作者 李宇航

合并分支 'lyh-server' 到 'master'

Lyh server



查看合并请求 !1563
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :GoogleKeywordInsightController.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/3/25 14:23
  8 + */
  9 +
  10 +namespace App\Http\Controllers\Bside\GoogleKeywordInsight;
  11 +
  12 +use App\Enums\Common\Code;
  13 +use App\Http\Controllers\Bside\BaseController;
  14 +use App\Http\Logic\Bside\GoogleKeywordInsight\GoogleKeywordInsightLogic;
  15 +
  16 +/**
  17 + * @remark :谷歌洞察数据
  18 + * @name :GoogleKeywordInsightController
  19 + * @author :lyh
  20 + * @method :post
  21 + * @time :2025/3/25 14:24
  22 + */
  23 +class GoogleKeywordInsightController extends BaseController
  24 +{
  25 + /**
  26 + * @remark :保存数据
  27 + * @name :saveKeywordInsight
  28 + * @author :lyh
  29 + * @method :post
  30 + * @time :2025/3/25 14:30
  31 + */
  32 + public function getKeywordInsight(GoogleKeywordInsightLogic $logic){
  33 + $this->request->validate([
  34 + 'keyword' => 'required'
  35 + ],[
  36 + 'keyword.required' => '关键词不能为空',
  37 + ]);
  38 + $data = $logic->getGoogleInsight();
  39 + $this->response('success',Code::SUCCESS,$data);
  40 + }
  41 +}
@@ -44,6 +44,9 @@ class TestController extends BaseController @@ -44,6 +44,9 @@ class TestController extends BaseController
44 //获取上一周询盘数量 44 //获取上一周询盘数量
45 $service = new GoogleKeywordInsightService(); 45 $service = new GoogleKeywordInsightService();
46 $list = $service->requestUrl('cnc'); 46 $list = $service->requestUrl('cnc');
  47 + if(!empty($list)){
  48 +
  49 + }
47 $this->response('success',Code::SUCCESS,$list); 50 $this->response('success',Code::SUCCESS,$list);
48 } 51 }
49 } 52 }
@@ -10,7 +10,10 @@ @@ -10,7 +10,10 @@
10 namespace App\Http\Logic\Aside\Project; 10 namespace App\Http\Logic\Aside\Project;
11 11
12 use App\Http\Logic\Aside\BaseLogic; 12 use App\Http\Logic\Aside\BaseLogic;
  13 +use App\Models\Product\Keyword;
13 use App\Models\Project\AggregateKeyword; 14 use App\Models\Project\AggregateKeyword;
  15 +use App\Services\ProjectServer;
  16 +use Illuminate\Support\Facades\DB;
14 17
15 class AggregateKeywordLogic extends BaseLogic 18 class AggregateKeywordLogic extends BaseLogic
16 { 19 {
@@ -22,7 +25,7 @@ class AggregateKeywordLogic extends BaseLogic @@ -22,7 +25,7 @@ class AggregateKeywordLogic extends BaseLogic
22 } 25 }
23 26
24 /** 27 /**
25 - * @remark : 28 + * @remark :保存关键词
26 * @name :saveKeyword 29 * @name :saveKeyword
27 * @author :lyh 30 * @author :lyh
28 * @method :post 31 * @method :post
@@ -34,7 +37,16 @@ class AggregateKeywordLogic extends BaseLogic @@ -34,7 +37,16 @@ class AggregateKeywordLogic extends BaseLogic
34 $this->model->edit($this->param,['id'=>$this->param['id']]); 37 $this->model->edit($this->param,['id'=>$this->param['id']]);
35 }else{ 38 }else{
36 $id = $this->model->addReturnId($this->param); 39 $id = $this->model->addReturnId($this->param);
  40 + //保存到客户关键词
  41 + $keywords = explode("\n", $this->param['keywords']);
  42 + if(!empty($keywords)){
  43 + ProjectServer::useProject($this->param['project_id']);
  44 + $keywordModel = new Keyword();
  45 + $keywordModel->saveBKeyword($this->param['keyword'],$keywords);
  46 + DB::disconnect('custom_mysql');
  47 + }
37 } 48 }
38 return $this->success(['id'=>$id]); 49 return $this->success(['id'=>$id]);
39 } 50 }
  51 +
40 } 52 }
  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\Helper\Translate;
  13 +use App\Http\Logic\Bside\BaseLogic;
  14 +use App\Models\GoogleKeywordInsight\GoogleKeywordInsight;
  15 +use App\Models\GoogleKeywordInsight\GoogleKeywordInsightDetail;
  16 +use App\Services\GoogleKeywordInsightService;
  17 +
  18 +class GoogleKeywordInsightLogic extends BaseLogic
  19 +{
  20 + public $service;
  21 +
  22 + public function __construct()
  23 + {
  24 + parent::__construct();
  25 + $this->model = new GoogleKeywordInsight();
  26 + $this->param = $this->requestAll;
  27 + }
  28 +
  29 + /**
  30 + * @remark :获取google洞察数据
  31 + * @name :saveGoogleKeywordInsight
  32 + * @author :lyh
  33 + * @method :post
  34 + * @time :2025/3/25 14:36
  35 + */
  36 + public function getGoogleInsight(){
  37 + $data = $this->model->read(['search'=>$this->param['keyword']]);
  38 + if($data === false){
  39 + $this->service = new GoogleKeywordInsightService();
  40 + $data = $this->service->requestUrl($this->param['keyword']);
  41 + if(!empty($data)){
  42 + //保存数据库
  43 + $detailModel = new GoogleKeywordInsightDetail();
  44 + $this->model->saveInsight($this->param['keyword'],$data);
  45 + $detailModel->saveInsightDetail($this->param['keyword'],$data);
  46 + }
  47 + }
  48 + return $this->success($data);
  49 + }
  50 +}
@@ -79,8 +79,8 @@ class KeywordLogic extends BaseLogic @@ -79,8 +79,8 @@ class KeywordLogic extends BaseLogic
79 if($info !== false){ 79 if($info !== false){
80 return $this->success(['id'=>$info['id']]); 80 return $this->success(['id'=>$info['id']]);
81 } 81 }
82 - $this->param = $this->addHandleParam($this->param);  
83 - $id = $this->model->insertGetId($this->param); 82 + $this->param['project_id'] = $this->user['project_id'];
  83 + $id = $this->model->addReturnId($this->param);
84 //路由映射 84 //路由映射
85 $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); 85 $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
86 $this->model->edit(['route'=>$route],['id'=>$id]); 86 $this->model->edit(['route'=>$route],['id'=>$id]);
@@ -93,20 +93,6 @@ class KeywordLogic extends BaseLogic @@ -93,20 +93,6 @@ class KeywordLogic extends BaseLogic
93 } 93 }
94 94
95 /** 95 /**
96 - * @remark :添加组装数据  
97 - * @name :addHandleParam  
98 - * @author :lyh  
99 - * @method :post  
100 - * @time :2023/11/30 15:00  
101 - */  
102 - public function addHandleParam($param){  
103 - $param['project_id'] = $this->user['project_id'];  
104 - $param['created_at'] = date('Y-m-d H:i:s');  
105 - $param['updated_at'] = $param['created_at'];  
106 - return $this->success($param);  
107 - }  
108 -  
109 - /**  
110 * @remark :保存数据时参数处理 96 * @remark :保存数据时参数处理
111 * @name :handleSaveParam 97 * @name :handleSaveParam
112 * @author :lyh 98 * @author :lyh
@@ -135,27 +121,11 @@ class KeywordLogic extends BaseLogic @@ -135,27 +121,11 @@ class KeywordLogic extends BaseLogic
135 if(!empty($param['seo_title'])){ 121 if(!empty($param['seo_title'])){
136 $param['seo_title'] = ucfirst($param['seo_title']); 122 $param['seo_title'] = ucfirst($param['seo_title']);
137 } 123 }
138 - $param['first_word'] = $this->first_word($param['title']); 124 + $param['first_word'] = $this->model->first_word($param['title']);
139 return $param; 125 return $param;
140 } 126 }
141 127
142 /** 128 /**
143 - * @remark :获取字符串首字符  
144 - * @name :first_word  
145 - * @author :lyh  
146 - * @method :post  
147 - * @time :2024/10/28 10:47  
148 - */  
149 - public function first_word($title){  
150 - $first_title = mb_substr(strtolower($title), 0, 1);  
151 - if (is_numeric($first_title)){  
152 - return 0;  
153 - }  
154 - $string_key = array_search($first_title, $this->model->firstNumWord);  
155 - return $string_key ?: 27;  
156 - }  
157 -  
158 - /**  
159 * @remark :批量添加关键词任务, 异步处理 129 * @remark :批量添加关键词任务, 异步处理
160 * @name :batchAdd 130 * @name :batchAdd
161 * @author :lyh 131 * @author :lyh
@@ -164,20 +134,7 @@ class KeywordLogic extends BaseLogic @@ -164,20 +134,7 @@ class KeywordLogic extends BaseLogic
164 */ 134 */
165 public function batchAdd(){ 135 public function batchAdd(){
166 try { 136 try {
167 - foreach ($this->param['title'] as $k=>$v){  
168 - if(empty($v)){  
169 - continue;  
170 - }  
171 - $info = $this->model->read(['title'=>$v],['id']);  
172 - if($info === false){  
173 - $param['project_id'] = $this->user['project_id'];  
174 - $param['created_at'] = date('Y-m-d H:i:s');  
175 - $param['updated_at'] = $param['created_at'];  
176 - $param['title'] = $v;  
177 - $param['first_word'] = $this->first_word($param['title']);  
178 - $this->model->insertGetId($param);  
179 - }  
180 - } 137 + $this->model->saveBKeyword($this->user['project_id'],$this->param['title']);
181 }catch (\Exception $e){ 138 }catch (\Exception $e){
182 $this->fail('保存失败,请联系管理员'); 139 $this->fail('保存失败,请联系管理员');
183 } 140 }
@@ -249,7 +206,7 @@ class KeywordLogic extends BaseLogic @@ -249,7 +206,7 @@ class KeywordLogic extends BaseLogic
249 if($v){ 206 if($v){
250 $keyword_info = $this->model->read(['title'=>$v]); 207 $keyword_info = $this->model->read(['title'=>$v]);
251 if(!$keyword_info){ 208 if(!$keyword_info){
252 - $k_id = $this->model->addReturnId(['title'=>$v,'first_word' => $this->first_word($v),'project_id'=>$project_id]); 209 + $k_id = $this->model->addReturnId(['title'=>$v,'first_word' => $this->model->first_word($v),'project_id'=>$project_id]);
253 $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $k_id, $project_id); 210 $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $k_id, $project_id);
254 $this->model->edit(['route'=>$route],['id'=>$k_id]); 211 $this->model->edit(['route'=>$route],['id'=>$k_id]);
255 }else{ 212 }else{
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :GoogleKeywordInsight.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/3/25 14:33
  8 + */
  9 +
  10 +namespace App\Models\GoogleKeywordInsight;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class GoogleKeywordInsight extends Base
  15 +{
  16 + protected $table = 'gl_google_keyword_insight';
  17 +
  18 + /**
  19 + * @remark :保存洞察总数据
  20 + * @name :saveInsight
  21 + * @author :lyh
  22 + * @method :post
  23 + * @time :2025/3/25 14:45
  24 + */
  25 + public function saveInsight($keyword,$data){
  26 + $saveData = [
  27 + 'search'=>$keyword,
  28 + 'project_id'=>$this->user['project_id'],
  29 + 'data'=>json_encode($data,true),
  30 + ];
  31 + return $this->addReturnId($saveData);
  32 + }
  33 +
  34 +}
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :GoogleKeywordInsightDetail.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/3/25 14:33
  8 + */
  9 +
  10 +namespace App\Models\GoogleKeywordInsight;
  11 +
  12 +use App\Helper\Translate;
  13 +use App\Models\Base;
  14 +
  15 +class GoogleKeywordInsightDetail extends Base
  16 +{
  17 + protected $table = 'gl_google_keyword_insight_detail';
  18 +
  19 + /**
  20 + * @remark :保存洞察数据详情
  21 + * @name :saveInsightDetail
  22 + * @author :lyh
  23 + * @method :post
  24 + * @time :2025/3/25 14:45
  25 + */
  26 + public function saveInsightDetail($keyword,$data){
  27 + $saveData = [];
  28 + foreach ($data as $val){
  29 + $zh_text = Translate::tran($val['text'], 'zh');
  30 + if(empty($zh_text)){
  31 + $zh_text = $val['text'];
  32 + }
  33 + $saveData[] = [
  34 + 'search'=>$keyword,
  35 + 'text'=>$val['text'],
  36 + 'zh_text'=>$zh_text,
  37 + 'project_id'=>$this->user['project_id'],
  38 + 'volume'=>$val['volume'],
  39 + 'competition_level'=>$val['competition_level'],
  40 + 'competition_index'=>$val['competition_index'],
  41 + 'low_bid'=>$val['low_bid'],
  42 + 'high_bid'=>$val['high_bid'],
  43 + 'trend'=>$val['trend'],
  44 + ];
  45 + }
  46 + return $this->insertAll($saveData);
  47 + }
  48 +}
@@ -3,8 +3,13 @@ @@ -3,8 +3,13 @@
3 namespace App\Models\Product; 3 namespace App\Models\Product;
4 4
5 use App\Helper\Arr; 5 use App\Helper\Arr;
  6 +use App\Helper\Common;
6 use App\Models\Base; 7 use App\Models\Base;
  8 +use App\Models\Com\NoticeLog;
  9 +use App\Models\RouteMap\RouteMap;
  10 +use App\Services\ProjectServer;
7 use Illuminate\Database\Eloquent\SoftDeletes; 11 use Illuminate\Database\Eloquent\SoftDeletes;
  12 +use Illuminate\Support\Facades\DB;
8 13
9 class Keyword extends Base 14 class Keyword extends Base
10 { 15 {
@@ -149,4 +154,44 @@ class Keyword extends Base @@ -149,4 +154,44 @@ class Keyword extends Base
149 } 154 }
150 return $result; 155 return $result;
151 } 156 }
  157 +
  158 + /**
  159 + * @remark :保存到产品关键词中
  160 + * @name :saveBKeyword
  161 + * @author :lyh
  162 + * @method :post
  163 + * @time :2025/3/25 16:28
  164 + */
  165 + public function saveBKeyword($project_id,$keywords){
  166 + foreach ($keywords as $v){
  167 + if(empty($v)){
  168 + continue;
  169 + }
  170 + $info = $this->read(['title'=>$v],['id']);
  171 + if($info === false){
  172 + $param['project_id'] = $project_id;
  173 + $param['title'] = $v;
  174 + $param['first_word'] = $this->first_word($param['title']);
  175 + $this->addReturnId($param);
  176 + }
  177 + }
  178 + NoticeLog::createLog(NoticeLog::TYPE_INIT_KEYWORD, ['project_id' => $this->user['project_id']]);
  179 + return true;
  180 + }
  181 +
  182 + /**
  183 + * @remark :获取字符串首字符
  184 + * @name :first_word
  185 + * @author :lyh
  186 + * @method :post
  187 + * @time :2025/3/25 16:42
  188 + */
  189 + public function first_word($title){
  190 + $first_title = mb_substr(strtolower($title), 0, 1);
  191 + if (is_numeric($first_title)){
  192 + return 0;
  193 + }
  194 + $string_key = array_search($first_title, $this->model->firstNumWord);
  195 + return $string_key ?: 27;
  196 + }
152 } 197 }
@@ -695,6 +695,11 @@ Route::middleware(['bloginauth'])->group(function () { @@ -695,6 +695,11 @@ Route::middleware(['bloginauth'])->group(function () {
695 Route::any('/getInfo', [\App\Http\Controllers\Bside\SeoSetting\DomainSettingController::class, 'getInfo'])->name('domain_setting_getInfo'); 695 Route::any('/getInfo', [\App\Http\Controllers\Bside\SeoSetting\DomainSettingController::class, 'getInfo'])->name('domain_setting_getInfo');
696 Route::any('/save', [\App\Http\Controllers\Bside\SeoSetting\DomainSettingController::class, 'save'])->name('domain_setting_save'); 696 Route::any('/save', [\App\Http\Controllers\Bside\SeoSetting\DomainSettingController::class, 'save'])->name('domain_setting_save');
697 }); 697 });
  698 +
  699 + //google数据洞察
  700 + Route::prefix('google_keyword_insight')->group(function () {
  701 + Route::any('/getKeywordInsight', [\App\Http\Controllers\Bside\GoogleKeywordInsight\GoogleKeywordInsightController::class, 'getKeywordInsight'])->name('google_keyword_insight_getKeywordInsight');
  702 + });
698 }); 703 });
699 //无需登录验证的路由组 704 //无需登录验证的路由组
700 Route::group([], function () { 705 Route::group([], function () {