mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
fix mail send
This commit is contained in:
parent
dd924d95c6
commit
2217286d03
@ -3,24 +3,27 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\MailSend;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Jobs\SendEmail;
|
||||
|
||||
class MailController extends Controller
|
||||
{
|
||||
public function send(MailSend $request)
|
||||
{
|
||||
|
||||
$userService = new UserService();
|
||||
$users = [];
|
||||
switch ($request->input('type')) {
|
||||
case 1: $users = $this->getAllUser();
|
||||
case 1: $users = $userService->getAllUsers();
|
||||
break;
|
||||
case 2: $users = $this->getReceiver($request->input('receiver'));
|
||||
case 2: $users = $userService->getUsersByIds($request->input('receiver'));
|
||||
break;
|
||||
case 3: $users = $this->getSubscribeUser();
|
||||
// available users
|
||||
case 3: $users = $userService->getAvailableUsers();
|
||||
break;
|
||||
case 4: $users = $this->getExpireUser();
|
||||
// un available users
|
||||
case 4: $users = $userService->getUnAvailbaleUsers();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -41,27 +44,4 @@ class MailController extends Controller
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
private function getAllUser()
|
||||
{
|
||||
return User::all();
|
||||
}
|
||||
|
||||
private function getReceiver($receiver)
|
||||
{
|
||||
if (empty($receiver)) {
|
||||
abort(500, '收件人不能为空');
|
||||
}
|
||||
return User::whereIn('id', $receiver)->get();
|
||||
}
|
||||
|
||||
private function getSubscribeUser()
|
||||
{
|
||||
return User::where('expired_at', '=>', time())->get();
|
||||
}
|
||||
|
||||
private function getExpireUser()
|
||||
{
|
||||
return User::where('expired_at', '<', time())->get();
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ class ClientController extends Controller
|
||||
$user = $request->user;
|
||||
$server = [];
|
||||
// account not expired and is not banned.
|
||||
$userService = new UserService($user);
|
||||
if ($userService->isAvailable()) {
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$servers = Server::where('show', 1)
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
@ -18,8 +18,8 @@ class ServerController extends Controller
|
||||
{
|
||||
$user = User::find($request->session()->get('id'));
|
||||
$server = [];
|
||||
$userService = new UserService($user);
|
||||
if ($userService->isAvailable()) {
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$servers = Server::where('show', 1)
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
@ -6,18 +6,57 @@ use App\Models\User;
|
||||
|
||||
class UserService
|
||||
{
|
||||
public $user;
|
||||
|
||||
public function __construct(User $user)
|
||||
public function isAvailable(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function isAvailable()
|
||||
{
|
||||
if ($this->user->enable && $this->user->transfer_enable && ($this->user->expired_at > time() || $this->user->expired_at == 0)) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user