mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-30 16:07:24 +08:00
refactor: 重构规范部分代码、邮件队列增加失败重试、去除多个支付方式、更新依赖
This commit is contained in:
@@ -2,14 +2,12 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\MailService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Models\MailLog;
|
||||
|
||||
class SendEmailJob implements ShouldQueue
|
||||
{
|
||||
@@ -36,40 +34,9 @@ class SendEmailJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (admin_setting('email_host')) {
|
||||
Config::set('mail.host', admin_setting('email_host', config('mail.host')));
|
||||
Config::set('mail.port', admin_setting('email_port', config('mail.port')));
|
||||
Config::set('mail.encryption', admin_setting('email_encryption', config('mail.encryption')));
|
||||
Config::set('mail.username', admin_setting('email_username', config('mail.username')));
|
||||
Config::set('mail.password', admin_setting('email_password', config('mail.password')));
|
||||
Config::set('mail.from.address', admin_setting('email_from_address', config('mail.from.address')));
|
||||
Config::set('mail.from.name', admin_setting('app_name', 'XBoard'));
|
||||
$mailLog = MailService::sendEmail($this->params);
|
||||
if($mailLog['error']){
|
||||
$this->release(); //发送失败将触发重试
|
||||
}
|
||||
$params = $this->params;
|
||||
$email = $params['email'];
|
||||
$subject = $params['subject'];
|
||||
$params['template_name'] = 'mail.' . admin_setting('email_template', 'default') . '.' . $params['template_name'];
|
||||
try {
|
||||
Mail::send(
|
||||
$params['template_name'],
|
||||
$params['template_value'],
|
||||
function ($message) use ($email, $subject) {
|
||||
$message->to($email)->subject($subject);
|
||||
}
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
$log = [
|
||||
'email' => $params['email'],
|
||||
'subject' => $params['subject'],
|
||||
'template_name' => $params['template_name'],
|
||||
'error' => isset($error) ? $error : NULL
|
||||
];
|
||||
|
||||
MailLog::create($log);
|
||||
$log['config'] = config('mail');
|
||||
return $log;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user