作者 赵彬吉

引流设置

@@ -7,6 +7,7 @@ use App\Models\Product\Category; @@ -7,6 +7,7 @@ use App\Models\Product\Category;
7 use App\Models\Product\Product; 7 use App\Models\Product\Product;
8 use App\Models\Project\OnlineCheck; 8 use App\Models\Project\OnlineCheck;
9 use App\Models\Project\Project; 9 use App\Models\Project\Project;
  10 +use App\Models\Project\WebTrafficConfig;
10 use App\Models\Template\BCustomTemplate; 11 use App\Models\Template\BCustomTemplate;
11 use App\Models\WebSetting\WebLanguage; 12 use App\Models\WebSetting\WebLanguage;
12 use App\Services\ProjectServer; 13 use App\Services\ProjectServer;
@@ -193,35 +194,35 @@ class WebTraffic extends Command @@ -193,35 +194,35 @@ class WebTraffic extends Command
193 $need_project[] = $project; 194 $need_project[] = $project;
194 } 195 }
195 //随机访问ip 196 //随机访问ip
196 - $ips = $this->getIpAreas(count($need_project)); 197 + $ips = $this->getIpAreas(array_column($need_project, 'project_id'));
197 198
198 //特殊日期 降访问率 199 //特殊日期 降访问率
199 foreach ($need_project as $project_key => $project){ 200 foreach ($need_project as $project_key => $project){
  201 + if(empty($ips[$project_key]['ip'])){
  202 + Log::channel('traffic')->info('未获取到ip project_id:' . $project['project_id']);
  203 + unset($need_project[$project_key]);
  204 + continue;
  205 + }
200 $diff = $ips[$project_key]['diff']; 206 $diff = $ips[$project_key]['diff'];
201 //当地时间 207 //当地时间
202 $w = date('w', strtotime($diff . 'hour')); 208 $w = date('w', strtotime($diff . 'hour'));
203 $date = date('m-d', strtotime($diff . 'hour')); 209 $date = date('m-d', strtotime($diff . 'hour'));
204 - //元旦节和圣诞节按照周六的比例处理  
205 - if(in_array($date, ['01-01', '12-25'])){  
206 - $w = 6;  
207 - } 210 +
  211 + //周五流量不变 周六周日下降20-30% 元旦圣诞下降30-50%
208 switch ($w){ 212 switch ($w){
209 case 0: 213 case 0:
210 - //周日降70-80%  
211 - $rate = rand(70, 80) * 10;  
212 - $res = $this->get_rand([1000-$rate, $rate]);  
213 - break;  
214 - case 5:  
215 - //周5降30-40%  
216 - $rate = rand(30, 40) * 10;  
217 - $res = $this->get_rand([1000-$rate, $rate]);  
218 - break;  
219 case 6: 214 case 6:
220 - //周6降60-70%  
221 - $rate = rand(60, 70) * 10; 215 + //周日降20-30%
  216 + $rate = rand(20, 30) * 10;
222 $res = $this->get_rand([1000-$rate, $rate]); 217 $res = $this->get_rand([1000-$rate, $rate]);
223 break; 218 break;
224 default: 219 default:
  220 + //元旦圣诞下降30-50%
  221 + if(in_array($date, ['01-01', '12-25'])){
  222 + $rate = rand(30, 50) * 10;
  223 + $res = $this->get_rand([1000-$rate, $rate]);
  224 + break;
  225 + }
225 $res = 0; 226 $res = 0;
226 } 227 }
227 //不访问 228 //不访问
@@ -368,7 +369,7 @@ class WebTraffic extends Command @@ -368,7 +369,7 @@ class WebTraffic extends Command
368 /** 369 /**
369 * 获取地区IP 370 * 获取地区IP
370 */ 371 */
371 - protected function getIpAreas($num) 372 + protected function getIpAreas($project_ids)
372 { 373 {
373 //本地时间为7-23点的地区 374 //本地时间为7-23点的地区
374 $h = date('H'); 375 $h = date('H');
@@ -386,11 +387,26 @@ class WebTraffic extends Command @@ -386,11 +387,26 @@ class WebTraffic extends Command
386 $time_zones[$v['name']] = $v['diff']; 387 $time_zones[$v['name']] = $v['diff'];
387 } 388 }
388 } 389 }
389 - //根据地区随机取该地区的IP  
390 - $data = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)->inRandomOrder()->limit($num)->get();  
391 - $data = Arr::s2a(Arr::a2s($data));  
392 - foreach ($data as &$item){  
393 - $item['diff'] = $time_zones[$item['ip_area']]; 390 + $data = [];
  391 + foreach ($project_ids as $project_id){
  392 + //引流配置
  393 + $config = WebTrafficConfig::getCacheInfoByProjectId($project_id);
  394 + $main_countries = $config->main_countries ? explode(',',$config->main_countries) : [];
  395 + $filter_countries = $config->filter_countries ? explode(',',$config->filter_countries) : [];
  396 +
  397 + //根据地区随机取该地区的IP
  398 + $ipdata = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)
  399 + ->where(function ($query) use ($main_countries, $filter_countries){
  400 + if($main_countries){
  401 + $query->whereIn('ip_area', $main_countries);
  402 + }
  403 + if($filter_countries){
  404 + $query->whereNotIn('ip_area', $main_countries);
  405 + }
  406 + })->inRandomOrder()->first();
  407 + $ipdata = (array)$ipdata ?: [];
  408 + $ipdata['diff'] = $time_zones[$ipdata['ip_area']];
  409 + $data[] = $ipdata;
394 } 410 }
395 return $data; 411 return $data;
396 } 412 }
@@ -457,6 +473,9 @@ class WebTraffic extends Command @@ -457,6 +473,9 @@ class WebTraffic extends Command
457 $v = $project_urls['home'] . $v; 473 $v = $project_urls['home'] . $v;
458 } 474 }
459 } 475 }
  476 +
  477 + Log::channel('traffic')->info('project_id:访问深度' . $res_sdzb, $url);
  478 +
