58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Mail\Customer;
|
|
|
|
use App\Mail\Customer\HostingAccountCreated;
|
|
use App\Services\InvoicePdfService;
|
|
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;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class HostingAccountCreatedJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public int $tries = 3;
|
|
|
|
public array $data;
|
|
|
|
public function __construct(array $data)
|
|
{
|
|
$this->data = $data;
|
|
}
|
|
|
|
public function handle(): void
|
|
{
|
|
if (empty($this->data['customer_email'])) {
|
|
Log::warning('HostingAccountCreatedJob: missing customer_email, skipped.', [
|
|
'domain_name' => $this->data['domain_name'] ?? null,
|
|
]);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$invoice = app(InvoicePdfService::class)->attachment($this->data['invoice_id'] ?? null);
|
|
|
|
Mail::to($this->data['customer_email'])
|
|
->send(new HostingAccountCreated($this->data, $invoice['pdf'] ?? null, $invoice['file_name'] ?? null));
|
|
} catch (\Throwable $e) {
|
|
Log::error('Không thể gửi email thông báo khởi tạo hosting: ' . $e->getMessage(), [
|
|
'customer_email' => $this->data['customer_email'] ?? null,
|
|
'domain_name' => $this->data['domain_name'] ?? null,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function failed(\Throwable $e): void
|
|
{
|
|
Log::error('HostingAccountCreatedJob: job failed.', [
|
|
'error' => $e->getMessage(),
|
|
'domain_name' => $this->data['domain_name'] ?? null,
|
|
]);
|
|
}
|
|
}
|