update email template

This commit is contained in:
baodev0
2026-09-09 16:56:22 +07:00
parent d3d9f76ba0
commit 2365ef72e9
210 changed files with 6335 additions and 4688 deletions
+45 -29
View File
@@ -2,8 +2,8 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
@@ -11,55 +11,71 @@ use Illuminate\Queue\SerializesModels;
class OrderPaymentSuccess extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public array $data;
/**
* Create a new message instance.
*/
public function __construct(array $data)
{
$this->data = $data;
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: '✅ Thanh toán thành công - Đơn hàng #' . ($this->data['order_num'] ?? 'N/A'),
subject: $this->renderFromTemplate('order_payment_success', $this->vars())['subject'],
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.customer.order-payment-success',
with: [
'customerName' => $this->data['customer_name'] ?? 'Khách hàng',
'orderId' => $this->data['order_id'] ?? 'N/A',
'orderNum' => $this->data['order_num'] ?? 'N/A',
'amount' => $this->data['amount'] ?? 0,
'vmResults' => $this->data['vm_results'] ?? [],
'addonsSummary' => $this->data['addons_summary'] ?? [],
'supportEmail' => config('mail.support_email', 'support@example.com'),
'supportPhone' => config('mail.support_phone', '1900-xxxx'),
],
htmlString: $this->renderFromTemplate('order_payment_success', $this->vars())['html'],
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
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'),
];
}
}