|
...
|
...
|
@@ -3,14 +3,17 @@ |
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\Domain\DomainInfo;
|
|
|
|
use App\Models\Project\DeployOptimize;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Promise\Utils;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -147,12 +150,14 @@ class WebTraffic extends Command |
|
|
|
|
|
|
|
$this->sleep($type);
|
|
|
|
|
|
|
|
$project_list = $this->getProjectList($type);
|
|
|
|
$project_chunk = array_chunk($project_list,500,true);
|
|
|
|
|
|
|
|
foreach ($project_chunk as $chunk) {
|
|
|
|
$page = 1;
|
|
|
|
while (true){
|
|
|
|
$project_list = $this->getProjectList($type, $page);
|
|
|
|
if(!$project_list){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$need_project = [];
|
|
|
|
foreach ($chunk as $project) {
|
|
|
|
foreach ($project_list as $project) {
|
|
|
|
//随机引流间隔
|
|
|
|
$res_sjjg = $this->get_rand($this->sjjg);
|
|
|
|
if ($res_sjjg == 1) {
|
|
...
|
...
|
@@ -169,7 +174,6 @@ class WebTraffic extends Command |
|
|
|
|
|
|
|
$need_project[] = $project;
|
|
|
|
}
|
|
|
|
|
|
|
|
//随机访问ip
|
|
|
|
$ips = $this->getIpAreas(count($need_project));
|
|
|
|
//最多10层深度
|
|
...
|
...
|
@@ -189,6 +193,7 @@ class WebTraffic extends Command |
|
|
|
'url' => $project['visit_urls'][$j],
|
|
|
|
'device_port' => $this->get_rand($this->yddzb)
|
|
|
|
];
|
|
|
|
Log::channel('traffic')->info('traffic project_id:' . $project['project_id'], $data);
|
|
|
|
$promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
|
|
|
|
}
|
|
|
|
Utils::settle($promises)->wait();
|
|
...
|
...
|
@@ -197,6 +202,8 @@ class WebTraffic extends Command |
|
|
|
sleep(rand(2, 10));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$page++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -216,35 +223,76 @@ class WebTraffic extends Command |
|
|
|
/**
|
|
|
|
* 引流的项目
|
|
|
|
*/
|
|
|
|
protected function getProjectList($type){
|
|
|
|
//todo 根据type获取需要引流的项目
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'project_id' => 1,
|
|
|
|
'domain' => 'https://demomark.globalso.com/',
|
|
|
|
]
|
|
|
|
];
|
|
|
|
protected function getProjectList($type, $page){
|
|
|
|
//推广项目
|
|
|
|
$list = Project::with('domainInfo')
|
|
|
|
->leftJoin('gl_project_deploy_optimize', 'gl_project_deploy_optimize.project_id', '=', 'gl_project.id')
|
|
|
|
->where('gl_project_deploy_optimize.domain', '>', 0)
|
|
|
|
->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
|
|
|
|
->whereIn('gl_project_deploy_optimize.project_id', [6,25]) //todo 测试两个项目 后面删掉
|
|
|
|
->where(function ($query) use ($type){
|
|
|
|
if($type == 1){
|
|
|
|
//1-3个月项目
|
|
|
|
$startTime = Carbon::now()->addMonths(-4)->toDateString();
|
|
|
|
$endTime = Carbon::now()->addMonths(-1)->toDateString();
|
|
|
|
$query->whereBetween('gl_project_deploy_optimize.start_date', [$startTime,$endTime]);
|
|
|
|
}elseif($type == 2){
|
|
|
|
//4-8个月项目
|
|
|
|
$startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
|
|
|
|
$endTime = Carbon::now()->addMonths(-4)->endOfDay()->toDateTimeString();
|
|
|
|
$query->whereBetween('gl_project_deploy_optimize.start_date', [$startTime,$endTime]);
|
|
|
|
}else{
|
|
|
|
//大于9个月项目
|
|
|
|
$startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
|
|
|
|
$query->whereBetween('gl_project_deploy_optimize.start_date', '<', $startTime);
|
|
|
|
}
|
|
|
|
})->select('gl_project_deploy_optimize.project_id')->forPage($page, 500)->get();
|
|
|
|
|
|
|
|
//其他地方在引流的域名
|
|
|
|
$other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
foreach ($list as $project) {
|
|
|
|
//其他地方在引流就不再引流了
|
|
|
|
if(in_array($project->domainInfo['domain'], $other)){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$data[] = [
|
|
|
|
'project_id' => $project['project_id'],
|
|
|
|
'domain' => 'https://' . $project->domainInfo['domain'] . '/',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取产品分类、单页和详情链接
|
|
|
|
*/
|
|
|
|
protected function getProductUrls($project_id){
|
|
|
|
//产品分类页面
|
|
|
|
ProjectServer::useProject($project_id);
|
|
|
|
//产品分类页面
|
|
|
|
$product_cate_ids = DB::connection('custom_mysql')->table('gl_product_category')
|
|
|
|
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
|
|
|
|
//只查发布的分类路由
|
|
|
|
$data['urls_cats'] = DB::connection('custom_mysql')->table('gl_route_map')
|
|
|
|
->where('project_id', $project_id)->where('source', 'product_category')->whereIn('source_id', $product_cate_ids)->get()->toArray();
|
|
|
|
->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT_CATE)
|
|
|
|
->whereIn('source_id', $product_cate_ids)->get()->toArray();
|
|
|
|
|
|
|
|
//单页面
|
|
|
|
//todo 发布状态的单页面id
|
|
|
|
$page_ids = DB::connection('custom_mysql')->table('gl_web_custom_template')
|
|
|
|
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
|
|
|
|
//只查发布的单页面
|
|
|
|
$data['urls_page'] = DB::connection('custom_mysql')->table('gl_route_map')
|
|
|
|
->where('project_id', $project_id)->where('source', 'page')->get()->toArray();
|
|
|
|
->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PAGE)
|
|
|
|
->whereIn('source_id', $page_ids)->get()->toArray();
|
|
|
|
|
|
|
|
//产品详情页
|
|
|
|
$product_ids = DB::connection('custom_mysql')->table('gl_product_category')
|
|
|
|
$product_ids = DB::connection('custom_mysql')->table('gl_product')
|
|
|
|
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
|
|
|
|
$data['urls_details'] = DB::connection('custom_mysql')->table('gl_route_map')
|
|
|
|
->where('project_id', $project_id)->where('source', 'product')->whereIn('source_id', $product_ids)->get()->toArray();
|
|
|
|
->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT)
|
|
|
|
->whereIn('source_id', $product_ids)->get()->toArray();
|
|
|
|
|
|
|
|
$data['urls_cats'] = array_merge($data['urls_cats'], $data['urls_page']);
|
|
|
|
if(empty($data['urls_cats'])){
|
...
|
...
|
|