mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-13 07:59:20 +00:00
1. 框架更新至5.8,并且其涉及代码进行修改; 2. 对支付的alipay组件针对php7.2/3进行修改; 3. 重构了节点信息获取逻辑;现在为实时请求; 4. 代码小细节和命名规范
60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Components\Helpers;
|
|
use App\Http\Models\User;
|
|
use App\Mail\userTrafficWarning;
|
|
use Illuminate\Console\Command;
|
|
use Log;
|
|
use Mail;
|
|
|
|
class UserTrafficAutoWarning extends Command
|
|
{
|
|
protected static $systemConfig;
|
|
protected $signature = 'userTrafficAutoWarning';
|
|
protected $description = '用户流量超过警告阈值自动发邮件提醒';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
self::$systemConfig = Helpers::systemConfig();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
$jobStartTime = microtime(TRUE);
|
|
|
|
// 用户流量超过警告阈值自动发邮件提醒
|
|
if(self::$systemConfig['traffic_warning']){
|
|
$this->userTrafficWarning();
|
|
}
|
|
|
|
$jobEndTime = microtime(TRUE);
|
|
$jobUsedTime = round(($jobEndTime-$jobStartTime), 4);
|
|
|
|
Log::info('---【'.$this->description.'】完成---,耗时'.$jobUsedTime.'秒');
|
|
}
|
|
|
|
// 用户流量超过警告阈值自动发邮件提醒
|
|
private function userTrafficWarning()
|
|
{
|
|
$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->where('transfer_enable', '>', 0)->get();
|
|
foreach($userList as $user){
|
|
// 用户名不是邮箱的跳过
|
|
if(FALSE === filter_var($user->username, FILTER_VALIDATE_EMAIL)){
|
|
continue;
|
|
}
|
|
|
|
$usedPercent = round(($user->d+$user->u)/$user->transfer_enable, 2)*100; // 已使用流量百分比
|
|
if($usedPercent >= self::$systemConfig['traffic_warning_percent']){
|
|
$title = '流量提醒';
|
|
$content = '流量已使用:'.$usedPercent.'%,请保持关注。';
|
|
|
|
$logId = Helpers::addEmailLog($user->username, $title, $content);
|
|
Mail::to($user->username)->send(new userTrafficWarning($logId, $usedPercent));
|
|
}
|
|
}
|
|
}
|
|
}
|