作者 lyh

gx

  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\Http\Controllers\Bside\BaseController;
  13 +
  14 +/**
  15 + * @remark :谷歌洞察数据
  16 + * @name :GoogleKeywordInsightController
  17 + * @author :lyh
  18 + * @method :post
  19 + * @time :2025/3/25 14:24
  20 + */
  21 +class GoogleKeywordInsightController extends BaseController
  22 +{
  23 + /**
  24 + * @remark :保存数据
  25 + * @name :saveKeywordInsight
  26 + * @author :lyh
  27 + * @method :post
  28 + * @time :2025/3/25 14:30
  29 + */
  30 + public function saveKeywordInsight(){
  31 + $this->request->validate([
  32 + 'keyword' => 'required'
  33 + ],[
  34 + 'keyword.required' => '关键词不能为空',
  35 + ]);
  36 + }
  37 +}
@@ -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 }
  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\Http\Logic\Bside\BaseLogic;
  13 +use App\Models\GoogleKeywordInsight\GoogleKeywordInsight;
  14 +use App\Services\GoogleKeywordInsightService;
  15 +
  16 +class GoogleKeywordInsightLogic extends BaseLogic
  17 +{
  18 + public $service;
  19 +
  20 + public function __construct()
  21 + {
  22 + parent::__construct();
  23 + $this->model = new GoogleKeywordInsight();
  24 + $this->param = $this->requestAll;
  25 + }
  26 +
  27 + /**
  28 + * @remark :获取google洞察数据
  29 + * @name :saveGoogleKeywordInsight
  30 + * @author :lyh
  31 + * @method :post
  32 + * @time :2025/3/25 14:36
  33 + */
  34 + public function getGoogleInsight(){
  35 + $data = $this->model->read(['project_id'=>$this->user['project_id'],'search'=>$this->param['keyword']]);
  36 + if($data === false){
  37 + $this->service = new GoogleKeywordInsightService();
  38 + $data = $this->service->requestUrl($this->param['keyword']);
  39 + if(!empty($data)){
  40 + //保存数据库
  41 + $this->saveInsight($this->param['keyword'],$data);
  42 + $this->saveInsightDetail($this->param['keyword'],$data);
  43 + }
  44 + }
  45 + return $this->success($data);
  46 + }
  47 +
  48 + /**
  49 + * @remark :保存洞察总数据
  50 + * @name :saveInsight
  51 + * @author :lyh
  52 + * @method :post
  53 + * @time :2025/3/25 14:45
  54 + */
  55 + public function saveInsight($keyword,$data){
  56 + $saveData = [
  57 + 'search'=>$keyword,
  58 + 'project_id'=>$this->user['project_id'],
  59 + 'data'=>json_encode($data,true),
  60 + ];
  61 + return $this->model->addReturnId($saveData);
  62 + }
  63 +
  64 + /**
  65 + * @remark :保存洞察数据详情
  66 + * @name :saveInsightDetail
  67 + * @author :lyh
  68 + * @method :post
  69 + * @time :2025/3/25 14:45
  70 + */
  71 + public function saveInsightDetail($keyword,$data){
  72 + $saveData = [];
  73 + foreach ($data as $val){
  74 + $saveData[] = [
  75 + 'search'=>$keyword,
  76 + 'text'=>$val['text'],
  77 + 'project_id'=>$this->user['project_id'],
  78 + 'volume'=>$val['volume'],
  79 + 'competition_level'=>$val['competition_level'],
  80 + 'competition_index'=>$val['competition_index'],
  81 + 'low_bid'=>$val['low_bid'],
  82 + 'high_bid'=>$val['high_bid'],
  83 + 'trend'=>$val['trend'],
  84 + ];
  85 + }
  86 + return $this->model->insertAll($saveData);
  87 + }
  88 +}
  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 +}
  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\Models\Base;
  13 +
  14 +class GoogleKeywordInsightDetail extends Base
  15 +{
  16 + protected $table = 'gl_google_keyword_insight_detail';
  17 +}