Files
ProxyPanel/app/Console/Commands/UserTrafficWarning.php
兔姬桑 c3dbcb19f4 使用whenFilled优化代码筛选 & 页面代码适量简化
针对管理页面中筛选行为使用whenFilled属性进行重写简化&规范化修正;
同时对页面搜索代码进行适量简化;
2021-03-16 13:13:42 -04:00

47 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\User;
use App\Notifications\DataExhaust;
use Illuminate\Console\Command;
use Log;
class UserTrafficWarning extends Command
{
protected $signature = 'userTrafficWarning';
protected $description = '用户流量超过警告阈值自动发邮件提醒';
public function handle()
{
$jobStartTime = microtime(true);
if (sysConfig('data_exhaust_notification')) {// 用户流量超过警告阈值提醒
$this->userTrafficWarning();
}
$jobEndTime = microtime(true);
$jobUsedTime = round(($jobEndTime - $jobStartTime), 4);
Log::info('---【'.$this->description.'】完成---,耗时'.$jobUsedTime.'秒');
}
private function userTrafficWarning()// 用户流量超过警告阈值提醒
{
$trafficWarningPercent = sysConfig('traffic_warning_percent');
User::activeUser()->where('transfer_enable', '>', 0)->chunk(config('tasks.chunk'), function ($users) use ($trafficWarningPercent) {
foreach ($users as $user) {
// 用户账号不是邮箱的跳过
if (filter_var($user->email, FILTER_VALIDATE_EMAIL) === false) {
continue;
}
$usedPercent = $user->used_traffic_percentage * 100; // 已使用流量百分比
if ($usedPercent >= $trafficWarningPercent) {
$user->notify(new DataExhaust($usedPercent));
}
}
});
}
}