作者 lyh

gx

... ... @@ -12,6 +12,7 @@ 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
... ... @@ -39,56 +40,11 @@ class GoogleKeywordInsightLogic extends BaseLogic
$data = $this->service->requestUrl($this->param['keyword']);
if(!empty($data)){
//保存数据库
$this->saveInsight($this->param['keyword'],$data);
$this->saveInsightDetail($this->param['keyword'],$data);
$detailModel = new GoogleKeywordInsightDetail();
$this->model->saveInsight($this->param['keyword'],$data);
$detailModel->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){
$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->model->insertAll($saveData);
}
}
... ...
... ... @@ -14,4 +14,21 @@ 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);
}
}
... ...
... ... @@ -9,9 +9,40 @@
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);
}
}
... ...