SendKeyword.php
6.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2025/3/11
* Time: 14:13
*/
namespace App\Console\Commands\Product;
use App\Models\Product\Keyword;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use App\Models\RankData\RankData;
use App\Repositories\ToolRepository;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* Class SendKeyword
* @package App\Console\Commands\Product
*/
class SendKeyword extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'send_product_tag_keyword';
/**
* The console command description.
*
* @var string
*/
protected $description = '未达标项目 自动推送拼接关键词 到监控系统';
/**
* SendKeyword constructor.
*/
public function __construct()
{
parent::__construct();
}
/**
* TODO 查询不达标优化项目, 按照规则推送拼接关键词到监控系统
* http://zentao.globalso.com/index.php?m=task&f=view&taskID=185918
* @return bool
*/
public function handle()
{
$field = ['gl_project.id', 'gl_project.company', 'gl_project.main_lang_id', 'b.is_auto_keywords', 'b.start_date', 'b.api_no', 'd.domain'];
$projects = Project::select($field)->leftJoin('gl_project_deploy_optimize as b', 'gl_project.id', '=', 'b.project_id')
->leftJoin('gl_project_online_check as c', 'gl_project.id', '=', 'c.project_id')
->leftJoin('gl_domain_info as d', 'gl_project.id', '=', 'd.project_id')
->where('gl_project.type', Project::TYPE_TWO)
->where('gl_project.extend_type', 0) // 是否续费是由extend_type字段控制
->where('gl_project.delete_status', Project::IS_DEL_FALSE)
->where('gl_project.main_lang_id', '<>', 8) // 不需要俄语站点项目
->where(function ($subQuery) {
$subQuery->orwhere('c.qa_status', OnlineCheck::STATUS_ONLINE_TRUE)->orwhere('gl_project.is_upgrade', Project::IS_UPGRADE_TRUE);
})
->get();
$time = time();
$send_num = [30 => 1000, 60 => 3000, 90 => 6000];
$ban_domain = $this->banDomain();
foreach ($projects as $item) {
if (empty($item->is_auto_keywords))
continue;
if (in_array($item->domain, $ban_domain))
continue;
if (empty($item->api_no)) {
$this->output('项目ID:' . $item->id . ', api_no为空;');
continue;
}
if (empty($item->start_date)) {
$this->output('项目ID:' . $item->id . ', 推广开始时间为空;');
continue;
}
// 按照间隔时间发送不同关键词数量
$start_time = strtotime($item->start_date);
$day = intval(($time - $start_time) / 86400);
if (empty($send_num[$day])) {
$this->output('项目ID:' . $item->id . ', 推广天数:' . $day . ', 不需要推送;');
continue;
}
// 项目是否达标
$compliance = RankData::where(['project_id' => $item->id, 'api_no' => $item->api_no, 'lang' => ''])->value('is_compliance');
if (FALSE == empty($compliance))
return false;
$project = ProjectServer::useProject($item->id);
if (empty($project)) {
DB::disconnect('custom_mysql');
continue;
}
$send = $this->extendKeyword($item, $send_num[$day]);
DB::disconnect('custom_mysql');
// 数据成功后推送同志
if ($send) {
$item = $item->toArray();
unset($item['main_lang_id']);
unset($item['is_auto_keywords']);
$item['day'] = $day;
$this->sendNotice($item);
}
}
return true;
}
/**
* 截取关键词
* @param $item
* @param int $num
* @return bool
*/
public function extendKeyword($item, $num = 1000)
{
$keywords = Keyword::extendKeyword($item->id);
if (empty($keywords))
return false;
$keywords = array_filter(array_unique($keywords));
$sort = [];
foreach ($keywords as $keyword) {
$sort[] = strlen($keyword);
}
array_multisort($sort, SORT_ASC, $keywords);
$result = array_slice($keywords, 0, $num);
file_put_contents(storage_path('data/send_product_tag_keyword/' . $item->id . '.json'), json_encode($result, 256));
return true;
}
/**
* 通知
* @param $item
* @return bool
*/
public function sendNotice($item)
{
try {
$query = http_build_query($item);
$url = 'http://api.quanqiusou.cn/google-rank/api/v6_add_extend_keywords.php?' . $query;
app(ToolRepository::class)->curlRequest($url, [], 'GET');
// TODO 推送通知 待定
} catch (\Exception $e) {
$this->output('推送通知失败,项目ID:' . $item['id']);
}
return true;
}
/**
* 禁用
* @return array
*/
public function banDomain()
{
$array = [
'www.venttopurifier.com',
'www.gwxpcsheet.com',
'www.bizzyboi.com',
'www.wholesaleladyclothing.com',
'www.chuanbokeji.com',
'www.goalwhite.com',
'www.yusunheating.com',
'www.bretonprecision.com',
'www.chinarendering.com',
'www.centurybeauty.com',
'www.vazpocable.com',
'www.tengda-smart.com',
'www.kayne-bm.com',
'www.aimazingbag.com',
'www.alpha-lifetech.com',
'www.junyi-laser.com',
'www.unionfurnish.com',
'www.zphydraulic.com',
'www.younisicleaning.com',
'www.shibaodeprecision.com',
'www.semmcocoa.com',
'www.sbdmold.com',
'www.utsfabrictester.com',
'www.tlgantryrobot.com',
'www.slabyte.com',
'www.hysum.com',
'www.rsecobag.com',
'www.yuchomachine.com',
'www.hidinosaurs.com',
'www.medigauze.com',
'www.shtangkefresh.com',
'www.fkcrane.com',
'www.zkmparts.com',
'www.zhishuogroup.com',
'www.yunlinplushtoys.com',
];
return $array;
}
/**
* @param $message
*/
public function output($message)
{
$message = date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
echo $message;
file_put_contents(storage_path('data/send_product_tag_keyword.log'), $message, FILE_APPEND);
}
}