GoogleKeywordInsightLogic.php 1.5 KB
<?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->user['project_id'],$this->param['keyword'],$data);
                $detailModel->saveInsightDetail($this->user['project_id'],$this->param['keyword'],$data);
            }
        }
        return $this->success($data);
    }
}