70 lines
2.7 KiB
PHP
70 lines
2.7 KiB
PHP
<?php
|
|
|
|
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\Log;
|
|
|
|
class SendAdminQnaCreatedMailJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public int $tries = 3;
|
|
public int $timeout = 30;
|
|
|
|
public function __construct(
|
|
public int $memNo,
|
|
public int $qnaId,
|
|
public array $data = []
|
|
) {}
|
|
|
|
// 문의 등록이 되면 db처리 후 관리자 메일 발송만 큐에 담아 순차적으로 발송한다.
|
|
public function handle(MailService $mail): void
|
|
{
|
|
//관리자 이메일
|
|
//$adminEmails = ['sungro815@syye.net', 'rudals1540@plusmaker.co.kr'];
|
|
$adminEmails = ['sungro815@syye.net'];
|
|
foreach ($adminEmails as $to) {
|
|
try {
|
|
$mail->sendTemplate(
|
|
$to,
|
|
'[PIN FOR YOU] 1:1 문의 등록 알림',
|
|
'mail.admin.qna_created',
|
|
[
|
|
'name' => $this->data['name'],
|
|
'email' => $this->data['email'],
|
|
'cell' => $this->data['cell'],
|
|
'title' => '[PIN FOR YOU] 1:1 문의 등록 알림',
|
|
'mem_no' => $this->memNo,
|
|
'qna_id' => $this->qnaId,
|
|
'year' => $this->data['year'] ?? null,
|
|
'enquiry_code' => $this->data['enquiry_code'] ?? '',
|
|
'enquiry_title' => $this->data['enquiry_title'] ?? '',
|
|
'enquiry_content' => $this->data['enquiry_content'] ?? '',
|
|
'return_type' => $this->data['return_type'] ?? null,
|
|
'ip' => $this->data['ip'] ?? '',
|
|
'created_at' => $this->data['created_at'] ?? now()->toDateTimeString(),
|
|
'accent' => '#E4574B',
|
|
'brand' => 'PIN FOR YOU',
|
|
'siteUrl' => config('app.url'),
|
|
],
|
|
queue: false // 여기서도 실제 발송은 즉시, 하지만 "요청 처리"와 분리됨(비동기)
|
|
);
|
|
} catch (\Throwable $e) {
|
|
Log::error('[QNA] admin notify mail failed', [
|
|
'mem_no' => $this->memNo,
|
|
'qna_id' => $this->qnaId,
|
|
'email' => $to,
|
|
'err' => $e->getMessage(),
|
|
]);
|
|
// 한 명 실패해도 나머지 계속 시도
|
|
}
|
|
}
|
|
}
|
|
}
|