82 lines
3.2 KiB
PHP
82 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Mail\Customer;
|
|
|
|
use App\Mail\Concerns\RequiresDbTemplate;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Mail\Mailables\Content;
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class OrderPaymentSuccess extends Mailable
|
|
{
|
|
use Queueable, SerializesModels, RequiresDbTemplate;
|
|
|
|
public array $data;
|
|
|
|
public function __construct(array $data)
|
|
{
|
|
$this->data = $data;
|
|
}
|
|
|
|
public function envelope(): Envelope
|
|
{
|
|
return new Envelope(
|
|
subject: $this->renderFromTemplate('order_payment_success', $this->vars())['subject'],
|
|
);
|
|
}
|
|
|
|
public function content(): Content
|
|
{
|
|
return new Content(
|
|
htmlString: $this->renderFromTemplate('order_payment_success', $this->vars())['html'],
|
|
);
|
|
}
|
|
|
|
public function attachments(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
private function vars(): array
|
|
{
|
|
$vmRows = '';
|
|
foreach ($this->data['vm_results'] ?? [] as $vm) {
|
|
$rows = '';
|
|
if (!empty($vm['ip'])) {
|
|
$rows .= '<div class="vm-row"><span class="vm-label">🌐 IP Address</span><span class="vm-value">' . $vm['ip'] . '</span></div>';
|
|
}
|
|
if (!empty($vm['username'])) {
|
|
$rows .= '<div class="vm-row"><span class="vm-label">👤 Username</span><span class="vm-value">' . $vm['username'] . '</span></div>';
|
|
}
|
|
if (!empty($vm['password'])) {
|
|
$rows .= '<div class="vm-row"><span class="vm-label">🔑 Password</span><span class="vm-value">' . $vm['password'] . '</span></div>';
|
|
}
|
|
if (!empty($vm['os'])) {
|
|
$rows .= '<div class="vm-row"><span class="vm-label">💿 Hệ điều hành</span><span class="vm-value">' . $vm['os'] . '</span></div>';
|
|
}
|
|
$vmRows .= '<div class="vm-box">' . $rows . '</div>';
|
|
}
|
|
$vmBlock = $vmRows ? '<div class="section-label">Thông tin dịch vụ Cloud VPS</div>' . $vmRows : '';
|
|
|
|
$addonRows = '';
|
|
foreach ($this->data['addons_summary'] ?? [] as $addon) {
|
|
$addonRows .= '<tr><td>' . $addon['name'] . '</td><td class="td-num">' . $addon['qty'] . '</td><td class="td-num">' . number_format((float) $addon['subtotal'], 0, ',', '.') . ' VNĐ</td></tr>';
|
|
}
|
|
$addonBlock = $addonRows
|
|
? '<div class="section-label">Gói nâng cấp cấu hình (Addon)</div><table class="addon-table"><thead><tr><th>Dịch vụ addon</th><th style="text-align:right">Số lượng</th><th style="text-align:right">Thành tiền</th></tr></thead><tbody>' . $addonRows . '</tbody></table>'
|
|
: '';
|
|
|
|
return [
|
|
'customer_name' => $this->data['customer_name'] ?? 'Khách hàng',
|
|
'order_num' => $this->data['order_num'] ?? 'N/A',
|
|
'amount_formatted'=> number_format((float) ($this->data['amount'] ?? 0), 0, ',', '.'),
|
|
'vm_block' => $vmBlock,
|
|
'addon_block' => $addonBlock,
|
|
'support_email' => config('mail.support_email', 'support@example.com'),
|
|
'support_phone' => config('mail.support_phone', '1900-xxxx'),
|
|
];
|
|
}
|
|
}
|