2019-12-30 22:40:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Http\Requests\Admin\MailSend;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Jobs\SendEmail;
|
|
|
|
|
|
|
|
class MailController extends Controller
|
|
|
|
{
|
2020-01-11 13:36:52 +08:00
|
|
|
public function send(MailSend $request)
|
|
|
|
{
|
2019-12-30 22:40:39 +08:00
|
|
|
|
2020-02-15 17:24:00 +08:00
|
|
|
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;
|
2019-12-30 22:40:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
SendEmail::dispatch([
|
|
|
|
'email' => $user->email,
|
2019-12-30 22:45:10 +08:00
|
|
|
'subject' => $request->input('subject'),
|
2019-12-30 22:52:02 +08:00
|
|
|
'template_name' => 'mail.sendEmailCustom',
|
2019-12-30 22:40:39 +08:00
|
|
|
'template_value' => [
|
|
|
|
'name' => config('v2board.app_name', 'V2Board'),
|
|
|
|
'url' => config('v2board.app_url'),
|
2019-12-30 22:45:10 +08:00
|
|
|
'content' => $request->input('content')
|
2019-12-30 22:40:39 +08:00
|
|
|
]
|
2020-01-20 13:57:30 +08:00
|
|
|
])->onQueue('other_mail');
|
2019-12-30 22:40:39 +08:00
|
|
|
}
|
2019-12-30 22:45:42 +08:00
|
|
|
|
|
|
|
return response([
|
|
|
|
'data' => true
|
|
|
|
]);
|
2019-12-30 22:40:39 +08:00
|
|
|
}
|
2020-02-15 17:24:00 +08:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2020-01-11 13:36:52 +08:00
|
|
|
}
|