|
...
|
...
|
@@ -7,6 +7,7 @@ use App\Models\Product\Category; |
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\Project\OnlineCheck;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\Project\WebTrafficConfig;
|
|
|
|
use App\Models\Template\BCustomTemplate;
|
|
|
|
use App\Models\WebSetting\WebLanguage;
|
|
|
|
use App\Services\ProjectServer;
|
|
...
|
...
|
@@ -193,35 +194,35 @@ class WebTraffic extends Command |
|
|
|
$need_project[] = $project;
|
|
|
|
}
|
|
|
|
//随机访问ip
|
|
|
|
$ips = $this->getIpAreas(count($need_project));
|
|
|
|
$ips = $this->getIpAreas(array_column($need_project, 'project_id'));
|
|
|
|
|
|
|
|
//特殊日期 降访问率
|
|
|
|
foreach ($need_project as $project_key => $project){
|
|
|
|
if(empty($ips[$project_key]['ip'])){
|
|
|
|
Log::channel('traffic')->info('未获取到ip project_id:' . $project['project_id']);
|
|
|
|
unset($need_project[$project_key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$diff = $ips[$project_key]['diff'];
|
|
|
|
//当地时间
|
|
|
|
$w = date('w', strtotime($diff . 'hour'));
|
|
|
|
$date = date('m-d', strtotime($diff . 'hour'));
|
|
|
|
//元旦节和圣诞节按照周六的比例处理
|
|
|
|
if(in_array($date, ['01-01', '12-25'])){
|
|
|
|
$w = 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
//周五流量不变 周六周日下降20-30% 元旦圣诞下降30-50%
|
|
|
|
switch ($w){
|
|
|
|
case 0:
|
|
|
|
//周日降70-80%
|
|
|
|
$rate = rand(70, 80) * 10;
|
|
|
|
$res = $this->get_rand([1000-$rate, $rate]);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
//周5降30-40%
|
|
|
|
$rate = rand(30, 40) * 10;
|
|
|
|
$res = $this->get_rand([1000-$rate, $rate]);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
//周6降60-70%
|
|
|
|
$rate = rand(60, 70) * 10;
|
|
|
|
//周日降20-30%
|
|
|
|
$rate = rand(20, 30) * 10;
|
|
|
|
$res = $this->get_rand([1000-$rate, $rate]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//元旦圣诞下降30-50%
|
|
|
|
if(in_array($date, ['01-01', '12-25'])){
|
|
|
|
$rate = rand(30, 50) * 10;
|
|
|
|
$res = $this->get_rand([1000-$rate, $rate]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$res = 0;
|
|
|
|
}
|
|
|
|
//不访问
|
|
...
|
...
|
@@ -265,7 +266,7 @@ class WebTraffic extends Command |
|
|
|
$page++;
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
Log::channel('traffic')->error($e->getMessage());
|
|
|
|
Log::channel('traffic')->error("line" . $e->getLine() . ',error:' . $e->getMessage(), $e->getTrace());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -298,22 +299,22 @@ class WebTraffic extends Command |
|
|
|
->where('gl_project.is_upgrade', 0) //非升级项目
|
|
|
|
->where('gl_project.main_lang_id', '<>', $ru_lang_id) //非俄语站
|
|
|
|
->where(function ($query) use ($type) {
|
|
|
|
if($type == 1){
|
|
|
|
//1-3个月项目
|
|
|
|
$startTime = Carbon::now()->addMonths(-4)->toDateString();
|
|
|
|
$endTime = Carbon::now()->addMonths(-1)->toDateString();
|
|
|
|
$query->whereBetween('pdo.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('pdo.start_date', [$startTime,$endTime]);
|
|
|
|
}else{
|
|
|
|
//大于9个月项目
|
|
|
|
$startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
|
|
|
|
$query->where('pdo.start_date', '<', $startTime);
|
|
|
|
}
|
|
|
|
})->select(['pdo.project_id','gl_project.main_lang_id','gl_project.id'])->forPage($page, 500)->get();
|
|
|
|
if($type == 1){
|
|
|
|
//1-3个月项目
|
|
|
|
$startTime = Carbon::now()->addMonths(-4)->toDateString();
|
|
|
|
$endTime = Carbon::now()->addMonths(-1)->toDateString();
|
|
|
|
$query->whereBetween('pdo.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('pdo.start_date', [$startTime,$endTime]);
|
|
|
|
}else{
|
|
|
|
//大于9个月项目
|
|
|
|
$startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
|
|
|
|
$query->where('pdo.start_date', '<', $startTime);
|
|
|
|
}
|
|
|
|
})->select(['pdo.project_id','gl_project.main_lang_id','gl_project.id'])->forPage($page, 500)->get();
|
|
|
|
//其他地方在引流的域名
|
|
|
|
$other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
|
|
|
|
$data = [];
|
|
...
|
...
|
@@ -368,7 +369,7 @@ class WebTraffic extends Command |
|
|
|
/**
|
|
|
|
* 获取地区IP
|
|
|
|
*/
|
|
|
|
protected function getIpAreas($num)
|
|
|
|
protected function getIpAreas($project_ids)
|
|
|
|
{
|
|
|
|
//本地时间为7-23点的地区
|
|
|
|
$h = date('H');
|
|
...
|
...
|
@@ -386,11 +387,26 @@ class WebTraffic extends Command |
|
|
|
$time_zones[$v['name']] = $v['diff'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//根据地区随机取该地区的IP
|
|
|
|
$data = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)->inRandomOrder()->limit($num)->get();
|
|
|
|
$data = Arr::s2a(Arr::a2s($data));
|
|
|
|
foreach ($data as &$item){
|
|
|
|
$item['diff'] = $time_zones[$item['ip_area']];
|
|
|
|
$data = [];
|
|
|
|
foreach ($project_ids as $project_id){
|
|
|
|
//引流配置
|
|
|
|
$config = WebTrafficConfig::getCacheInfoByProjectId($project_id);
|
|
|
|
$main_countries = !empty($config->main_countries) ? explode(',',$config->main_countries) : [];
|
|
|
|
$filter_countries = !empty($config->filter_countries) ? explode(',',$config->filter_countries) : [];
|
|
|
|
|
|
|
|
//根据地区随机取该地区的IP
|
|
|
|
$ipdata = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)
|
|
|
|
->where(function ($query) use ($main_countries, $filter_countries){
|
|
|
|
if($main_countries){
|
|
|
|
$query->whereIn('ip_area', $main_countries);
|
|
|
|
}
|
|
|
|
if($filter_countries){
|
|
|
|
$query->whereNotIn('ip_area', $main_countries);
|
|
|
|
}
|
|
|
|
})->inRandomOrder()->first();
|
|
|
|
$ipdata = (array)$ipdata ?: [];
|
|
|
|
$ipdata['diff'] = $time_zones[$ipdata['ip_area']];
|
|
|
|
$data[] = $ipdata;
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
...
|
...
|
@@ -457,6 +473,9 @@ class WebTraffic extends Command |
|
|
|
$v = $project_urls['home'] . $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Log::channel('traffic')->info('project_id:访问深度' . $res_sdzb, $url);
|
|
|
|
|
|
|
|
return array_unique(array_filter($url));
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|