作者 lyh

gx

<?php
/**
* @remark :
* @name :GoogleKeywordInsightController.php
* @author :lyh
* @method :post
* @time :2025/3/25 14:23
*/
namespace App\Http\Controllers\Bside\GoogleKeywordInsight;
use App\Http\Controllers\Bside\BaseController;
/**
* @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 saveKeywordInsight(){
$this->request->validate([
'keyword' => 'required'
],[
'keyword.required' => '关键词不能为空',
]);
}
}
... ...
... ... @@ -44,6 +44,9 @@ class TestController extends BaseController
//获取上一周询盘数量
$service = new GoogleKeywordInsightService();
$list = $service->requestUrl('cnc');
if(!empty($list)){
}
$this->response('success',Code::SUCCESS,$list);
}
}
... ...
<?php
/**
* @remark :
* @name :GoogleKeywordInsightLogic.php
* @author :lyh
* @method :post
* @time :2025/3/25 14:31
*/
namespace App\Http\Logic\Bside\GoogleKeywordInsight;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\GoogleKeywordInsight\GoogleKeywordInsight;
use App\Services\GoogleKeywordInsightService;
class GoogleKeywordInsightLogic extends BaseLogic
{
public $service;
public function __construct()
{
parent::__construct();
$this->model = new GoogleKeywordInsight();
$this->param = $this->requestAll;
}
/**
* @remark :获取google洞察数据
* @name :saveGoogleKeywordInsight
* @author :lyh
* @method :post
* @time :2025/3/25 14:36
*/
public function getGoogleInsight(){
$data = $this->model->read(['project_id'=>$this->user['project_id'],'search'=>$this->param['keyword']]);
if($data === false){
$this->service = new GoogleKeywordInsightService();
$data = $this->service->requestUrl($this->param['keyword']);
if(!empty($data)){
//保存数据库
$this->saveInsight($this->param['keyword'],$data);
$this->saveInsightDetail($this->param['keyword'],$data);
}
}
return $this->success($data);
}
/**
* @remark :保存洞察总数据
* @name :saveInsight
* @author :lyh
* @method :post
* @time :2025/3/25 14:45
*/
public function saveInsight($keyword,$data){
$saveData = [
'search'=>$keyword,
'project_id'=>$this->user['project_id'],
'data'=>json_encode($data,true),
];
return $this->model->addReturnId($saveData);
}
/**
* @remark :保存洞察数据详情
* @name :saveInsightDetail
* @author :lyh
* @method :post
* @time :2025/3/25 14:45
*/
public function saveInsightDetail($keyword,$data){
$saveData = [];
foreach ($data as $val){
$saveData[] = [
'search'=>$keyword,
'text'=>$val['text'],
'project_id'=>$this->user['project_id'],
'volume'=>$val['volume'],
'competition_level'=>$val['competition_level'],
'competition_index'=>$val['competition_index'],
'low_bid'=>$val['low_bid'],
'high_bid'=>$val['high_bid'],
'trend'=>$val['trend'],
];
}
return $this->model->insertAll($saveData);
}
}
... ...
<?php
/**
* @remark :
* @name :GoogleKeywordInsight.php
* @author :lyh
* @method :post
* @time :2025/3/25 14:33
*/
namespace App\Models\GoogleKeywordInsight;
use App\Models\Base;
class GoogleKeywordInsight extends Base
{
protected $table = 'gl_google_keyword_insight';
}
... ...
<?php
/**
* @remark :
* @name :GoogleKeywordInsightDetail.php
* @author :lyh
* @method :post
* @time :2025/3/25 14:33
*/
namespace App\Models\GoogleKeywordInsight;
use App\Models\Base;
class GoogleKeywordInsightDetail extends Base
{
protected $table = 'gl_google_keyword_insight_detail';
}
... ...