作者 赵彬吉

WebTraffic

... ... @@ -178,6 +178,43 @@ class WebTraffic extends Command
}
//随机访问ip
$ips = $this->getIpAreas(count($need_project));
//特殊日期 降访问率
foreach ($need_project as $project_key => $project){
$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;
}
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;
$res = $this->get_rand([1000-$rate, $rate]);
break;
default:
$res = 0;
}
//不访问
if($res == 1){
unset($need_project[$project_key]);
unset($ips[$project_key]);
}
}
//最多10层深度
$client = new Client(['verify' => false]);
for ($j = 0; $j < 10; $j++) {
... ... @@ -314,6 +351,7 @@ class WebTraffic extends Command
$h = date('H');
$areas = [];
$list = DB::table('gl_area_timezone')->get();
$time_zones = [];
foreach ($list as $v) {
$v = (array)$v;
$country_hour = $h + $v['diff'];
... ... @@ -322,11 +360,16 @@ class WebTraffic extends Command
}
if ($country_hour >= 7 && $country_hour < 23) {
$areas[] = $v['name'];
$time_zones[$v['name']] = $v['diff'];
}
}
//根据地区随机取该地区的IP
$data = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)->inRandomOrder()->limit($num)->get();
return Arr::s2a(Arr::a2s($data));
$data = Arr::s2a(Arr::a2s($data));
foreach ($data as &$item){
$item['diff'] = $time_zones[$item['ip_area']];
}
return $data;
}
/**
... ...