v2board/app/Services/UserService.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2020-02-28 01:12:55 +08:00
<?php
namespace App\Services;
use App\Models\User;
class UserService
{
2020-02-28 17:16:05 +08:00
public function isAvailable(User $user)
{
2020-03-02 20:29:17 +08:00
if (!$user->banned && $user->transfer_enable && ($user->expired_at > time() || $user->expired_at === NULL)) {
2020-02-28 17:16:05 +08:00
return true;
}
return false;
}
2020-02-28 01:12:55 +08:00
2020-02-28 17:16:05 +08:00
public function getAvailableUsers()
2020-02-28 01:12:55 +08:00
{
2020-02-28 17:16:05 +08:00
return User::whereRaw('u + d < transfer_enable')
->where(function ($query) {
$query->where('expired_at', '>=', time())
2020-03-01 23:29:49 +08:00
->orWhere('expired_at', NULL);
2020-02-28 17:16:05 +08:00
})
2020-03-02 20:29:17 +08:00
->where('banned', 0)
2020-02-28 17:16:05 +08:00
->get();
2020-02-28 01:12:55 +08:00
}
2020-02-28 17:16:05 +08:00
public function getUnAvailbaleUsers()
2020-02-28 01:12:55 +08:00
{
2020-02-28 17:16:05 +08:00
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();
2020-02-28 01:12:55 +08:00
}
}