2019-12-30 22:40:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Http\Requests\Admin\MailSend;
|
2020-02-28 17:16:05 +08:00
|
|
|
use App\Services\UserService;
|
2019-12-30 22:40:39 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Jobs\SendEmail;
|
|
|
|
|
|
|
|
class MailController extends Controller
|
|
|
|
{
|
2020-01-11 13:36:52 +08:00
|
|
|
public function send(MailSend $request)
|
|
|
|
{
|
2020-02-28 17:16:05 +08:00
|
|
|
$userService = new UserService();
|
|
|
|
$users = [];
|
2020-02-15 17:24:00 +08:00
|
|
|
switch ($request->input('type')) {
|
2020-02-28 17:16:05 +08:00
|
|
|
case 1: $users = $userService->getAllUsers();
|
2020-02-15 17:24:00 +08:00
|
|
|
break;
|
2020-02-28 17:16:05 +08:00
|
|
|
case 2: $users = $userService->getUsersByIds($request->input('receiver'));
|
2020-02-15 17:24:00 +08:00
|
|
|
break;
|
2020-02-28 17:16:05 +08:00
|
|
|
// available users
|
|
|
|
case 3: $users = $userService->getAvailableUsers();
|
2020-02-15 17:24:00 +08:00
|
|
|
break;
|
2020-02-28 17:16:05 +08:00
|
|
|
// un available users
|
|
|
|
case 4: $users = $userService->getUnAvailbaleUsers();
|
2020-02-15 17:24:00 +08:00
|
|
|
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-01-11 13:36:52 +08:00
|
|
|
}
|