You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Malio/app/Services/Analytics.php

121 lines
2.8 KiB
PHTML

9 years ago
<?php
namespace App\Services;
use App\Models\User;
use App\Models\Node;
use App\Utils\Tools;
class Analytics
{
public function getTotalUser()
{
return User::count();
}
public function getCheckinUser()
{
return User::where('last_check_in_time', '>', 0)->count();
}
8 years ago
9 years ago
public function getTodayCheckinUser()
{
return User::where('last_check_in_time', '>', strtotime('today'))->count();
}
public function getTrafficUsage()
{
$total = User::sum('u') + User::sum('d');
return Tools::flowAutoShow($total);
}
8 years ago
9 years ago
public function getTodayTrafficUsage()
{
$total = User::sum('u') + User::sum('d') - User::sum('last_day_t');
return Tools::flowAutoShow($total);
}
8 years ago
9 years ago
public function getRawTodayTrafficUsage()
{
return User::sum('u') + User::sum('d') - User::sum('last_day_t');
9 years ago
}
8 years ago
9 years ago
public function getLastTrafficUsage()
{
$total = User::sum('last_day_t');
return Tools::flowAutoShow($total);
}
8 years ago
9 years ago
public function getRawLastTrafficUsage()
{
return User::sum('last_day_t');
9 years ago
}
8 years ago
9 years ago
public function getUnusedTrafficUsage()
{
$total = User::sum('transfer_enable') - User::sum('u') - User::sum('d');
return Tools::flowAutoShow($total);
}
8 years ago
9 years ago
public function getRawUnusedTrafficUsage()
{
return User::sum('transfer_enable') - User::sum('u') - User::sum('d');
9 years ago
}
8 years ago
9 years ago
public function getTotalTraffic()
{
$total = User::sum('transfer_enable');
return Tools::flowAutoShow($total);
}
8 years ago
9 years ago
public function getRawTotalTraffic()
{
return User::sum('transfer_enable');
9 years ago
}
public function getOnlineUser($time)
{
$time = time() - $time;
return User::where('t', '>', $time)->count();
}
8 years ago
9 years ago
public function getUnusedUser()
{
return User::where('t', '=', 0)->count();
}
public function getTotalNode()
{
return Node::count();
}
8 years ago
public function getTotalNodes()
9 years ago
{
return Node::where('node_heartbeat', '>', 0)->where(
static function ($query) {
8 years ago
$query->Where('sort', '=', 0)
->orWhere('sort', '=', 10)
->orWhere('sort', '=', 11)
->orWhere('sort', '=', 12)
->orWhere('sort', '=', 13);
}
)->count();
}
public function getAliveNodes()
9 years ago
{
return Node::where(
static function ($query) {
9 years ago
$query->Where('sort', '=', 0)
->orWhere('sort', '=', 10)
->orWhere('sort', '=', 11)
->orWhere('sort', '=', 12)
->orWhere('sort', '=', 13);
9 years ago
}
8 years ago
)->where('node_heartbeat', '>', time() - 90)->count();
9 years ago
}
}