mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\User;
|
|
|
|
class UserService
|
|
{
|
|
public function isAvailable(User $user)
|
|
{
|
|
if ($user->enable && $user->transfer_enable && ($user->expired_at > time() || $user->expired_at == 0)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getAvailableUsers()
|
|
{
|
|
return User::whereRaw('u + d < transfer_enable')
|
|
->where(function ($query) {
|
|
$query->where('expired_at', '>=', time())
|
|
->orWhere('expired_at', 0);
|
|
})
|
|
->where('enable', 1)
|
|
->select([
|
|
'id',
|
|
'email',
|
|
't',
|
|
'u',
|
|
'd',
|
|
'transfer_enable',
|
|
'enable',
|
|
'v2ray_uuid',
|
|
'v2ray_alter_id',
|
|
'v2ray_level'
|
|
])
|
|
->get();
|
|
}
|
|
|
|
public function getUnAvailbaleUsers()
|
|
{
|
|
return User::where(function ($query) {
|
|
$query->where('expired_at', '<', time())
|
|
->orWhere('expired_at', 0);
|
|
})
|
|
->where(function ($query) {
|
|
$query->where('plan_id', NULL)
|
|
->orWhere('transfer_enable', 0);
|
|
})
|
|
->get();
|
|
}
|
|
|
|
public function getUsersByIds($ids)
|
|
{
|
|
return User::whereIn('id', $ids)->get();
|
|
}
|
|
|
|
public function getAllUsers()
|
|
{
|
|
return User::all();
|
|
}
|
|
}
|