460 return array_unique(array_filter($url)); 479 return array_unique(array_filter($url));
461 } 480 }
462 481
@@ -7,6 +7,7 @@ use App\Models\Product\Category; @@ -7,6 +7,7 @@ use App\Models\Product\Category;
7 use App\Models\Product\Product; 7 use App\Models\Product\Product;
8 use App\Models\Project\OnlineCheck; 8 use App\Models\Project\OnlineCheck;
9 use App\Models\Project\Project; 9 use App\Models\Project\Project;
  10 +use App\Models\Project\WebTrafficConfig;
10 use App\Models\Template\BCustomTemplate; 11 use App\Models\Template\BCustomTemplate;
11 use App\Models\WebSetting\WebLanguage; 12 use App\Models\WebSetting\WebLanguage;
12 use App\Services\ProjectServer; 13 use App\Services\ProjectServer;
@@ -229,35 +230,34 @@ class WebTrafficRussia extends Command @@ -229,35 +230,34 @@ class WebTrafficRussia extends Command
229 $need_project[] = $project; 230 $need_project[] = $project;
230 } 231 }
231 //随机访问ip 232 //随机访问ip
232 - $ips = $this->getIpAreas(count($need_project)); 233 + $ips = $this->getIpAreas(array_column($need_project, 'project_id'));
233 234
234 //特殊日期 降访问率 235 //特殊日期 降访问率
235 foreach ($need_project as $project_key => $project){ 236 foreach ($need_project as $project_key => $project){
  237 + if(empty($ips[$project_key]['ip'])){
  238 + Log::channel('traffic')->info('未获取到ip project_id:' . $project['project_id']);
  239 + unset($need_project[$project_key]);
  240 + continue;
  241 + }
236 $diff = $ips[$project_key]['diff']; 242 $diff = $ips[$project_key]['diff'];
237 //当地时间 243 //当地时间
238 $w = date('w', strtotime($diff . 'hour')); 244 $w = date('w', strtotime($diff . 'hour'));
239 $date = date('m-d', strtotime($diff . 'hour')); 245 $date = date('m-d', strtotime($diff . 'hour'));
240 - //元旦节和圣诞节按照周六的比例处理  
241 - if(in_array($date, ['01-01', '12-25'])){  
242 - $w = 6;  
243 - } 246 + //周五流量不变 周六周日下降20-30% 元旦圣诞下降30-50%
244 switch ($w){ 247 switch ($w){
245 case 0: 248 case 0:
246 - //周日降70-80%  
247 - $rate = rand(70, 80) * 10;  
248 - $res = $this->get_rand([1000-$rate, $rate]);  
249 - break;  
250 - case 5:  
251 - //周5降30-40%  
252 - $rate = rand(30, 40) * 10;  
253 - $res = $this->get_rand([1000-$rate, $rate]);  
254 - break;  
255 case 6: 249 case 6:
256 - //周6降60-70%  
257 - $rate = rand(60, 70) * 10; 250 + //周日降20-30%
  251 + $rate = rand(20, 30) * 10;
258 $res = $this->get_rand([1000-$rate, $rate]); 252 $res = $this->get_rand([1000-$rate, $rate]);
259 break; 253 break;
260 default: 254 default:
  255 + //元旦圣诞下降30-50%
  256 + if(in_array($date, ['01-01', '12-25'])){
  257 + $rate = rand(30, 50) * 10;
  258 + $res = $this->get_rand([1000-$rate, $rate]);
  259 + break;
  260 + }
261 $res = 0; 261 $res = 0;
262 } 262 }
263 //不访问 263 //不访问
@@ -404,7 +404,7 @@ class WebTrafficRussia extends Command @@ -404,7 +404,7 @@ class WebTrafficRussia extends Command
404 /** 404 /**
405 * 获取地区IP 405 * 获取地区IP
406 */ 406 */
407 - protected function getIpAreas($num) 407 + protected function getIpAreas($project_ids)
408 { 408 {
409 //本地时间为7-23点的地区 409 //本地时间为7-23点的地区
410 $h = date('H'); 410 $h = date('H');
@@ -431,11 +431,31 @@ class WebTrafficRussia extends Command @@ -431,11 +431,31 @@ class WebTrafficRussia extends Command
431 } 431 }
432 432
433 $data = []; 433 $data = [];
434 - for ($i=0;$i<$num;$i++){  
435 - //ip国家占比  
436 - $ip_area = $this->get_rand($country_ratio); 434 + foreach ($project_ids as $project_id) {
  435 + $project_country = $country_ratio;
  436 + //引流配置
  437 + $config = WebTrafficConfig::getCacheInfoByProjectId($project_id);
  438 + $main_countries = $config->main_countries ? explode(',', $config->main_countries) : [];
  439 + $filter_countries = $config->filter_countries ? explode(',', $config->filter_countries) : [];
  440 + //设置了主推的
  441 + if($main_countries){
  442 + foreach ($project_country as $k => $v){
  443 + if(!in_array($k, $main_countries)){
  444 + unset($project_country[$k]);
  445 + }
  446 + }
  447 + }
  448 + //设置了不推广
  449 + if($filter_countries){
  450 + foreach ($project_country as $k => $v){
  451 + if(in_array($k, $filter_countries)){
  452 + unset($project_country[$k]);
  453 + }
  454 + }
  455 + }
  456 + $ip_area = $this->get_rand($project_country);
437 $res = DB::table('gl_xunpan_ipdata')->where('ip_area', $ip_area)->inRandomOrder()->first(); 457 $res = DB::table('gl_xunpan_ipdata')->where('ip_area', $ip_area)->inRandomOrder()->first();
438 - $res = (array)$res; 458 + $res = (array)$res ?: [];
439 $res['diff'] = $time_zones[$res['ip_area']]; 459 $res['diff'] = $time_zones[$res['ip_area']];
440 $data[] = $res; 460 $data[] = $res;
441 } 461 }
@@ -504,6 +524,9 @@ class WebTrafficRussia extends Command @@ -504,6 +524,9 @@ class WebTrafficRussia extends Command
504 $v = $project_urls['home'] . $v; 524 $v = $project_urls['home'] . $v;
505 } 525 }
506 } 526 }
  527 +
  528 + Log::channel('traffic')->info('project_id:访问深度' . $res_sdzb, $url);
  529 +
