Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate
正在显示
14 个修改的文件
包含
307 行增加
和
180 行删除
| @@ -23,7 +23,7 @@ class UpgradeCount extends Command | @@ -23,7 +23,7 @@ class UpgradeCount extends Command | ||
| 23 | * | 23 | * |
| 24 | * @var string | 24 | * @var string |
| 25 | */ | 25 | */ |
| 26 | - protected $signature = 'upgrade_count'; | 26 | + protected $signature = 'upgrade_counts'; |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | * The console command description. | 29 | * The console command description. |
| @@ -34,7 +34,7 @@ class UpgradeCount extends Command | @@ -34,7 +34,7 @@ class UpgradeCount extends Command | ||
| 34 | 34 | ||
| 35 | public function handle(){ | 35 | public function handle(){ |
| 36 | $projectModel = new Project(); | 36 | $projectModel = new Project(); |
| 37 | - $list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0,'id'=>['<=',550]]); | 37 | + $list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]); |
| 38 | foreach ($list as $v) { | 38 | foreach ($list as $v) { |
| 39 | echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL; | 39 | echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL; |
| 40 | ProjectServer::useProject($v['id']); | 40 | ProjectServer::useProject($v['id']); |
| @@ -55,6 +55,9 @@ class UpgradeProjectCount extends Command | @@ -55,6 +55,9 @@ class UpgradeProjectCount extends Command | ||
| 55 | $arr = []; | 55 | $arr = []; |
| 56 | foreach ($list as $k=>$v){ | 56 | foreach ($list as $k=>$v){ |
| 57 | $v = (array)$v; | 57 | $v = (array)$v; |
| 58 | + if($v['updated_date'] == date('Y-m-d')){ | ||
| 59 | + continue; | ||
| 60 | + } | ||
| 58 | echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL; | 61 | echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL; |
| 59 | $count = new Count(); | 62 | $count = new Count(); |
| 60 | $arr['project_id'] = $project_id; | 63 | $arr['project_id'] = $project_id; |
| @@ -27,7 +27,7 @@ class UpgradeCount extends Command | @@ -27,7 +27,7 @@ class UpgradeCount extends Command | ||
| 27 | * | 27 | * |
| 28 | * @var string | 28 | * @var string |
| 29 | */ | 29 | */ |
| 30 | - protected $signature = 'upgrade_month_count'; | 30 | + protected $signature = 'upgrade_month_counts'; |
| 31 | 31 | ||
| 32 | /** | 32 | /** |
| 33 | * The console command description. | 33 | * The console command description. |
| @@ -38,7 +38,7 @@ class UpgradeCount extends Command | @@ -38,7 +38,7 @@ class UpgradeCount extends Command | ||
| 38 | 38 | ||
| 39 | public function handle(){ | 39 | public function handle(){ |
| 40 | $projectModel = new Project(); | 40 | $projectModel = new Project(); |
| 41 | - $list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0,'id'=>['<=',456]]); | 41 | + $list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]); |
| 42 | foreach ($list as $v) { | 42 | foreach ($list as $v) { |
| 43 | $oldModel = new UpdateOldInfo(); | 43 | $oldModel = new UpdateOldInfo(); |
| 44 | $info = $oldModel->read(['project_id' => $v['id']]); | 44 | $info = $oldModel->read(['project_id' => $v['id']]); |
| @@ -65,6 +65,9 @@ class UpgradeProjectCount extends Command | @@ -65,6 +65,9 @@ class UpgradeProjectCount extends Command | ||
| 65 | ->groupBy('month')->get()->toArray(); | 65 | ->groupBy('month')->get()->toArray(); |
| 66 | foreach ($list as $k=>$v){ | 66 | foreach ($list as $k=>$v){ |
| 67 | $v = (array)$v; | 67 | $v = (array)$v; |
| 68 | + if($v['month'] == date('Y-m')){ | ||
| 69 | + continue; | ||
| 70 | + } | ||
| 68 | $monthCountModel = new MonthCount(); | 71 | $monthCountModel = new MonthCount(); |
| 69 | $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]); | 72 | $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]); |
| 70 | // 获取当月开始时间 | 73 | // 获取当月开始时间 |
| @@ -4,6 +4,7 @@ namespace App\Console\Commands\Test; | @@ -4,6 +4,7 @@ namespace App\Console\Commands\Test; | ||
| 4 | 4 | ||
| 5 | use App\Helper\Arr; | 5 | use App\Helper\Arr; |
| 6 | use App\Models\Collect\CollectTask; | 6 | use App\Models\Collect\CollectTask; |
| 7 | +use App\Models\Com\Notify; | ||
| 7 | use App\Models\Com\UpdateLog; | 8 | use App\Models\Com\UpdateLog; |
| 8 | use App\Models\Com\UpdateVisit; | 9 | use App\Models\Com\UpdateVisit; |
| 9 | use App\Models\Devops\ServerConfig; | 10 | use App\Models\Devops\ServerConfig; |
| @@ -33,75 +34,109 @@ class Temp extends Command | @@ -33,75 +34,109 @@ class Temp extends Command | ||
| 33 | */ | 34 | */ |
| 34 | protected $description = '临时脚本'; | 35 | protected $description = '临时脚本'; |
| 35 | 36 | ||
| 36 | - | ||
| 37 | public function handle() | 37 | public function handle() |
| 38 | { | 38 | { |
| 39 | $domain_model = new DomainInfo(); | 39 | $domain_model = new DomainInfo(); |
| 40 | - $server_model = new ServerConfig(); | 40 | + $notify_model = new Notify(); |
| 41 | $project_model = new Project(); | 41 | $project_model = new Project(); |
| 42 | 42 | ||
| 43 | - $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc'); | 43 | + $domain_list = $domain_model->list(['amp_status' => 1]); |
| 44 | foreach ($domain_list as $info) { | 44 | foreach ($domain_list as $info) { |
| 45 | - $this->output('domain:' . $info['domain'] . ',开始'); | ||
| 46 | - | ||
| 47 | - $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id'); | ||
| 48 | - if ($project_info === false) { | ||
| 49 | - $this->output('获取项目数据失败'); | ||
| 50 | - continue; | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']); | ||
| 54 | - if ($server_info === false) { | ||
| 55 | - $this->output('获取服务器数据失败'); | ||
| 56 | - continue; | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - $domain_array = parse_url($info['domain']); | ||
| 60 | - $host = $domain_array['host'] ?? $domain_array['path']; | ||
| 61 | - $host_array = explode('.', $host); | ||
| 62 | - if (count($host_array) <= 2) { | ||
| 63 | - array_unshift($host_array, 'm'); | ||
| 64 | - } else { | ||
| 65 | - $host_array[0] = 'm'; | ||
| 66 | - } | ||
| 67 | - $amp_domain = implode('.', $host_array); | ||
| 68 | - if (!$this->check_cname($amp_domain, $server_info)) { | ||
| 69 | - $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器'); | ||
| 70 | - continue; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp'; | ||
| 74 | - $api_param = [ | ||
| 75 | - 'domain' => $info['domain'], | ||
| 76 | - 'private_key' => '', | ||
| 77 | - 'cert' => '' | ||
| 78 | - ]; | ||
| 79 | - | ||
| 80 | - try { | ||
| 81 | - $rs = HttpUtils::get($api_url, $api_param); | ||
| 82 | - $rs = json_decode($rs, true); | ||
| 83 | - if (isset($rs['status']) && $rs['status'] == 200) { | ||
| 84 | - $this->output('创建AMP站点成功'); | ||
| 85 | - } else { | ||
| 86 | - $this->output($rs['message'] ?? ''); | ||
| 87 | - continue; | 45 | + if ($info['project_id'] > 0) { |
| 46 | + $notify_info = $notify_model->read(['project_id' => $info['project_id'], 'type' => 3]); | ||
| 47 | + if (!$notify_info) { | ||
| 48 | + | ||
| 49 | + $domain_array = parse_url($info['domain']); | ||
| 50 | + $host = $domain_array['host'] ?? $domain_array['path']; | ||
| 51 | + $host_array = explode('.', $host); | ||
| 52 | + if (count($host_array) <= 2) { | ||
| 53 | + array_unshift($host_array, 'm'); | ||
| 54 | + } else { | ||
| 55 | + $host_array[0] = 'm'; | ||
| 56 | + } | ||
| 57 | + $amp_domain = implode('.', $host_array); | ||
| 58 | + | ||
| 59 | + $project_info = $project_model->read(['id' => $info['project_id']]); | ||
| 60 | + | ||
| 61 | + $notify_model->add([ | ||
| 62 | + 'project_id' => $info['project_id'], | ||
| 63 | + 'type' => 3, | ||
| 64 | + 'data' => json_encode(['domain' => $amp_domain, 'url' => [], 'language' => []]), | ||
| 65 | + 'server_id' => $project_info['serve_id'], | ||
| 66 | + ]); | ||
| 88 | } | 67 | } |
| 89 | - } catch (\Exception | GuzzleException $e) { | ||
| 90 | - errorLog('创建AMP站点', $api_param, $e); | ||
| 91 | - $this->output('创建AMP站点失败'); | ||
| 92 | - continue; | ||
| 93 | } | 68 | } |
| 94 | - | ||
| 95 | - $data = [ | ||
| 96 | - 'amp_status' => 1, | ||
| 97 | - 'amp_type' => 1, | ||
| 98 | - ]; | ||
| 99 | - $domain_model->edit($data, ['id' => $info['id']]); | ||
| 100 | } | 69 | } |
| 101 | - | ||
| 102 | - echo '成功' . PHP_EOL; | ||
| 103 | } | 70 | } |
| 104 | 71 | ||
| 72 | +// public function handle() | ||
| 73 | +// { | ||
| 74 | +// $domain_model = new DomainInfo(); | ||
| 75 | +// $server_model = new ServerConfig(); | ||
| 76 | +// $project_model = new Project(); | ||
| 77 | +// | ||
| 78 | +// $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc'); | ||
| 79 | +// foreach ($domain_list as $info) { | ||
| 80 | +// $this->output('domain:' . $info['domain'] . ',开始'); | ||
| 81 | +// | ||
| 82 | +// $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id'); | ||
| 83 | +// if ($project_info === false) { | ||
| 84 | +// $this->output('获取项目数据失败'); | ||
| 85 | +// continue; | ||
| 86 | +// } | ||
| 87 | +// | ||
| 88 | +// $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']); | ||
| 89 | +// if ($server_info === false) { | ||
| 90 | +// $this->output('获取服务器数据失败'); | ||
| 91 | +// continue; | ||
| 92 | +// } | ||
| 93 | +// | ||
| 94 | +// $domain_array = parse_url($info['domain']); | ||
| 95 | +// $host = $domain_array['host'] ?? $domain_array['path']; | ||
| 96 | +// $host_array = explode('.', $host); | ||
| 97 | +// if (count($host_array) <= 2) { | ||
| 98 | +// array_unshift($host_array, 'm'); | ||
| 99 | +// } else { | ||
| 100 | +// $host_array[0] = 'm'; | ||
| 101 | +// } | ||
| 102 | +// $amp_domain = implode('.', $host_array); | ||
| 103 | +// if (!$this->check_cname($amp_domain, $server_info)) { | ||
| 104 | +// $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器'); | ||
| 105 | +// continue; | ||
| 106 | +// } | ||
| 107 | +// | ||
| 108 | +// $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp'; | ||
| 109 | +// $api_param = [ | ||
| 110 | +// 'domain' => $info['domain'], | ||
| 111 | +// 'private_key' => '', | ||
| 112 | +// 'cert' => '' | ||
| 113 | +// ]; | ||
| 114 | +// | ||
| 115 | +// try { | ||
| 116 | +// $rs = HttpUtils::get($api_url, $api_param); | ||
| 117 | +// $rs = json_decode($rs, true); | ||
| 118 | +// if (isset($rs['status']) && $rs['status'] == 200) { | ||
| 119 | +// $this->output('创建AMP站点成功'); | ||
| 120 | +// } else { | ||
| 121 | +// $this->output($rs['message'] ?? ''); | ||
| 122 | +// continue; | ||
| 123 | +// } | ||
| 124 | +// } catch (\Exception | GuzzleException $e) { | ||
| 125 | +// errorLog('创建AMP站点', $api_param, $e); | ||
| 126 | +// $this->output('创建AMP站点失败'); | ||
| 127 | +// continue; | ||
| 128 | +// } | ||
| 129 | +// | ||
| 130 | +// $data = [ | ||
| 131 | +// 'amp_status' => 1, | ||
| 132 | +// 'amp_type' => 1, | ||
| 133 | +// ]; | ||
| 134 | +// $domain_model->edit($data, ['id' => $info['id']]); | ||
| 135 | +// } | ||
| 136 | +// | ||
| 137 | +// echo '成功' . PHP_EOL; | ||
| 138 | +// } | ||
| 139 | + | ||
| 105 | public function check_cname($domain, $server_info) | 140 | public function check_cname($domain, $server_info) |
| 106 | { | 141 | { |
| 107 | $checkA = false; | 142 | $checkA = false; |
| @@ -195,7 +195,8 @@ class ProjectUpdate extends Command | @@ -195,7 +195,8 @@ class ProjectUpdate extends Command | ||
| 195 | $custom_types = $data['data']['customposttypes'] ?? ''; | 195 | $custom_types = $data['data']['customposttypes'] ?? ''; |
| 196 | 196 | ||
| 197 | $model = new WebSettingReceiving(); | 197 | $model = new WebSettingReceiving(); |
| 198 | - if ($phones) { | 198 | + $has_phone = $model->read(['type' => 2]); |
| 199 | + if (!$has_phone && $phones) { | ||
| 199 | $phone_arr = explode(',', $phones); | 200 | $phone_arr = explode(',', $phones); |
| 200 | foreach ($phone_arr as $v_phone) { | 201 | foreach ($phone_arr as $v_phone) { |
| 201 | if ($v_phone) { | 202 | if ($v_phone) { |
| @@ -215,7 +216,8 @@ class ProjectUpdate extends Command | @@ -215,7 +216,8 @@ class ProjectUpdate extends Command | ||
| 215 | } | 216 | } |
| 216 | } | 217 | } |
| 217 | } | 218 | } |
| 218 | - if ($emails) { | 219 | + $has_email = $model->read(['type' => 1]); |
| 220 | + if (!$has_email && $emails) { | ||
| 219 | $email_arr = explode(',', $emails); | 221 | $email_arr = explode(',', $emails); |
| 220 | foreach ($email_arr as $v_email) { | 222 | foreach ($email_arr as $v_email) { |
| 221 | if ($v_email) { | 223 | if ($v_email) { |
| @@ -152,8 +152,6 @@ class UpdateSeoTdk extends Command | @@ -152,8 +152,6 @@ class UpdateSeoTdk extends Command | ||
| 152 | try { | 152 | try { |
| 153 | $this->project = ProjectServer::useProject($project_id); | 153 | $this->project = ProjectServer::useProject($project_id); |
| 154 | $this->seo_tdk($project_id, $task->id); | 154 | $this->seo_tdk($project_id, $task->id); |
| 155 | - //TODO::通知C端更新所有界面 | ||
| 156 | - $this->sendNotify($project_id); | ||
| 157 | DB::disconnect('custom_mysql'); | 155 | DB::disconnect('custom_mysql'); |
| 158 | }catch (\Exception $e){ | 156 | }catch (\Exception $e){ |
| 159 | echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL; | 157 | 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 | @@ -163,7 +161,7 @@ class UpdateSeoTdk extends Command | ||
| 163 | echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL; | 161 | echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL; |
| 164 | } | 162 | } |
| 165 | } | 163 | } |
| 166 | - public function sendNotify($project_id) | 164 | + public function sendNotify($project_id, $route) |
| 167 | { | 165 | { |
| 168 | //获取当前项目的域名 | 166 | //获取当前项目的域名 |
| 169 | $domainModel = new DomainInfo(); | 167 | $domainModel = new DomainInfo(); |
| @@ -180,7 +178,7 @@ class UpdateSeoTdk extends Command | @@ -180,7 +178,7 @@ class UpdateSeoTdk extends Command | ||
| 180 | $param = [ | 178 | $param = [ |
| 181 | 'project_id' => $project_id, | 179 | 'project_id' => $project_id, |
| 182 | 'type' => 1, | 180 | 'type' => 1, |
| 183 | - 'route' => 1, | 181 | + 'route' => $route, |
| 184 | 'url' => [], | 182 | 'url' => [], |
| 185 | 'language'=> [], | 183 | 'language'=> [], |
| 186 | ]; | 184 | ]; |
| @@ -189,7 +187,7 @@ class UpdateSeoTdk extends Command | @@ -189,7 +187,7 @@ class UpdateSeoTdk extends Command | ||
| 189 | } | 187 | } |
| 190 | public function seo_tdk($project_id, $task_id) | 188 | public function seo_tdk($project_id, $task_id) |
| 191 | { | 189 | { |
| 192 | - | 190 | + $notify_master = $notify_keyword = false; |
| 193 | //更新统计 | 191 | //更新统计 |
| 194 | $update = []; | 192 | $update = []; |
| 195 | $ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray(); | 193 | $ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray(); |
| @@ -329,10 +327,19 @@ class UpdateSeoTdk extends Command | @@ -329,10 +327,19 @@ class UpdateSeoTdk extends Command | ||
| 329 | $data[$json_field] = json_encode($data[$json_field]); | 327 | $data[$json_field] = json_encode($data[$json_field]); |
| 330 | } | 328 | } |
| 331 | DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data); | 329 | DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data); |
| 330 | + if($table == 'gl_product_keyword'){ | ||
| 331 | + $notify_keyword = true; | ||
| 332 | + }else{ | ||
| 333 | + $notify_master = true; | ||
| 334 | + } | ||
| 332 | } | 335 | } |
| 333 | } | 336 | } |
| 334 | } | 337 | } |
| 335 | ProjectUpdateTdk::finish($task_id, $update); | 338 | ProjectUpdateTdk::finish($task_id, $update); |
| 339 | + | ||
| 340 | + //通知C端更新界面 | ||
| 341 | + $notify_master && $this->sendNotify($project_id, 1); //通知主站更新 | ||
| 342 | + $notify_keyword && $this->sendNotify($project_id, 4); //通知聚合页更新 | ||
| 336 | } | 343 | } |
| 337 | 344 | ||
| 338 | public function getPrompt($project_id, $prompt, $table, $data){ | 345 | public function getPrompt($project_id, $prompt, $table, $data){ |
| @@ -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 |
| @@ -34,7 +34,7 @@ class NewsController extends BaseController | @@ -34,7 +34,7 @@ class NewsController extends BaseController | ||
| 34 | $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page); | 34 | $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page); |
| 35 | if(!empty($lists)){ | 35 | if(!empty($lists)){ |
| 36 | $lists = $lists->toArray(); | 36 | $lists = $lists->toArray(); |
| 37 | -// //获取当前项目的所有分类 | 37 | + //获取当前项目的所有分类 |
| 38 | $data = $this->getCategoryList(); | 38 | $data = $this->getCategoryList(); |
| 39 | //获取当前用户选择的模版 | 39 | //获取当前用户选择的模版 |
| 40 | $template_id = $this->getTemplateId(BTemplate::SOURCE_NEWS,BTemplate::IS_DETAIL);//获取模版id | 40 | $template_id = $this->getTemplateId(BTemplate::SOURCE_NEWS,BTemplate::IS_DETAIL);//获取模版id |
| @@ -647,7 +647,7 @@ class BTemplateLogic extends BaseLogic | @@ -647,7 +647,7 @@ class BTemplateLogic extends BaseLogic | ||
| 647 | * @time :2023/8/23 11:16 | 647 | * @time :2023/8/23 11:16 |
| 648 | */ | 648 | */ |
| 649 | public function setOperationRecords($html,$source,$source_id,$template_id,$is_custom,$type = 0){ | 649 | public function setOperationRecords($html,$source,$source_id,$template_id,$is_custom,$type = 0){ |
| 650 | - if($source != BTemplate::SOURCE_HOME){ | 650 | + if($is_custom != BTemplate::IS_NO_CUSTOM){ |
| 651 | return true; | 651 | return true; |
| 652 | } | 652 | } |
| 653 | $data = [ | 653 | $data = [ |
| @@ -167,8 +167,13 @@ class NewsLogic extends BaseLogic | @@ -167,8 +167,13 @@ class NewsLogic extends BaseLogic | ||
| 167 | DB::beginTransaction(); | 167 | DB::beginTransaction(); |
| 168 | try { | 168 | try { |
| 169 | foreach ($this->param['id'] as $id) { | 169 | foreach ($this->param['id'] as $id) { |
| 170 | - $this->delRoute($id); | ||
| 171 | - $this->model->del(['id' => $id]); | 170 | + $info = $this->model->read(['id'=>$id],['id','status']); |
| 171 | + if($info['status'] != 2){ | ||
| 172 | + $this->model->edit(['status'=>2],['id'=>$id]); | ||
| 173 | + }else{ | ||
| 174 | + $this->delRoute($id); | ||
| 175 | + $this->model->del(['id' => $id]); | ||
| 176 | + } | ||
| 172 | } | 177 | } |
| 173 | DB::commit(); | 178 | DB::commit(); |
| 174 | } catch (Exception $e) { | 179 | } catch (Exception $e) { |
-
请 注册 或 登录 后发表评论