作者 李宇航

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

Lyh server



查看合并请求 !1563
<?php
/**
* @remark :
* @name :GoogleKeywordInsightController.php
* @author :lyh
* @method :post
* @time :2025/3/25 14:23
*/
namespace App\Http\Controllers\Bside\GoogleKeywordInsight;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\GoogleKeywordInsight\GoogleKeywordInsightLogic;
/**
* @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' => '关键词不能为空',
]);
$data = $logic->getGoogleInsight();
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -44,6 +44,9 @@ class TestController extends BaseController
//获取上一周询盘数量
$service = new GoogleKeywordInsightService();
$list = $service->requestUrl('cnc');
if(!empty($list)){
}
$this->response('success',Code::SUCCESS,$list);
}
}
... ...
... ... @@ -10,7 +10,10 @@
namespace App\Http\Logic\Aside\Project;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Product\Keyword;
use App\Models\Project\AggregateKeyword;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class AggregateKeywordLogic extends BaseLogic
{
... ... @@ -22,7 +25,7 @@ class AggregateKeywordLogic extends BaseLogic
}
/**
* @remark :
* @remark :保存关键词
* @name :saveKeyword
* @author :lyh
* @method :post
... ... @@ -34,7 +37,16 @@ class AggregateKeywordLogic extends BaseLogic
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$id = $this->model->addReturnId($this->param);
//保存到客户关键词
$keywords = explode("\n", $this->param['keywords']);
if(!empty($keywords)){
ProjectServer::useProject($this->param['project_id']);
$keywordModel = new Keyword();
$keywordModel->saveBKeyword($this->param['keyword'],$keywords);
DB::disconnect('custom_mysql');
}
}
return $this->success(['id'=>$id]);
}
}
... ...
<?php
/**
* @remark :
* @name :GoogleKeywordInsightLogic.php
* @author :lyh
* @method :post
* @time :2025/3/25 14:31
*/
namespace App\Http\Logic\Bside\GoogleKeywordInsight;
use App\Helper\Translate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\GoogleKeywordInsight\GoogleKeywordInsight;
use App\Models\GoogleKeywordInsight\GoogleKeywordInsightDetail;
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(['search'=>$this->param['keyword']]);
if($data === false){
$this->service = new GoogleKeywordInsightService();
$data = $this->service->requestUrl($this->param['keyword']);
if(!empty($data)){
//保存数据库
$detailModel = new GoogleKeywordInsightDetail();
$this->model->saveInsight($this->param['keyword'],$data);
$detailModel->saveInsightDetail($this->param['keyword'],$data);
}
}
return $this->success($data);
}
}
... ...
... ... @@ -79,8 +79,8 @@ class KeywordLogic extends BaseLogic
if($info !== false){
return $this->success(['id'=>$info['id']]);
}
$this->param = $this->addHandleParam($this->param);
$id = $this->model->insertGetId($this->param);
$this->param['project_id'] = $this->user['project_id'];
$id = $this->model->addReturnId($this->param);
//路由映射
$route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$id]);
... ... @@ -93,20 +93,6 @@ class KeywordLogic extends BaseLogic
}
/**
* @remark :添加组装数据
* @name :addHandleParam
* @author :lyh
* @method :post
* @time :2023/11/30 15:00
*/
public function addHandleParam($param){
$param['project_id'] = $this->user['project_id'];
$param['created_at'] = date('Y-m-d H:i:s');
$param['updated_at'] = $param['created_at'];
return $this->success($param);
}
/**
* @remark :保存数据时参数处理
* @name :handleSaveParam
* @author :lyh
... ... @@ -135,27 +121,11 @@ class KeywordLogic extends BaseLogic
if(!empty($param['seo_title'])){
$param['seo_title'] = ucfirst($param['seo_title']);
}
$param['first_word'] = $this->first_word($param['title']);
$param['first_word'] = $this->model->first_word($param['title']);
return $param;
}
/**
* @remark :获取字符串首字符
* @name :first_word
* @author :lyh
* @method :post
* @time :2024/10/28 10:47
*/
public function first_word($title){
$first_title = mb_substr(strtolower($title), 0, 1);
if (is_numeric($first_title)){
return 0;
}
$string_key = array_search($first_title, $this->model->firstNumWord);
return $string_key ?: 27;
}
/**
* @remark :批量添加关键词任务, 异步处理
* @name :batchAdd
* @author :lyh
... ... @@ -164,20 +134,7 @@ class KeywordLogic extends BaseLogic
*/
public function batchAdd(){
try {
foreach ($this->param['title'] as $k=>$v){
if(empty($v)){
continue;
}
$info = $this->model->read(['title'=>$v],['id']);
if($info === false){
$param['project_id'] = $this->user['project_id'];
$param['created_at'] = date('Y-m-d H:i:s');
$param['updated_at'] = $param['created_at'];
$param['title'] = $v;
$param['first_word'] = $this->first_word($param['title']);
$this->model->insertGetId($param);
}
}
$this->model->saveBKeyword($this->user['project_id'],$this->param['title']);
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
... ... @@ -249,7 +206,7 @@ class KeywordLogic extends BaseLogic
if($v){
$keyword_info = $this->model->read(['title'=>$v]);
if(!$keyword_info){
$k_id = $this->model->addReturnId(['title'=>$v,'first_word' => $this->first_word($v),'project_id'=>$project_id]);
$k_id = $this->model->addReturnId(['title'=>$v,'first_word' => $this->model->first_word($v),'project_id'=>$project_id]);
$route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $k_id, $project_id);
$this->model->edit(['route'=>$route],['id'=>$k_id]);
}else{
... ...
<?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';
/**
* @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->addReturnId($saveData);
}
}
... ...
<?php
/**
* @remark :
* @name :GoogleKeywordInsightDetail.php
* @author :lyh
* @method :post
* @time :2025/3/25 14:33
*/
namespace App\Models\GoogleKeywordInsight;
use App\Helper\Translate;
use App\Models\Base;
class GoogleKeywordInsightDetail extends Base
{
protected $table = 'gl_google_keyword_insight_detail';
/**
* @remark :保存洞察数据详情
* @name :saveInsightDetail
* @author :lyh
* @method :post
* @time :2025/3/25 14:45
*/
public function saveInsightDetail($keyword,$data){
$saveData = [];
foreach ($data as $val){
$zh_text = Translate::tran($val['text'], 'zh');
if(empty($zh_text)){
$zh_text = $val['text'];
}
$saveData[] = [
'search'=>$keyword,
'text'=>$val['text'],
'zh_text'=>$zh_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->insertAll($saveData);
}
}
... ...
... ... @@ -3,8 +3,13 @@
namespace App\Models\Product;
use App\Helper\Arr;
use App\Helper\Common;
use App\Models\Base;
use App\Models\Com\NoticeLog;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
class Keyword extends Base
{
... ... @@ -149,4 +154,44 @@ class Keyword extends Base
}
return $result;
}
/**
* @remark :保存到产品关键词中
* @name :saveBKeyword
* @author :lyh
* @method :post
* @time :2025/3/25 16:28
*/
public function saveBKeyword($project_id,$keywords){
foreach ($keywords as $v){
if(empty($v)){
continue;
}
$info = $this->read(['title'=>$v],['id']);
if($info === false){
$param['project_id'] = $project_id;
$param['title'] = $v;
$param['first_word'] = $this->first_word($param['title']);
$this->addReturnId($param);
}
}
NoticeLog::createLog(NoticeLog::TYPE_INIT_KEYWORD, ['project_id' => $this->user['project_id']]);
return true;
}
/**
* @remark :获取字符串首字符
* @name :first_word
* @author :lyh
* @method :post
* @time :2025/3/25 16:42
*/
public function first_word($title){
$first_title = mb_substr(strtolower($title), 0, 1);
if (is_numeric($first_title)){
return 0;
}
$string_key = array_search($first_title, $this->model->firstNumWord);
return $string_key ?: 27;
}
}
... ...
... ... @@ -695,6 +695,11 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/getInfo', [\App\Http\Controllers\Bside\SeoSetting\DomainSettingController::class, 'getInfo'])->name('domain_setting_getInfo');
Route::any('/save', [\App\Http\Controllers\Bside\SeoSetting\DomainSettingController::class, 'save'])->name('domain_setting_save');
});
//google数据洞察
Route::prefix('google_keyword_insight')->group(function () {
Route::any('/getKeywordInsight', [\App\Http\Controllers\Bside\GoogleKeywordInsight\GoogleKeywordInsightController::class, 'getKeywordInsight'])->name('google_keyword_insight_getKeywordInsight');
});
});
//无需登录验证的路由组
Route::group([], function () {
... ...