507 return array_unique(array_filter($url)); 530 return array_unique(array_filter($url));
508 } 531 }
509 532
@@ -7,6 +7,7 @@ use App\Models\Product\Category; @@ -7,6 +7,7 @@ use App\Models\Product\Category;
7 use App\Models\Product\Product; 7 use App\Models\Product\Product;
8 use App\Models\Project\OnlineCheck; 8 use App\Models\Project\OnlineCheck;
9 use App\Models\Project\Project; 9 use App\Models\Project\Project;
  10 +use App\Models\Project\WebTrafficConfig;
10 use App\Models\Template\BCustomTemplate; 11 use App\Models\Template\BCustomTemplate;
11 use App\Models\WebSetting\WebLanguage; 12 use App\Models\WebSetting\WebLanguage;
12 use App\Services\ProjectServer; 13 use App\Services\ProjectServer;
@@ -52,9 +53,6 @@ class WebTrafficRussiaSpecial extends Command @@ -52,9 +53,6 @@ class WebTrafficRussiaSpecial extends Command
52 parent::__construct(); 53 parent::__construct();
53 } 54 }
54 55
55 - protected $projects = [  
56 - 969 => 60,  
57 - ];  
58 56
59 /** 57 /**
60 * 国家概率 58 * 国家概率
@@ -232,35 +230,34 @@ class WebTrafficRussiaSpecial extends Command @@ -232,35 +230,34 @@ class WebTrafficRussiaSpecial extends Command
232 $need_project[] = $project; 230 $need_project[] = $project;
233 } 231 }
234 //随机访问ip 232 //随机访问ip
235 - $ips = $this->getIpAreas(count($need_project)); 233 + $ips = $this->getIpAreas(array_column($need_project, 'project_id'));
236 234
237 //特殊日期 降访问率 235 //特殊日期 降访问率
238 foreach ($need_project as $project_key => $project){ 236 foreach ($need_project as $project_key => $project){
  237 + if(empty($ips[$project_key]['ip'])){
  238 + Log::channel('traffic')->info('未获取到ip project_id:' . $project['project_id']);
  239 + unset($need_project[$project_key]);
  240 + continue;
  241 + }
239 $diff = $ips[$project_key]['diff']; 242 $diff = $ips[$project_key]['diff'];
240 //当地时间 243 //当地时间
241 $w = date('w', strtotime($diff . 'hour')); 244 $w = date('w', strtotime($diff . 'hour'));
242 $date = date('m-d', strtotime($diff . 'hour')); 245 $date = date('m-d', strtotime($diff . 'hour'));
243 - //元旦节和圣诞节按照周六的比例处理  
244 - if(in_array($date, ['01-01', '12-25'])){  
245 - $w = 6;  
246 - } 246 + //周五流量不变 周六周日下降20-30% 元旦圣诞下降30-50%
247 switch ($w){ 247 switch ($w){
248 case 0: 248 case 0:
249 - //周日降70-80%  
250 - $rate = rand(70, 80) * 10;  
251 - $res = $this->get_rand([1000-$rate, $rate]);  
252 - break;  
253 - case 5:  
254 - //周5降30-40%  
255 - $rate = rand(30, 40) * 10;  
256 - $res = $this->get_rand([1000-$rate, $rate]);  
257 - break;  
258 case 6: 249 case 6:
259 - //周6降60-70%  
260 - $rate = rand(60, 70) * 10; 250 + //周日降20-30%
  251 + $rate = rand(20, 30) * 10;
261 $res = $this->get_rand([1000-$rate, $rate]); 252 $res = $this->get_rand([1000-$rate, $rate]);
262 break; 253 break;
263 default: 254 default:
  255 + //元旦圣诞下降30-50%
  256 + if(in_array($date, ['01-01', '12-25'])){
  257 + $rate = rand(30, 50) * 10;
  258 + $res = $this->get_rand([1000-$rate, $rate]);
  259 + break;
  260 + }
264 $res = 0; 261 $res = 0;
265 } 262 }
266 //不访问 263 //不访问
@@ -319,6 +316,9 @@ class WebTrafficRussiaSpecial extends Command @@ -319,6 +316,9 @@ class WebTrafficRussiaSpecial extends Command
319 * 俄语站引流的项目 316 * 俄语站引流的项目
320 */ 317 */
321 protected function getProjectList($page){ 318 protected function getProjectList($page){
  319 + //设置了特殊引流的项目
  320 + $projects = WebTrafficConfig::where('add_num', '>', 0)->pluck('add_num', 'project_id')->toArray();
  321 +
322 $ru_lang_id = WebLanguage::getIdByLang('ru'); 322 $ru_lang_id = WebLanguage::getIdByLang('ru');
323 323
324 //推广项目 324 //推广项目
@@ -330,7 +330,7 @@ class WebTrafficRussiaSpecial extends Command @@ -330,7 +330,7 @@ class WebTrafficRussiaSpecial extends Command
330 ->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR]) 330 ->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
331 ->where('gl_project.is_upgrade', 0) //非升级项目 331 ->where('gl_project.is_upgrade', 0) //非升级项目
332 ->where('gl_project.main_lang_id', $ru_lang_id)// 俄语站 332 ->where('gl_project.main_lang_id', $ru_lang_id)// 俄语站
333 - ->whereIn('gl_project.id', array_keys($this->projects)) 333 + ->whereIn('gl_project.id', array_keys($projects))
334 ->select(['pdo.project_id','gl_project.main_lang_id','gl_project.id'])->forPage($page, 500)->get(); 334 ->select(['pdo.project_id','gl_project.main_lang_id','gl_project.id'])->forPage($page, 500)->get();
335 //其他地方在引流的域名 335 //其他地方在引流的域名
336 // $other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray(); 336 // $other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
@@ -342,7 +342,7 @@ class WebTrafficRussiaSpecial extends Command @@ -342,7 +342,7 @@ class WebTrafficRussiaSpecial extends Command
342 if(Cache::get('web_traffic_russia_special_' . $project['project_id'])){ 342 if(Cache::get('web_traffic_russia_special_' . $project['project_id'])){
343 continue; 343 continue;
344 }else{ 344 }else{
345 - $ttl = 24 * 60 * 60 / $this->projects[$project['project_id']]; 345 + $ttl = 24 * 60 * 60 / ($projects[$project['project_id']] / ($this->sjjg[0] / ($this->sjjg[0] + $this->sjjg[1])));
346 Cache::put('web_traffic_russia_special_' . $project['project_id'], 1, $ttl); 346 Cache::put('web_traffic_russia_special_' . $project['project_id'], 1, $ttl);
347 } 347 }
348 348
@@ -396,7 +396,7 @@ class WebTrafficRussiaSpecial extends Command @@ -396,7 +396,7 @@ class WebTrafficRussiaSpecial extends Command
396 /** 396 /**
397 * 获取地区IP 397 * 获取地区IP
398 */ 398 */
399 - protected function getIpAreas($num) 399 + protected function getIpAreas($project_ids)
400 { 400 {
401 //本地时间为7-23点的地区 401 //本地时间为7-23点的地区
402 $h = date('H'); 402 $h = date('H');
@@ -423,11 +423,31 @@ class WebTrafficRussiaSpecial extends Command @@ -423,11 +423,31 @@ class WebTrafficRussiaSpecial extends Command
423 } 423 }
424 424
425 $data = []; 425 $data = [];
426 - for ($i=0;$i<$num;$i++){  
427 - //ip国家占比  
428 - $ip_area = $this->get_rand($country_ratio); 426 + foreach ($project_ids as $project_id) {
  427 + $project_country = $country_ratio;
  428 + //引流配置
  429 + $config = WebTrafficConfig::getCacheInfoByProjectId($project_id);
  430 + $main_countries = $config->main_countries ? explode(',', $config->main_countries) : [];
  431 + $filter_countries = $config->filter_countries ? explode(',', $config->filter_countries) : [];
  432 + //设置了主推的
  433 + if($main_countries){
  434 + foreach ($project_country as $k => $v){
  435 + if(!in_array($k, $main_countries)){
  436 + unset($project_country[$k]);
  437 + }
  438 + }
  439 + }
  440 + //设置了不推广
  441 + if($filter_countries){
  442 + foreach ($project_country as $k => $v){
  443 + if(in_array($k, $filter_countries)){
  444 + unset($project_country[$k]);
  445 + }
  446 + }
  447 + }
  448 + $ip_area = $this->get_rand($project_country);
429 $res = DB::table('gl_xunpan_ipdata')->where('ip_area', $ip_area)->inRandomOrder()->first(); 449 $res = DB::table('gl_xunpan_ipdata')->where('ip_area', $ip_area)->inRandomOrder()->first();
430 - $res = (array)$res; 450 + $res = (array)$res ?: [];
431 $res['diff'] = $time_zones[$res['ip_area']]; 451 $res['diff'] = $time_zones[$res['ip_area']];
432 $data[] = $res; 452 $data[] = $res;
433 } 453 }
@@ -496,6 +516,9 @@ class WebTrafficRussiaSpecial extends Command @@ -496,6 +516,9 @@ class WebTrafficRussiaSpecial extends Command
496 $v = $project_urls['home'] . $v; 516 $v = $project_urls['home'] . $v;
497 } 517 }
498 } 518 }
  519 +
  520 + Log::channel('traffic')->info('project_id:访问深度' . $res_sdzb, $url);
  521 +
