|
@@ -3,14 +3,17 @@ |
|
@@ -3,14 +3,17 @@ |
|
3
|
namespace App\Console\Commands;
|
3
|
namespace App\Console\Commands;
|
|
4
|
|
4
|
|
|
5
|
use App\Helper\Arr;
|
5
|
use App\Helper\Arr;
|
|
6
|
-use App\Models\Product\Category;
|
|
|
|
7
|
-use App\Models\Product\Product;
|
6
|
+use App\Models\Domain\DomainInfo;
|
|
|
|
7
|
+use App\Models\Project\DeployOptimize;
|
|
|
|
8
|
+use App\Models\Project\Project;
|
|
8
|
use App\Models\RouteMap\RouteMap;
|
9
|
use App\Models\RouteMap\RouteMap;
|
|
9
|
use App\Services\ProjectServer;
|
10
|
use App\Services\ProjectServer;
|
|
|
|
11
|
+use Carbon\Carbon;
|
|
10
|
use GuzzleHttp\Client;
|
12
|
use GuzzleHttp\Client;
|
|
11
|
use GuzzleHttp\Promise\Utils;
|
13
|
use GuzzleHttp\Promise\Utils;
|
|
12
|
use Illuminate\Console\Command;
|
14
|
use Illuminate\Console\Command;
|
|
13
|
use Illuminate\Support\Facades\DB;
|
15
|
use Illuminate\Support\Facades\DB;
|
|
|
|
16
|
+use Illuminate\Support\Facades\Log;
|
|
14
|
use Illuminate\Support\Str;
|
17
|
use Illuminate\Support\Str;
|
|
15
|
|
18
|
|
|
16
|
/**
|
19
|
/**
|
|
@@ -147,12 +150,14 @@ class WebTraffic extends Command |
|
@@ -147,12 +150,14 @@ class WebTraffic extends Command |
|
147
|
|
150
|
|
|
148
|
$this->sleep($type);
|
151
|
$this->sleep($type);
|
|
149
|
|
152
|
|
|
150
|
- $project_list = $this->getProjectList($type);
|
|
|
|
151
|
- $project_chunk = array_chunk($project_list,500,true);
|
|
|
|
152
|
-
|
|
|
|
153
|
- foreach ($project_chunk as $chunk) {
|
153
|
+ $page = 1;
|
|
|
|
154
|
+ while (true){
|
|
|
|
155
|
+ $project_list = $this->getProjectList($type, $page);
|
|
|
|
156
|
+ if(!$project_list){
|
|
|
|
157
|
+ break;
|
|
|
|
158
|
+ }
|
|
154
|
$need_project = [];
|
159
|
$need_project = [];
|
|
155
|
- foreach ($chunk as $project) {
|
160
|
+ foreach ($project_list as $project) {
|
|
156
|
//随机引流间隔
|
161
|
//随机引流间隔
|
|
157
|
$res_sjjg = $this->get_rand($this->sjjg);
|
162
|
$res_sjjg = $this->get_rand($this->sjjg);
|
|
158
|
if ($res_sjjg == 1) {
|
163
|
if ($res_sjjg == 1) {
|
|
@@ -169,7 +174,6 @@ class WebTraffic extends Command |
|
@@ -169,7 +174,6 @@ class WebTraffic extends Command |
|
169
|
|
174
|
|
|
170
|
$need_project[] = $project;
|
175
|
$need_project[] = $project;
|
|
171
|
}
|
176
|
}
|
|
172
|
-
|
|
|
|
173
|
//随机访问ip
|
177
|
//随机访问ip
|
|
174
|
$ips = $this->getIpAreas(count($need_project));
|
178
|
$ips = $this->getIpAreas(count($need_project));
|
|
175
|
//最多10层深度
|
179
|
//最多10层深度
|
|
@@ -189,6 +193,7 @@ class WebTraffic extends Command |
|
@@ -189,6 +193,7 @@ class WebTraffic extends Command |
|
189
|
'url' => $project['visit_urls'][$j],
|
193
|
'url' => $project['visit_urls'][$j],
|
|
190
|
'device_port' => $this->get_rand($this->yddzb)
|
194
|
'device_port' => $this->get_rand($this->yddzb)
|
|
191
|
];
|
195
|
];
|
|
|
|
196
|
+ Log::channel('traffic')->info('traffic project_id:' . $project['project_id'], $data);
|
|
192
|
$promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
|
197
|
$promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
|
|
193
|
}
|
198
|
}
|
|
194
|
Utils::settle($promises)->wait();
|
199
|
Utils::settle($promises)->wait();
|
|
@@ -197,6 +202,8 @@ class WebTraffic extends Command |
|
@@ -197,6 +202,8 @@ class WebTraffic extends Command |
|
197
|
sleep(rand(2, 10));
|
202
|
sleep(rand(2, 10));
|
|
198
|
}
|
203
|
}
|
|
199
|
}
|
204
|
}
|
|
|
|
205
|
+
|
|
|
|
206
|
+ $page++;
|
|
200
|
}
|
207
|
}
|
|
201
|
}
|
208
|
}
|
|
202
|
|
209
|
|
|
@@ -216,35 +223,76 @@ class WebTraffic extends Command |
|
@@ -216,35 +223,76 @@ class WebTraffic extends Command |
|
216
|
/**
|
223
|
/**
|
|
217
|
* 引流的项目
|
224
|
* 引流的项目
|
|
218
|
*/
|
225
|
*/
|
|
219
|
- protected function getProjectList($type){
|
|
|
|
220
|
- //todo 根据type获取需要引流的项目
|
|
|
|
221
|
- return [
|
|
|
|
222
|
- [
|
|
|
|
223
|
- 'project_id' => 1,
|
|
|
|
224
|
- 'domain' => 'https://demomark.globalso.com/',
|
|
|
|
225
|
- ]
|
226
|
+ protected function getProjectList($type, $page){
|
|
|
|
227
|
+ //推广项目
|
|
|
|
228
|
+ $list = Project::with('domainInfo')
|
|
|
|
229
|
+ ->leftJoin('gl_project_deploy_optimize', 'gl_project_deploy_optimize.project_id', '=', 'gl_project.id')
|
|
|
|
230
|
+ ->where('gl_project_deploy_optimize.domain', '>', 0)
|
|
|
|
231
|
+ ->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
|
|
|
|
232
|
+ ->whereIn('gl_project_deploy_optimize.project_id', [6,25]) //todo 测试两个项目 后面删掉
|
|
|
|
233
|
+ ->where(function ($query) use ($type){
|
|
|
|
234
|
+ if($type == 1){
|
|
|
|
235
|
+ //1-3个月项目
|
|
|
|
236
|
+ $startTime = Carbon::now()->addMonths(-4)->toDateString();
|
|
|
|
237
|
+ $endTime = Carbon::now()->addMonths(-1)->toDateString();
|
|
|
|
238
|
+ $query->whereBetween('gl_project_deploy_optimize.start_date', [$startTime,$endTime]);
|
|
|
|
239
|
+ }elseif($type == 2){
|
|
|
|
240
|
+ //4-8个月项目
|
|
|
|
241
|
+ $startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
|
|
|
|
242
|
+ $endTime = Carbon::now()->addMonths(-4)->endOfDay()->toDateTimeString();
|
|
|
|
243
|
+ $query->whereBetween('gl_project_deploy_optimize.start_date', [$startTime,$endTime]);
|
|
|
|
244
|
+ }else{
|
|
|
|
245
|
+ //大于9个月项目
|
|
|
|
246
|
+ $startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
|
|
|
|
247
|
+ $query->whereBetween('gl_project_deploy_optimize.start_date', '<', $startTime);
|
|
|
|
248
|
+ }
|
|
|
|
249
|
+ })->select('gl_project_deploy_optimize.project_id')->forPage($page, 500)->get();
|
|
|
|
250
|
+
|
|
|
|
251
|
+ //其他地方在引流的域名
|
|
|
|
252
|
+ $other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
|
|
|
|
253
|
+
|
|
|
|
254
|
+ $data = [];
|
|
|
|
255
|
+ foreach ($list as $project) {
|
|
|
|
256
|
+ //其他地方在引流就不再引流了
|
|
|
|
257
|
+ if(in_array($project->domainInfo['domain'], $other)){
|
|
|
|
258
|
+ continue;
|
|
|
|
259
|
+ }
|
|
|
|
260
|
+ $data[] = [
|
|
|
|
261
|
+ 'project_id' => $project['project_id'],
|
|
|
|
262
|
+ 'domain' => 'https://' . $project->domainInfo['domain'] . '/',
|
|
226
|
];
|
263
|
];
|
|
227
|
}
|
264
|
}
|
|
228
|
|
265
|
|
|
|
|
266
|
+ return $data;
|
|
|
|
267
|
+ }
|
|
|
|
268
|
+
|
|
229
|
/**
|
269
|
/**
|
|
230
|
* 获取产品分类、单页和详情链接
|
270
|
* 获取产品分类、单页和详情链接
|
|
231
|
*/
|
271
|
*/
|
|
232
|
protected function getProductUrls($project_id){
|
272
|
protected function getProductUrls($project_id){
|
|
233
|
- //产品分类页面
|
|
|
|
234
|
ProjectServer::useProject($project_id);
|
273
|
ProjectServer::useProject($project_id);
|
|
|
|
274
|
+ //产品分类页面
|
|
235
|
$product_cate_ids = DB::connection('custom_mysql')->table('gl_product_category')
|
275
|
$product_cate_ids = DB::connection('custom_mysql')->table('gl_product_category')
|
|
236
|
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
|
276
|
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
|
|
|
|
277
|
+ //只查发布的分类路由
|
|
237
|
$data['urls_cats'] = DB::connection('custom_mysql')->table('gl_route_map')
|
278
|
$data['urls_cats'] = DB::connection('custom_mysql')->table('gl_route_map')
|
|
238
|
- ->where('project_id', $project_id)->where('source', 'product_category')->whereIn('source_id', $product_cate_ids)->get()->toArray();
|
279
|
+ ->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT_CATE)
|
|
|
|
280
|
+ ->whereIn('source_id', $product_cate_ids)->get()->toArray();
|
|
|
|
281
|
+
|
|
239
|
//单页面
|
282
|
//单页面
|
|
240
|
- //todo 发布状态的单页面id
|
283
|
+ $page_ids = DB::connection('custom_mysql')->table('gl_web_custom_template')
|
|
|
|
284
|
+ ->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
|
|
|
|
285
|
+ //只查发布的单页面
|
|
241
|
$data['urls_page'] = DB::connection('custom_mysql')->table('gl_route_map')
|
286
|
$data['urls_page'] = DB::connection('custom_mysql')->table('gl_route_map')
|
|
242
|
- ->where('project_id', $project_id)->where('source', 'page')->get()->toArray();
|
287
|
+ ->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PAGE)
|
|
|
|
288
|
+ ->whereIn('source_id', $page_ids)->get()->toArray();
|
|
|
|
289
|
+
|
|
243
|
//产品详情页
|
290
|
//产品详情页
|
|
244
|
- $product_ids = DB::connection('custom_mysql')->table('gl_product_category')
|
291
|
+ $product_ids = DB::connection('custom_mysql')->table('gl_product')
|
|
245
|
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
|
292
|
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
|
|
246
|
$data['urls_details'] = DB::connection('custom_mysql')->table('gl_route_map')
|
293
|
$data['urls_details'] = DB::connection('custom_mysql')->table('gl_route_map')
|
|
247
|
- ->where('project_id', $project_id)->where('source', 'product')->whereIn('source_id', $product_ids)->get()->toArray();
|
294
|
+ ->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT)
|
|
|
|
295
|
+ ->whereIn('source_id', $product_ids)->get()->toArray();
|
|
248
|
|
296
|
|
|
249
|
$data['urls_cats'] = array_merge($data['urls_cats'], $data['urls_page']);
|
297
|
$data['urls_cats'] = array_merge($data['urls_cats'], $data['urls_page']);
|
|
250
|
if(empty($data['urls_cats'])){
|
298
|
if(empty($data['urls_cats'])){
|