update mailsend,frontend

This commit is contained in:
Tokumeikoi 2020-02-15 17:24:00 +08:00
parent 2b8456fdf5
commit 43e7bb6c9f
6 changed files with 37 additions and 12 deletions

View File

@ -12,14 +12,16 @@ class MailController extends Controller
{
public function send(MailSend $request)
{
if ($request->input('type') == 2 && empty($request->input('receiver'))) {
abort(500, '收件人不能为空');
}
if ($request->input('receiver')) {
$users = User::whereIn('id', $request->input('receiver'))->get();
} else {
$users = User::all();
switch ($request->input('type')) {
case 1: $users = $this->getAllUser();
break;
case 2: $users = $this->getReceiver($request->input('receiver'));
break;
case 3: $users = $this->getSubscribeUser();
break;
case 4: $users = $this->getExpireUser();
break;
}
foreach ($users as $user) {
@ -39,4 +41,27 @@ 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();
}
}

View File

@ -14,7 +14,7 @@ class MailSend extends FormRequest
public function rules()
{
return [
'type' => 'required|in:1,2',
'type' => 'required|in:1,2,3,4',
'subject' => 'required',
'content' => 'required',
'receiver' => 'array'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long