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