|
|
|
1
|
+<?php
|
|
|
|
2
|
+/**
|
|
|
|
3
|
+ * @remark :
|
|
|
|
4
|
+ * @name :UpdateKeyword.php
|
|
|
|
5
|
+ * @author :lyh
|
|
|
|
6
|
+ * @method :post
|
|
|
|
7
|
+ * @time :2024/7/3 9:23
|
|
|
|
8
|
+ */
|
|
|
|
9
|
+
|
|
|
|
10
|
+namespace App\Console\Commands\Update;
|
|
|
|
11
|
+
|
|
|
|
12
|
+use App\Models\Domain\DomainInfo;
|
|
|
|
13
|
+use App\Models\Product\Keyword;
|
|
|
|
14
|
+use App\Models\Product\KeywordPage;
|
|
|
|
15
|
+use App\Services\ProjectServer;
|
|
|
|
16
|
+use Illuminate\Console\Command;
|
|
|
|
17
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
18
|
+
|
|
|
|
19
|
+class UpdateKeyword extends Command
|
|
|
|
20
|
+{
|
|
|
|
21
|
+ /**
|
|
|
|
22
|
+ * The name and signature of the console command.
|
|
|
|
23
|
+ *
|
|
|
|
24
|
+ * @var string
|
|
|
|
25
|
+ */
|
|
|
|
26
|
+ protected $signature = 'update_keyword';
|
|
|
|
27
|
+
|
|
|
|
28
|
+ /**
|
|
|
|
29
|
+ * The console command description.
|
|
|
|
30
|
+ *
|
|
|
|
31
|
+ * @var string
|
|
|
|
32
|
+ */
|
|
|
|
33
|
+ protected $description = '批量更新关键词内容';
|
|
|
|
34
|
+
|
|
|
|
35
|
+ public function handle(){
|
|
|
|
36
|
+ while (true){
|
|
|
|
37
|
+ $keywordPageModel = new KeywordPage();
|
|
|
|
38
|
+ $lists = $keywordPageModel->list(['status'=>0]);
|
|
|
|
39
|
+ if(empty($lists)){
|
|
|
|
40
|
+ sleep(100);
|
|
|
|
41
|
+ continue;
|
|
|
|
42
|
+ }
|
|
|
|
43
|
+ $domainModel = new DomainInfo();
|
|
|
|
44
|
+ foreach ($lists as $v){
|
|
|
|
45
|
+ ProjectServer::useProject($v['project_id']);
|
|
|
|
46
|
+ $this->saveKeywordContent($v);
|
|
|
|
47
|
+ DB::disconnect('custom_mysql');
|
|
|
|
48
|
+ //获取当前项目的域名
|
|
|
|
49
|
+ $domainInfo = $domainModel->read(['project_id'=>$v['project_id']]);
|
|
|
|
50
|
+ if($domainInfo !== false){
|
|
|
|
51
|
+ $this->curlDelRoute($domainInfo['domain'],$v['project_id']);
|
|
|
|
52
|
+ }
|
|
|
|
53
|
+ }
|
|
|
|
54
|
+ sleep(10);
|
|
|
|
55
|
+ }
|
|
|
|
56
|
+
|
|
|
|
57
|
+ }
|
|
|
|
58
|
+
|
|
|
|
59
|
+ /**
|
|
|
|
60
|
+ * @remark :更新关键词内容
|
|
|
|
61
|
+ * @name :saveKeywordContent
|
|
|
|
62
|
+ * @author :lyh
|
|
|
|
63
|
+ * @method :post
|
|
|
|
64
|
+ * @time :2024/7/3 10:25
|
|
|
|
65
|
+ */
|
|
|
|
66
|
+ public function saveKeywordContent($info){
|
|
|
|
67
|
+ $keywordModel = new Keyword();
|
|
|
|
68
|
+ $updateObject = json_decode($info['update_object'],true);
|
|
|
|
69
|
+ $text = json_decode($info['text'],true);
|
|
|
|
70
|
+ if(empty($text)){
|
|
|
|
71
|
+ return false;
|
|
|
|
72
|
+ }
|
|
|
|
73
|
+ $number = count($info['text']);
|
|
|
|
74
|
+ $randomNumber = rand(0, $number - 1);
|
|
|
|
75
|
+ if($updateObject['type'] == 0){//更新所有关键字
|
|
|
|
76
|
+ $keywordModel->edit(['keyword_content'=>$text[$randomNumber]],['status'=>1]);
|
|
|
|
77
|
+ }else{
|
|
|
|
78
|
+ //按传递的关键字更新
|
|
|
|
79
|
+ if(!empty($updateObject['keyword'])){
|
|
|
|
80
|
+ $updateObject['keyword'] = (array)$updateObject['keyword'];
|
|
|
|
81
|
+ $keywordModel->edit(['keyword_content'=>$text[$randomNumber]],['title'=>['in',$updateObject['keyword']]]);
|
|
|
|
82
|
+ }
|
|
|
|
83
|
+ //按给定的数量更新
|
|
|
|
84
|
+ if(!empty($updateObject['number']) && ($updateObject['number'] != 0)){
|
|
|
|
85
|
+ $keywordIdArr = $keywordModel->where("status",1)->inRandomOrder()->take($updateObject['number'])->pluck('id')->toArray();
|
|
|
|
86
|
+ $keywordModel->edit(['keyword_content'=>$text[$randomNumber]],['id'=>['in',$keywordIdArr]]);
|
|
|
|
87
|
+ }
|
|
|
|
88
|
+ }
|
|
|
|
89
|
+ return true;
|
|
|
|
90
|
+ }
|
|
|
|
91
|
+
|
|
|
|
92
|
+ /**
|
|
|
|
93
|
+ * @remark :删除路由通知C端
|
|
|
|
94
|
+ * @name :curlDelRoute
|
|
|
|
95
|
+ * @author :lyh
|
|
|
|
96
|
+ * @method :post
|
|
|
|
97
|
+ * @time :2023/11/30 14:43
|
|
|
|
98
|
+ */
|
|
|
|
99
|
+ public function curlDelRoute($domain,$project_id){
|
|
|
|
100
|
+ if (strpos($domain, 'https://') === false) {
|
|
|
|
101
|
+ $domain = 'https://' . $domain . '/';
|
|
|
|
102
|
+ }
|
|
|
|
103
|
+ $url = $domain.'api/update_page/?project_id='.$project_id.'&route=4';
|
|
|
|
104
|
+ shell_exec('curl -k "'.$url.'"');
|
|
|
|
105
|
+ return true;
|
|
|
|
106
|
+ }
|
|
|
|
107
|
+} |