GoogleKeywordInsightLogic.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?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\RapIdApIService;
use Illuminate\Support\Facades\DB;
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']],['id']);
if($data === false){
$this->service = new RapIdApIService();
$data = $this->service->requestUrl($this->param['keyword']);
if(!empty($data)){
DB::beginTransaction();
//保存数据库
try {
$detailModel = new GoogleKeywordInsightDetail();
$this->model->saveInsight($this->user['project_id'],$this->param['keyword'],$data);
$detailModel->saveInsightDetail($this->user['project_id'],$this->param['keyword'],$data);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('保存失败,请联系管理员');
}
}
}
return $this->success();
}
/**
* @remark :保存一条数据
* @name :saveGoogleKeywordInsight
* @author :lyh
* @method :post
* @time :2025/3/25 14:36
*/
public function getGoogleInsightDetail(){
$this->service = new RapIdApIService();
$data = $this->service->requestUrl($this->param['keyword']);
if(!empty($data)){
DB::beginTransaction();
//保存数据库
try {
$detailModel = new GoogleKeywordInsightDetail();
$id = $detailModel->saveInsightDetailOne($this->user['project_id'],$this->param['keyword'],$data[0]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
}
}
return $this->success(['id'=>$id ?? 0]);
}
}