This commit is contained in:
Tokumeikoi 2020-03-18 18:12:19 +08:00
parent 1291bf47be
commit 49d5b407bc
8 changed files with 28 additions and 21 deletions

View File

@ -5,7 +5,7 @@ namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\User;
use App\Models\MailLog;
use App\Jobs\SendEmail;
use App\Jobs\SendEmailJob;
class SendRemindMail extends Command
{
@ -50,10 +50,10 @@ class SendRemindMail extends Command
private function remindExpire($user)
{
if (($user->expired_at - 86400) < time() && $user->expired_at > time()) {
SendEmail::dispatch([
SendEmailJob::dispatch([
'email' => $user->email,
'subject' => '在' . config('v2board.app_name', 'V2board') . '的服务即将到期',
'template_name' => 'mail.sendRemindExpire',
'template_name' => 'remindExpire',
'template_value' => [
'name' => config('v2board.app_name', 'V2Board'),
'url' => config('v2board.app_url')
@ -69,10 +69,10 @@ class SendRemindMail extends Command
->where('template_name', 'mail.sendRemindTraffic')
->count();
if ($sendCount > 0) return;
SendEmail::dispatch([
SendEmailJob::dispatch([
'email' => $user->email,
'subject' => '在' . config('v2board.app_name', 'V2board') . '的流量使用已达到80%',
'template_name' => 'mail.sendRemindTraffic',
'template_name' => 'remindTraffic',
'template_value' => [
'name' => config('v2board.app_name', 'V2Board'),
'url' => config('v2board.app_url')

View File

@ -11,12 +11,12 @@ class ConfigController extends Controller
{
public function getEmailTemplate()
{
$dirs = [];
foreach (glob(resource_path('views/mail')) as $file) {
array_push($dirs, $file);
}
$path = resource_path('views/mail/');
$files = array_map(function ($item) use ($path) {
return str_replace($path, '', $item);
}, glob($path . '*'));
return response([
'data' => $dirs
'data' => $files
]);
}
@ -83,6 +83,9 @@ class ConfigController extends Controller
],
'tutorial' => [
'apple_id' => config('v2board.apple_id')
],
'email' => [
'email_template' => config('v2board.email_template', 'default')
]
]
]);

View File

@ -6,7 +6,7 @@ use App\Http\Requests\Admin\MailSend;
use App\Services\UserService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Jobs\SendEmail;
use App\Jobs\SendEmailJob;
class MailController extends Controller
{
@ -28,10 +28,10 @@ class MailController extends Controller
}
foreach ($users as $user) {
SendEmail::dispatch([
SendEmailJob::dispatch([
'email' => $user->email,
'subject' => $request->input('subject'),
'template_name' => 'mail.sendEmailCustom',
'template_name' => 'notify',
'template_value' => [
'name' => config('v2board.app_name', 'V2Board'),
'url' => config('v2board.app_url'),

View File

@ -9,7 +9,7 @@ use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\Mail;
use App\Utils\Helper;
use Illuminate\Support\Facades\Cache;
use App\Jobs\SendEmail;
use App\Jobs\SendEmailJob;
use App\Models\InviteCode;
use App\Utils\Dict;
use App\Utils\CacheKey;
@ -45,10 +45,10 @@ class CommController extends Controller
$code = rand(100000, 999999);
$subject = config('v2board.app_name', 'V2Board') . '邮箱验证码';
SendEmail::dispatch([
SendEmailJob::dispatch([
'email' => $email,
'subject' => $subject,
'template_name' => 'mail.sendEmailVerify',
'template_name' => 'verify',
'template_value' => [
'name' => config('v2board.app_name', 'V2Board'),
'code' => $code,

View File

@ -10,7 +10,7 @@ use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
use App\Models\MailLog;
class SendEmail implements ShouldQueue
class SendEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $params;
@ -22,6 +22,7 @@ class SendEmail implements ShouldQueue
*/
public function __construct($params)
{
$this->onQueue = 'send_mail';
$this->params = $params;
}
@ -35,6 +36,7 @@ class SendEmail implements ShouldQueue
$params = $this->params;
$email = $params['email'];
$subject = $params['subject'];
$params['template_name'] = 'mail.' . config('v2board.email_template', 'default') . '.' . $params['template_name'];
try {
Mail::send(
$params['template_name'],

View File

@ -1,2 +0,0 @@
php artisan key:generate
php artisan config:cache

View File

@ -1,5 +1,5 @@
apps:
- name : 'V2Board'
script : 'php artisan queue:work --queue=verify_mail,other_mail'
script : 'php artisan queue:work --queue=send_email'
instances: 4
out_file : './storage/logs/queue/queue.log'
out_file : './storage/logs/queue/queue.log'

4
update.sh Executable file
View File

@ -0,0 +1,4 @@
git fetch --all && git reset --hard origin/master && git pull origin master
php artisan v2board:update
php artisan config:cache
pm2 restart pm2.yaml