作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate

... ... @@ -23,7 +23,7 @@ class UpgradeCount extends Command
*
* @var string
*/
protected $signature = 'upgrade_count';
protected $signature = 'upgrade_counts';
/**
* The console command description.
... ... @@ -34,7 +34,7 @@ class UpgradeCount extends Command
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0,'id'=>['<=',550]]);
$list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]);
foreach ($list as $v) {
echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
... ...
... ... @@ -55,6 +55,9 @@ class UpgradeProjectCount extends Command
$arr = [];
foreach ($list as $k=>$v){
$v = (array)$v;
if($v['updated_date'] == date('Y-m-d')){
continue;
}
echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL;
$count = new Count();
$arr['project_id'] = $project_id;
... ...
... ... @@ -27,7 +27,7 @@ class UpgradeCount extends Command
*
* @var string
*/
protected $signature = 'upgrade_month_count';
protected $signature = 'upgrade_month_counts';
/**
* The console command description.
... ... @@ -38,7 +38,7 @@ class UpgradeCount extends Command
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0,'id'=>['<=',456]]);
$list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]);
foreach ($list as $v) {
$oldModel = new UpdateOldInfo();
$info = $oldModel->read(['project_id' => $v['id']]);
... ...
... ... @@ -65,6 +65,9 @@ class UpgradeProjectCount extends Command
->groupBy('month')->get()->toArray();
foreach ($list as $k=>$v){
$v = (array)$v;
if($v['month'] == date('Y-m')){
continue;
}
$monthCountModel = new MonthCount();
$info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
// 获取当月开始时间
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Console\Commands\Test;
use App\Helper\Arr;
use App\Models\Collect\CollectTask;
use App\Models\Com\Notify;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateVisit;
use App\Models\Devops\ServerConfig;
... ... @@ -33,28 +34,17 @@ class Temp extends Command
*/
protected $description = '临时脚本';
public function handle()
{
$domain_model = new DomainInfo();
$server_model = new ServerConfig();
$notify_model = new Notify();
$project_model = new Project();
$domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc');
$domain_list = $domain_model->list(['amp_status' => 1]);
foreach ($domain_list as $info) {
$this->output('domain:' . $info['domain'] . ',开始');
$project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');
if ($project_info === false) {
$this->output('获取项目数据失败');
continue;
}
$server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
if ($server_info === false) {
$this->output('获取服务器数据失败');
continue;
}
if ($info['project_id'] > 0) {
$notify_info = $notify_model->read(['project_id' => $info['project_id'], 'type' => 3]);
if (!$notify_info) {
$domain_array = parse_url($info['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
... ... @@ -65,42 +55,87 @@ class Temp extends Command
$host_array[0] = 'm';
}
$amp_domain = implode('.', $host_array);
if (!$this->check_cname($amp_domain, $server_info)) {
$this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');
continue;
}
$api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
$api_param = [
'domain' => $info['domain'],
'private_key' => '',
'cert' => ''
];
try {
$rs = HttpUtils::get($api_url, $api_param);
$rs = json_decode($rs, true);
if (isset($rs['status']) && $rs['status'] == 200) {
$this->output('创建AMP站点成功');
} else {
$this->output($rs['message'] ?? '');
continue;
}
} catch (\Exception | GuzzleException $e) {
errorLog('创建AMP站点', $api_param, $e);
$this->output('创建AMP站点失败');
continue;
}
$data = [
'amp_status' => 1,
'amp_type' => 1,
];
$domain_model->edit($data, ['id' => $info['id']]);
}
echo '成功' . PHP_EOL;
}
$project_info = $project_model->read(['id' => $info['project_id']]);
$notify_model->add([
'project_id' => $info['project_id'],
'type' => 3,
'data' => json_encode(['domain' => $amp_domain, 'url' => [], 'language' => []]),
'server_id' => $project_info['serve_id'],
]);
}
}
}
}
// public function handle()
// {
// $domain_model = new DomainInfo();
// $server_model = new ServerConfig();
// $project_model = new Project();
//
// $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc');
// foreach ($domain_list as $info) {
// $this->output('domain:' . $info['domain'] . ',开始');
//
// $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');
// if ($project_info === false) {
// $this->output('获取项目数据失败');
// continue;
// }
//
// $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
// if ($server_info === false) {
// $this->output('获取服务器数据失败');
// continue;
// }
//
// $domain_array = parse_url($info['domain']);
// $host = $domain_array['host'] ?? $domain_array['path'];
// $host_array = explode('.', $host);
// if (count($host_array) <= 2) {
// array_unshift($host_array, 'm');
// } else {
// $host_array[0] = 'm';
// }
// $amp_domain = implode('.', $host_array);
// if (!$this->check_cname($amp_domain, $server_info)) {
// $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');
// continue;
// }
//
// $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
// $api_param = [
// 'domain' => $info['domain'],
// 'private_key' => '',
// 'cert' => ''
// ];
//
// try {
// $rs = HttpUtils::get($api_url, $api_param);
// $rs = json_decode($rs, true);
// if (isset($rs['status']) && $rs['status'] == 200) {
// $this->output('创建AMP站点成功');
// } else {
// $this->output($rs['message'] ?? '');
// continue;
// }
// } catch (\Exception | GuzzleException $e) {
// errorLog('创建AMP站点', $api_param, $e);
// $this->output('创建AMP站点失败');
// continue;
// }
//
// $data = [
// 'amp_status' => 1,
// 'amp_type' => 1,
// ];
// $domain_model->edit($data, ['id' => $info['id']]);
// }
//
// echo '成功' . PHP_EOL;
// }
public function check_cname($domain, $server_info)
{
... ...
... ... @@ -195,7 +195,8 @@ class ProjectUpdate extends Command
$custom_types = $data['data']['customposttypes'] ?? '';
$model = new WebSettingReceiving();
if ($phones) {
$has_phone = $model->read(['type' => 2]);
if (!$has_phone && $phones) {
$phone_arr = explode(',', $phones);
foreach ($phone_arr as $v_phone) {
if ($v_phone) {
... ... @@ -215,7 +216,8 @@ class ProjectUpdate extends Command
}
}
}
if ($emails) {
$has_email = $model->read(['type' => 1]);
if (!$has_email && $emails) {
$email_arr = explode(',', $emails);
foreach ($email_arr as $v_email) {
if ($v_email) {
... ...
... ... @@ -152,8 +152,6 @@ class UpdateSeoTdk extends Command
try {
$this->project = ProjectServer::useProject($project_id);
$this->seo_tdk($project_id, $task->id);
//TODO::通知C端更新所有界面
$this->sendNotify($project_id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
... ... @@ -163,7 +161,7 @@ class UpdateSeoTdk extends Command
echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL;
}
}
public function sendNotify($project_id)
public function sendNotify($project_id, $route)
{
//获取当前项目的域名
$domainModel = new DomainInfo();
... ... @@ -180,7 +178,7 @@ class UpdateSeoTdk extends Command
$param = [
'project_id' => $project_id,
'type' => 1,
'route' => 1,
'route' => $route,
'url' => [],
'language'=> [],
];
... ... @@ -189,7 +187,7 @@ class UpdateSeoTdk extends Command
}
public function seo_tdk($project_id, $task_id)
{
$notify_master = $notify_keyword = false;
//更新统计
$update = [];
$ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray();
... ... @@ -329,10 +327,19 @@ class UpdateSeoTdk extends Command
$data[$json_field] = json_encode($data[$json_field]);
}
DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data);
if($table == 'gl_product_keyword'){
$notify_keyword = true;
}else{
$notify_master = true;
}
}
}
}
ProjectUpdateTdk::finish($task_id, $update);
//通知C端更新界面
$notify_master && $this->sendNotify($project_id, 1); //通知主站更新
$notify_keyword && $this->sendNotify($project_id, 4); //通知聚合页更新
}
public function getPrompt($project_id, $prompt, $table, $data){
... ...
... ... @@ -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;
}
//不访问
... ... @@ -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'];
}
}
$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
$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']];
$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));
}
... ...
... ... @@ -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;
... ... @@ -229,35 +230,34 @@ class WebTrafficRussia 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;
}
//不访问
... ... @@ -404,7 +404,7 @@ class WebTrafficRussia extends Command
/**
* 获取地区IP
*/
protected function getIpAreas($num)
protected function getIpAreas($project_ids)
{
//本地时间为7-23点的地区
$h = date('H');
... ... @@ -431,11 +431,31 @@ class WebTrafficRussia extends Command
}
$data = [];
for ($i=0;$i<$num;$i++){
//ip国家占比
$ip_area = $this->get_rand($country_ratio);
foreach ($project_ids as $project_id) {
$project_country = $country_ratio;
//引流配置
$config = WebTrafficConfig::getCacheInfoByProjectId($project_id);
$main_countries = $config->main_countries ? explode(',', $config->main_countries) : [];
$filter_countries = $config->filter_countries ? explode(',', $config->filter_countries) : [];
//设置了主推的
if($main_countries){
foreach ($project_country as $k => $v){
if(!in_array($k, $main_countries)){
unset($project_country[$k]);
}
}
}
//设置了不推广
if($filter_countries){
foreach ($project_country as $k => $v){
if(in_array($k, $filter_countries)){
unset($project_country[$k]);
}
}
}
$ip_area = $this->get_rand($project_country);
$res = DB::table('gl_xunpan_ipdata')->where('ip_area', $ip_area)->inRandomOrder()->first();
$res = (array)$res;
$res = (array)$res ?: [];
$res['diff'] = $time_zones[$res['ip_area']];
$data[] = $res;
}
... ... @@ -504,6 +524,9 @@ class WebTrafficRussia extends Command
$v = $project_urls['home'] . $v;
}
}
Log::channel('traffic')->info('project_id:访问深度' . $res_sdzb, $url);
return array_unique(array_filter($url));
}
... ...
... ... @@ -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;
... ... @@ -52,9 +53,6 @@ class WebTrafficRussiaSpecial extends Command
parent::__construct();
}
protected $projects = [
969 => 60,
];
/**
* 国家概率
... ... @@ -232,35 +230,34 @@ class WebTrafficRussiaSpecial 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;
}
//不访问
... ... @@ -319,6 +316,9 @@ class WebTrafficRussiaSpecial extends Command
* 俄语站引流的项目
*/
protected function getProjectList($page){
//设置了特殊引流的项目
$projects = WebTrafficConfig::where('add_num', '>', 0)->pluck('add_num', 'project_id')->toArray();
$ru_lang_id = WebLanguage::getIdByLang('ru');
//推广项目
... ... @@ -330,7 +330,7 @@ class WebTrafficRussiaSpecial 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();
... ... @@ -342,7 +342,7 @@ class WebTrafficRussiaSpecial extends Command
if(Cache::get('web_traffic_russia_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('web_traffic_russia_special_' . $project['project_id'], 1, $ttl);
}
... ... @@ -396,7 +396,7 @@ class WebTrafficRussiaSpecial extends Command
/**
* 获取地区IP
*/
protected function getIpAreas($num)
protected function getIpAreas($project_ids)
{
//本地时间为7-23点的地区
$h = date('H');
... ... @@ -423,11 +423,31 @@ class WebTrafficRussiaSpecial extends Command
}
$data = [];
for ($i=0;$i<$num;$i++){
//ip国家占比
$ip_area = $this->get_rand($country_ratio);
foreach ($project_ids as $project_id) {
$project_country = $country_ratio;
//引流配置
$config = WebTrafficConfig::getCacheInfoByProjectId($project_id);
$main_countries = $config->main_countries ? explode(',', $config->main_countries) : [];
$filter_countries = $config->filter_countries ? explode(',', $config->filter_countries) : [];
//设置了主推的
if($main_countries){
foreach ($project_country as $k => $v){
if(!in_array($k, $main_countries)){
unset($project_country[$k]);
}
}
}
//设置了不推广
if($filter_countries){
foreach ($project_country as $k => $v){
if(in_array($k, $filter_countries)){
unset($project_country[$k]);
}
}
}
$ip_area = $this->get_rand($project_country);
$res = DB::table('gl_xunpan_ipdata')->where('ip_area', $ip_area)->inRandomOrder()->first();
$res = (array)$res;
$res = (array)$res ?: [];
$res['diff'] = $time_zones[$res['ip_area']];
$data[] = $res;
}
... ... @@ -496,6 +516,9 @@ class WebTrafficRussiaSpecial extends Command
$v = $project_urls['home'] . $v;
}
}
Log::channel('traffic')->info('project_id:访问深度' . $res_sdzb, $url);
return array_unique(array_filter($url));
}
... ...
... ... @@ -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'];
}
}
$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
$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']];
$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));
}
... ...
... ... @@ -34,7 +34,7 @@ class NewsController extends BaseController
$lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
if(!empty($lists)){
$lists = $lists->toArray();
// //获取当前项目的所有分类
//获取当前项目的所有分类
$data = $this->getCategoryList();
//获取当前用户选择的模版
$template_id = $this->getTemplateId(BTemplate::SOURCE_NEWS,BTemplate::IS_DETAIL);//获取模版id
... ...
... ... @@ -647,7 +647,7 @@ class BTemplateLogic extends BaseLogic
* @time :2023/8/23 11:16
*/
public function setOperationRecords($html,$source,$source_id,$template_id,$is_custom,$type = 0){
if($source != BTemplate::SOURCE_HOME){
if($is_custom != BTemplate::IS_NO_CUSTOM){
return true;
}
$data = [
... ...
... ... @@ -167,9 +167,14 @@ class NewsLogic extends BaseLogic
DB::beginTransaction();
try {
foreach ($this->param['id'] as $id) {
$info = $this->model->read(['id'=>$id],['id','status']);
if($info['status'] != 2){
$this->model->edit(['status'=>2],['id'=>$id]);
}else{
$this->delRoute($id);
$this->model->del(['id' => $id]);
}
}
DB::commit();
} catch (Exception $e) {
DB::rollBack();
... ...