mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-11 15:10:54 +00:00
56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Node;
|
|
use App\Models\User;
|
|
use App\Notifications\NodeDailyReport;
|
|
use Illuminate\Console\Command;
|
|
use Log;
|
|
use Notification;
|
|
|
|
class DailyNodeReport extends Command
|
|
{
|
|
protected $signature = 'dailyNodeReport';
|
|
protected $description = '自动报告节点昨日使用情况';
|
|
|
|
public function handle()
|
|
{
|
|
$jobTime = microtime(true);
|
|
|
|
if (sysConfig('node_daily_notification')) {
|
|
$nodeList = Node::whereStatus(1)->with('dailyDataFlows')->get();
|
|
if ($nodeList->isNotEmpty()) {
|
|
$data = [];
|
|
$upload = 0;
|
|
$download = 0;
|
|
foreach ($nodeList as $node) {
|
|
$log = $node->dailyDataFlows()->whereDate('created_at', date('Y-m-d', strtotime('-1 days')))->first();
|
|
$data[] = [
|
|
'name' => $node->name,
|
|
'upload' => flowAutoShow($log->u ?? 0),
|
|
'download' => flowAutoShow($log->d ?? 0),
|
|
'total' => $log->traffic ?? '',
|
|
];
|
|
$upload += $log->u ?? 0;
|
|
$download += $log->d ?? 0;
|
|
}
|
|
if ($data) {
|
|
$data[] = [
|
|
'name' => trans('notification.node.total'),
|
|
'total' => flowAutoShow($upload + $download),
|
|
'upload' => flowAutoShow($upload),
|
|
'download' => flowAutoShow($download),
|
|
];
|
|
|
|
Notification::send(User::role('Super Admin')->get(), new NodeDailyReport($data));
|
|
}
|
|
}
|
|
}
|
|
|
|
$jobTime = round((microtime(true) - $jobTime), 4);
|
|
|
|
Log::info('---【'.$this->description.'】完成---,耗时'.$jobTime.'秒');
|
|
}
|
|
}
|