作者 赵彬吉

WebTraffic

@@ -178,6 +178,43 @@ class WebTraffic extends Command @@ -178,6 +178,43 @@ class WebTraffic extends Command
178 } 178 }
179 //随机访问ip 179 //随机访问ip
180 $ips = $this->getIpAreas(count($need_project)); 180 $ips = $this->getIpAreas(count($need_project));
  181 +
  182 + //特殊日期 降访问率
  183 + foreach ($need_project as $project_key => $project){
  184 + $diff = $ips[$project_key]['diff'];
  185 + //当地时间
  186 + $w = date('w', strtotime($diff . 'hour'));
  187 + $date = date('m-d', strtotime($diff . 'hour'));
  188 + //元旦节和圣诞节按照周六的比例处理
  189 + if(in_array($date, ['01-01', '12-25'])){
  190 + $w = 6;
  191 + }
  192 + switch ($w){
  193 + case 0:
  194 + //周日降70-80%
  195 + $rate = rand(70, 80) * 10;
  196 + $res = $this->get_rand([1000-$rate, $rate]);
  197 + break;
  198 + case 5:
  199 + //周5降30-40%
  200 + $rate = rand(30, 40) * 10;
  201 + $res = $this->get_rand([1000-$rate, $rate]);
  202 + break;
  203 + case 6:
  204 + //周6降60-70%
  205 + $rate = rand(60, 70) * 10;
  206 + $res = $this->get_rand([1000-$rate, $rate]);
  207 + break;
  208 + default:
  209 + $res = 0;
  210 + }
  211 + //不访问
  212 + if($res == 1){
  213 + unset($need_project[$project_key]);
  214 + unset($ips[$project_key]);
  215 + }
  216 + }
  217 +
181 //最多10层深度 218 //最多10层深度
182 $client = new Client(['verify' => false]); 219 $client = new Client(['verify' => false]);
183 for ($j = 0; $j < 10; $j++) { 220 for ($j = 0; $j < 10; $j++) {
@@ -314,6 +351,7 @@ class WebTraffic extends Command @@ -314,6 +351,7 @@ class WebTraffic extends Command
314 $h = date('H'); 351 $h = date('H');
315 $areas = []; 352 $areas = [];
316 $list = DB::table('gl_area_timezone')->get(); 353 $list = DB::table('gl_area_timezone')->get();
  354 + $time_zones = [];
317 foreach ($list as $v) { 355 foreach ($list as $v) {
318 $v = (array)$v; 356 $v = (array)$v;
319 $country_hour = $h + $v['diff']; 357 $country_hour = $h + $v['diff'];
@@ -322,11 +360,16 @@ class WebTraffic extends Command @@ -322,11 +360,16 @@ class WebTraffic extends Command
322 } 360 }
323 if ($country_hour >= 7 && $country_hour < 23) { 361 if ($country_hour >= 7 && $country_hour < 23) {
324 $areas[] = $v['name']; 362 $areas[] = $v['name'];
  363 + $time_zones[$v['name']] = $v['diff'];
325 } 364 }
326 } 365 }
327 //根据地区随机取该地区的IP 366 //根据地区随机取该地区的IP
328 $data = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)->inRandomOrder()->limit($num)->get(); 367 $data = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)->inRandomOrder()->limit($num)->get();
329 - return Arr::s2a(Arr::a2s($data)); 368 + $data = Arr::s2a(Arr::a2s($data));
  369 + foreach ($data as &$item){
  370 + $item['diff'] = $time_zones[$item['ip_area']];
  371 + }
  372 + return $data;
330 } 373 }
331 374
332 /** 375 /**