60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Mail\Concerns\RequiresDbTemplate;
|
|
use App\Models\Customer;
|
|
use App\Models\Service;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Mail\Mailables\Content;
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class ServiceRenewalReminderMail extends Mailable
|
|
{
|
|
use Queueable, SerializesModels, RequiresDbTemplate;
|
|
|
|
public function __construct(
|
|
public readonly Customer $customer,
|
|
public readonly Service $service,
|
|
) {}
|
|
|
|
public function envelope(): Envelope
|
|
{
|
|
return new Envelope(
|
|
subject: $this->renderFromTemplate('service_renewal_reminder', $this->vars())['subject'],
|
|
);
|
|
}
|
|
|
|
public function content(): Content
|
|
{
|
|
return new Content(
|
|
htmlString: $this->renderFromTemplate('service_renewal_reminder', $this->vars())['html'],
|
|
);
|
|
}
|
|
|
|
private function vars(): array
|
|
{
|
|
$serverName = $this->service->server_name ?? '';
|
|
$price = $this->service->orderItem?->price
|
|
? number_format((float) $this->service->orderItem->price, 0, ',', '.')
|
|
: null;
|
|
|
|
return [
|
|
'client_name' => $this->customer->fullname ?? '',
|
|
'product_name' => $this->service->product?->name ?? 'Dịch vụ',
|
|
'server_name_suffix' => $serverName ? " ({$serverName})" : '',
|
|
'expires_at' => $this->service->expires_at
|
|
? \Carbon\Carbon::parse($this->service->expires_at)->format('d/m/Y')
|
|
: 'N/A',
|
|
'price_row' => $price
|
|
? '<tr><td style="padding: 7px 11px; border-right: 1px solid #e8e8e8;">Số tiền gia hạn:</td><td style="padding: 7px 11px; border-right: 1px solid #e8e8e8;"><strong>' . $price . ' VNĐ</strong></td></tr>'
|
|
: '',
|
|
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
|
|
'support_email' => 'support@tgs.com.vn',
|
|
'support_phone' => '(028) 7309. 7379',
|
|
];
|
|
}
|
|
}
|