|
...
|
...
|
@@ -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;
|
|
...
|
...
|
@@ -53,20 +54,6 @@ class WebTrafficSpecial extends Command |
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 要增加引流的项目及腰增加的数量
|
|
|
|
* key 要引流的ID
|
|
|
|
* value 每天要增加的流量
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $projects = [
|
|
|
|
509 => 30,
|
|
|
|
79 => 20,
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* google域名后缀
|
|
|
|
* @var string[]
|
|
...
|
...
|
@@ -207,35 +194,34 @@ class WebTrafficSpecial 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;
|
|
|
|
}
|
|
|
|
//不访问
|
|
...
|
...
|
@@ -294,6 +280,9 @@ class WebTrafficSpecial extends Command |
|
|
|
* 非俄语站的引流的项目
|
|
|
|
*/
|
|
|
|
protected function getProjectList($page){
|
|
|
|
//设置了特殊引流的项目
|
|
|
|
$projects = WebTrafficConfig::where('add_num', '>', 0)->pluck('add_num', 'project_id')->toArray();
|
|
|
|
|
|
|
|
$ru_lang_id = WebLanguage::getIdByLang('ru');
|
|
|
|
|
|
|
|
//推广项目
|
|
...
|
...
|
@@ -305,7 +294,7 @@ class WebTrafficSpecial extends Command |
|
|
|
->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
|
|
|
|
->where('gl_project.is_upgrade', 0) //非升级项目
|
|
|
|
->where('gl_project.main_lang_id', '<>', $ru_lang_id) //非俄语站
|
|
|
|
->whereIn('gl_project.id', array_keys($this->projects))
|
|
|
|
->whereIn('gl_project.id', array_keys($projects))
|
|
|
|
->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();
|
|
...
|
...
|
@@ -317,7 +306,7 @@ class WebTrafficSpecial extends Command |
|
|
|
if(Cache::get('traffic_special_' . $project['project_id'])){
|
|
|
|
continue;
|
|
|
|
}else{
|
|
|
|
$ttl = 24 * 60 * 60 / $this->projects[$project['project_id']];
|
|
|
|
$ttl = 24 * 60 * 60 / ($projects[$project['project_id']] / ($this->sjjg[0] / ($this->sjjg[0] + $this->sjjg[1])));
|
|
|
|
Cache::put('traffic_special_' . $project['project_id'], 1, $ttl);
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -371,7 +360,7 @@ class WebTrafficSpecial extends Command |
|
|
|
/**
|
|
|
|
* 获取地区IP
|
|
|
|
*/
|
|
|
|
protected function getIpAreas($num)
|
|
|
|
protected function getIpAreas($project_ids)
|
|
|
|
{
|
|
|
|
//本地时间为7-23点的地区
|
|
|
|
$h = date('H');
|
|
...
|
...
|
@@ -389,11 +378,26 @@ class WebTrafficSpecial 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 = $config->main_countries ? explode(',',$config->main_countries) : [];
|
|
|
|
$filter_countries = $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;
|
|
|
|
}
|
|
...
|
...
|
@@ -460,6 +464,9 @@ class WebTrafficSpecial extends Command |
|
|
|
$v = $project_urls['home'] . $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Log::channel('traffic')->info('project_id:访问深度' . $res_sdzb, $url);
|
|
|
|
|
|
|
|
return array_unique(array_filter($url));
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|