UpdateKeyword.php
3.8 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* @remark :
* @name :UpdateKeyword.php
* @author :lyh
* @method :post
* @time :2024/7/3 9:23
*/
namespace App\Console\Commands\Update;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordPage;
use App\Models\Product\Product;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class UpdateKeyword extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update_keyword_content';
/**
* The console command description.
*
* @var string
*/
protected $description = '批量更新关键词内容';
public function handle(){
while (true){
$keywordPageModel = new KeywordPage();
$lists = $keywordPageModel->list(['status'=>0]);
if(empty($lists)){
sleep(100);
continue;
}
$domainModel = new DomainInfo();
foreach ($lists as $v){
ProjectServer::useProject($v['project_id']);
$this->saveKeywordContent($v);
DB::disconnect('custom_mysql');
//获取当前项目的域名
$domainInfo = $domainModel->read(['project_id'=>$v['project_id']]);
if($domainInfo !== false){
$this->curlDelRoute($domainInfo['domain'],$v['project_id']);
}
$keywordPageModel->edit(['status'=>1],['id'=>$v['id']]);
}
sleep(10);
}
}
/**
* @remark :更新关键词内容
* @name :saveKeywordContent
* @author :lyh
* @method :post
* @time :2024/7/3 10:25
*/
public function saveKeywordContent($info){
$keywordModel = new Keyword();
$updateObject = json_decode($info['update_object'],true);
$text = json_decode($info['text'],true);
if(empty($text)){
return false;
}
$number = count($text);
$randomNumber = rand(0, $number - 1);
if($updateObject['type'] == 0){//更新所有关键字
$keywordModel->edit(['keyword_content'=>$text[$randomNumber]],['status'=>1]);
}else{
//按传递的关键字更新
if(!empty($updateObject['keyword'])){
$updateObject['keyword'] = (array)$updateObject['keyword'];
$keywordModel->edit(['keyword_content'=>$text[$randomNumber]],['title'=>['in',$updateObject['keyword']]]);
}
//按给定的数量更新
if(!empty($updateObject['number']) && ($updateObject['number'] != 0)){
$keywordIdArr = $keywordModel->where("status",1)->inRandomOrder()->take($updateObject['number'])->pluck('id')->toArray();
$keywordModel->edit(['keyword_content'=>$text[$randomNumber]],['id'=>['in',$keywordIdArr]]);
}
}
return true;
}
/**
* @remark :删除路由通知C端
* @name :curlDelRoute
* @author :lyh
* @method :post
* @time :2023/11/30 14:43
*/
public function curlDelRoute($domain,$project_id){
if (strpos($domain, 'https://') === false) {
$domain = 'https://' . $domain . '/';
}
$url = $domain.'api/update_page/?project_id='.$project_id.'&route=4';
shell_exec('curl -k "'.$url.'"');
return true;
}
/**
* @remark :更新产品关键词
* @name :updatedProductKeyword
* @author :lyh
* @method :post
* @time :2024/11/27 14:26
*/
public function updatedProductKeyword(){
$productModel = new Product();
$lists = $productModel->list();
foreach ($lists as $k => $v){
}
}
}