37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Mail\Customer;
|
|
|
|
use App\Models\Template;
|
|
use App\Services\Email\EmailTemplateService;
|
|
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 OrderCreatedJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public function __construct(public readonly array $data) {}
|
|
|
|
public function handle(EmailTemplateService $emailTemplateService): void
|
|
{
|
|
if (!Template::where('scenario', 'order_created')->where('status', 1)->exists()) {
|
|
Log::warning('OrderCreatedJob: Template "order_created" not found or inactive.');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$emailTemplateService->send('order_created', $this->data['customer_email'], $this->data);
|
|
} catch (\Throwable $e) {
|
|
Log::error('OrderCreatedJob: Failed to send email. ' . $e->getMessage(), [
|
|
'customer_email' => $this->data['customer_email'],
|
|
'order_num' => $this->data['order_num'] ?? null,
|
|
]);
|
|
}
|
|
}
|
|
}
|