499 return array_unique(array_filter($url)); 522 return array_unique(array_filter($url));
500 } 523 }
501 524
@@ -7,6 +7,7 @@ use App\Models\Product\Category; @@ -7,6 +7,7 @@ use App\Models\Product\Category;
7 use App\Models\Product\Product; 7 use App\Models\Product\Product;
8 use App\Models\Project\OnlineCheck; 8 use App\Models\Project\OnlineCheck;
9 use App\Models\Project\Project; 9 use App\Models\Project\Project;
  10 +use App\Models\Project\WebTrafficConfig;
10 use App\Models\Template\BCustomTemplate; 11 use App\Models\Template\BCustomTemplate;
11 use App\Models\WebSetting\WebLanguage; 12 use App\Models\WebSetting\WebLanguage;
12 use App\Services\ProjectServer; 13 use App\Services\ProjectServer;
@@ -53,20 +54,6 @@ class WebTrafficSpecial extends Command @@ -53,20 +54,6 @@ class WebTrafficSpecial extends Command
53 parent::__construct(); 54 parent::__construct();
54 } 55 }
55 56
56 -  
57 - /**  
58 - * 要增加引流的项目及腰增加的数量  
59 - * key 要引流的ID  
60 - * value 每天要增加的流量  
61 - * @var array  
62 - */  
63 - protected $projects = [  
64 - 509 => 30,  
65 - 79 => 20,  
66 - ];  
67 -  
68 -  
69 -  
70 /** 57 /**
71 * google域名后缀 58 * google域名后缀
72 * @var string[] 59 * @var string[]
@@ -207,35 +194,34 @@ class WebTrafficSpecial extends Command @@ -207,35 +194,34 @@ class WebTrafficSpecial extends Command
207 $need_project[] = $project; 194 $need_project[] = $project;
208 } 195 }
209 //随机访问ip 196 //随机访问ip
210 - $ips = $this->getIpAreas(count($need_project)); 197 + $ips = $this->getIpAreas(array_column($need_project, 'project_id'));
211 198
212 //特殊日期 降访问率 199 //特殊日期 降访问率
213 foreach ($need_project as $project_key => $project){ 200 foreach ($need_project as $project_key => $project){
  201 + if(empty($ips[$project_key]['ip'])){
  202 + Log::channel('traffic')->info('未获取到ip project_id:' . $project['project_id']);
  203 + unset($need_project[$project_key]);
  204 + continue;
  205 + }
214 $diff = $ips[$project_key]['diff']; 206 $diff = $ips[$project_key]['diff'];
215 //当地时间 207 //当地时间
216 $w = date('w', strtotime($diff . 'hour')); 208 $w = date('w', strtotime($diff . 'hour'));
217 $date = date('m-d', strtotime($diff . 'hour')); 209 $date = date('m-d', strtotime($diff . 'hour'));
218 - //元旦节和圣诞节按照周六的比例处理  
219 - if(in_array($date, ['01-01', '12-25'])){  
220 - $w = 6;  
221 - } 210 + //周五流量不变 周六周日下降20-30% 元旦圣诞下降30-50%
222 switch ($w){ 211 switch ($w){
223 case 0: 212 case 0:
224 - //周日降70-80%  
225 - $rate = rand(70, 80) * 10;  
226 - $res = $this->get_rand([1000-$rate, $rate]);  
227 - break;  
228 - case 5:  
229 - //周5降30-40%  
230 - $rate = rand(30, 40) * 10;  
231 - $res = $this->get_rand([1000-$rate, $rate]);  
232 - break;  
233 case 6: 213 case 6:
234 - //周6降60-70%  
235 - $rate = rand(60, 70) * 10; 214 + //周日降20-30%
  215 + $rate = rand(20, 30) * 10;
236 $res = $this->get_rand([1000-$rate, $rate]); 216 $res = $this->get_rand([1000-$rate, $rate]);
237 break; 217 break;
238 default: 218 default:
  219 + //元旦圣诞下降30-50%
  220 + if(in_array($date, ['01-01', '12-25'])){
  221 + $rate = rand(30, 50) * 10;
  222 + $res = $this->get_rand([1000-$rate, $rate]);
  223 + break;
  224 + }
239 $res = 0; 225 $res = 0;
240 } 226 }
241 //不访问 227 //不访问
@@ -294,6 +280,9 @@ class WebTrafficSpecial extends Command @@ -294,6 +280,9 @@ class WebTrafficSpecial extends Command
294 * 非俄语站的引流的项目 280 * 非俄语站的引流的项目
295 */ 281 */
296 protected function getProjectList($page){ 282 protected function getProjectList($page){
  283 + //设置了特殊引流的项目
  284 + $projects = WebTrafficConfig::where('add_num', '>', 0)->pluck('add_num', 'project_id')->toArray();
  285 +
297 $ru_lang_id = WebLanguage::getIdByLang('ru'); 286 $ru_lang_id = WebLanguage::getIdByLang('ru');
298 287
299 //推广项目 288 //推广项目
@@ -305,7 +294,7 @@ class WebTrafficSpecial extends Command @@ -305,7 +294,7 @@ class WebTrafficSpecial extends Command
305 ->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR]) 294 ->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
306 ->where('gl_project.is_upgrade', 0) //非升级项目 295 ->where('gl_project.is_upgrade', 0) //非升级项目
307 ->where('gl_project.main_lang_id', '<>', $ru_lang_id) //非俄语站 296 ->where('gl_project.main_lang_id', '<>', $ru_lang_id) //非俄语站
308 - ->whereIn('gl_project.id', array_keys($this->projects)) 297 + ->whereIn('gl_project.id', array_keys($projects))
309 ->select(['pdo.project_id','gl_project.main_lang_id','gl_project.id'])->forPage($page, 500)->get(); 298 ->select(['pdo.project_id','gl_project.main_lang_id','gl_project.id'])->forPage($page, 500)->get();
310 //其他地方在引流的域名 299 //其他地方在引流的域名
311 // $other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray(); 300 // $other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
@@ -317,7 +306,7 @@ class WebTrafficSpecial extends Command @@ -317,7 +306,7 @@ class WebTrafficSpecial extends Command
317 if(Cache::get('traffic_special_' . $project['project_id'])){ 306 if(Cache::get('traffic_special_' . $project['project_id'])){
318 continue; 307 continue;
319 }else{ 308 }else{
320 - $ttl = 24 * 60 * 60 / $this->projects[$project['project_id']]; 309 + $ttl = 24 * 60 * 60 / ($projects[$project['project_id']] / ($this->sjjg[0] / ($this->sjjg[0] + $this->sjjg[1])));
321 Cache::put('traffic_special_' . $project['project_id'], 1, $ttl); 310 Cache::put('traffic_special_' . $project['project_id'], 1, $ttl);
322 } 311 }
323 312
@@ -371,7 +360,7 @@ class WebTrafficSpecial extends Command @@ -371,7 +360,7 @@ class WebTrafficSpecial extends Command
371 /** 360 /**
372 * 获取地区IP 361 * 获取地区IP
373 */ 362 */
374 - protected function getIpAreas($num) 363 + protected function getIpAreas($project_ids)
375 { 364 {
376 //本地时间为7-23点的地区 365 //本地时间为7-23点的地区
377 $h = date('H'); 366 $h = date('H');
@@ -389,11 +378,26 @@ class WebTrafficSpecial extends Command @@ -389,11 +378,26 @@ class WebTrafficSpecial extends Command
389 $time_zones[$v['name']] = $v['diff']; 378 $time_zones[$v['name']] = $v['diff'];
390 } 379 }
391 } 380 }
392 - //根据地区随机取该地区的IP  
393 - $data = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)->inRandomOrder()->limit($num)->get();  
394 - $data = Arr::s2a(Arr::a2s($data));  
395 - foreach ($data as &$item){  
396 - $item['diff'] = $time_zones[$item['ip_area']]; 381 + $data = [];
  382 + foreach ($project_ids as $project_id){
  383 + //引流配置
  384 + $config = WebTrafficConfig::getCacheInfoByProjectId($project_id);
  385 + $main_countries = $config->main_countries ? explode(',',$config->main_countries) : [];
  386 + $filter_countries = $config->filter_countries ? explode(',',$config->filter_countries) : [];
  387 +
  388 + //根据地区随机取该地区的IP
  389 + $ipdata = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)
  390 + ->where(function ($query) use ($main_countries, $filter_countries){
  391 + if($main_countries){
  392 + $query->whereIn('ip_area', $main_countries);
  393 + }
  394 + if($filter_countries){
  395 + $query->whereNotIn('ip_area', $main_countries);
  396 + }
  397 + })->inRandomOrder()->first();
  398 + $ipdata = (array)$ipdata ?: [];
  399 + $ipdata['diff'] = $time_zones[$ipdata['ip_area']];
  400 + $data[] = $ipdata;
397 } 401 }
398 return $data; 402 return $data;
399 } 403 }
@@ -460,6 +464,9 @@ class WebTrafficSpecial extends Command @@ -460,6 +464,9 @@ class WebTrafficSpecial extends Command
460 $v = $project_urls['home'] . $v; 464 $v = $project_urls['home'] . $v;
461 } 465 }
462 } 466 }
  467 +
  468 + Log::channel('traffic')->info('project_id:访问深度' . $res_sdzb, $url);
  469 +
463 return array_unique(array_filter($url)); 470 return array_unique(array_filter($url));
464 } 471 }
465 472