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
+14 -38
View File
@@ -2,7 +2,7 @@
namespace App\Mail\Customer;
use App\Models\Template;
use App\Mail\Concerns\RequiresDbTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
@@ -11,59 +11,35 @@ use Illuminate\Queue\SerializesModels;
class CustomerPayment extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
protected $template;
protected $data;
/** @param int $template Không còn dùng — scenario cố định 'customer_payment'. Giữ tham số để không phá vỡ caller hiện tại. */
public function __construct($template = 0, public $data = []) {}
/**
* Create a new message instance.
*/
public function __construct($template = 0, $data = [])
{
$this->data = $data;
$this->template = Template::find($template);
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: $this->template->subject,
subject: $this->renderFromTemplate('customer_payment', $this->vars())['subject'],
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.template',
with: [
'template' => str_replace(
[
"{\$company_name}",
"{\$company_logo}",
],
[
$this->data['company_name'],
$this->data['company_logo'],
],
$this->template->message)
]
htmlString: $this->renderFromTemplate('customer_payment', $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
{
return [
'company_name' => $this->data['company_name'] ?? '',
'company_logo' => $this->data['company_logo'] ?? '',
];
}
}
+19 -18
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
@@ -10,7 +11,7 @@ use Illuminate\Queue\SerializesModels;
class DepositSuccess extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public array $data;
@@ -22,29 +23,29 @@ class DepositSuccess extends Mailable
public function envelope(): Envelope
{
return new Envelope(
subject: 'V/v: Thông báo nạp tiền thành công - ' . number_format($this->data['amount']) . ' VNĐ',
subject: $this->renderFromTemplate('customer_deposit_success', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.customer.deposit-success',
with: [
'customerName' => $this->data['customer_name'] ?? 'Khách hàng',
'transactionCode' => $this->data['transaction_code'] ?? 'N/A',
'amount' => $this->data['amount'] ?? 0,
'amountFormatted' => number_format($this->data['amount']) ?? '0',
'credit' => $this->data['credit'] ?? 0,
'creditFormatted' => number_format($this->data['credit']) ?? '0',
'currentTotal' => $this->data['current_total'] ?? 0,
'currentTotalFormatted' => number_format($this->data['current_total']) ?? '0',
'currentCredit' => $this->data['current_credit'] ?? 0,
'currentCreditFormatted' => number_format($this->data['current_credit']) ?? '0',
'depositDate' => $this->data['deposit_date'] ?? now()->format('d/m/Y H:i:s'),
'supportEmail' => config('mail.support_email', 'support@thegioiso.com'),
'supportPhone' => config('mail.support_phone', '1900.xxxx'),
],
htmlString: $this->renderFromTemplate('customer_deposit_success', $this->vars())['html'],
);
}
private function vars(): array
{
return [
'customer_name' => $this->data['customer_name'] ?? 'Khách hàng',
'transaction_code' => $this->data['transaction_code'] ?? 'N/A',
'amount_formatted' => number_format((float) ($this->data['amount'] ?? 0)),
'credit_formatted' => number_format((float) ($this->data['credit'] ?? 0)),
'current_total_formatted' => number_format((float) ($this->data['current_total'] ?? 0)),
'current_credit_formatted' => number_format((float) ($this->data['current_credit'] ?? 0)),
'deposit_date' => $this->data['deposit_date'] ?? now()->format('d/m/Y H:i:s'),
'support_email' => config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => config('mail.support_phone', '1900.xxxx'),
];
}
}
@@ -2,6 +2,7 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
@@ -11,7 +12,7 @@ use Illuminate\Queue\SerializesModels;
class DomainOrderReceivedNotification extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(
protected array $data,
@@ -20,19 +21,29 @@ class DomainOrderReceivedNotification extends Mailable implements ShouldQueue
public function envelope(): Envelope
{
return new Envelope(
subject: "Đơn đăng ký tên miền {$this->data['domain_name']} đã được ghi nhận",
subject: $this->renderFromTemplate('domain_order_received', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.layouts.notification',
with: [
'companyName' => $this->data['company_name'] ?? config('app.name'),
'title' => 'Đơn đăng ký tên miền đã được ghi nhận',
'body' => view('emails.customer.domain-order-received', $this->data)->render(),
],
htmlString: $this->renderFromTemplate('domain_order_received', $this->vars())['html'],
);
}
private function vars(): array
{
return [
'customer_name' => $this->data['customer_name'] ?? 'Quý khách',
'company_name' => $this->data['company_name'] ?? config('app.name'),
'domain_name' => $this->data['domain_name'] ?? '',
'order_num' => $this->data['order_num'] ?? '',
'order_total' => $this->data['order_total'] ?? '',
'created_at' => $this->data['created_at'] ?? '',
'order_url' => $this->data['order_url'] ?? '',
'support_email' => $this->data['support_email'] ?? 'support@tgs.com.vn',
'support_phone' => $this->data['support_phone'] ?? '(028) 7309. 7379',
];
}
}
@@ -1,44 +0,0 @@
<?php
namespace App\Mail\Customer;
use App\Models\Template;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class DomainOrderStatusMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public function __construct(
protected Template $template,
protected array $data,
) {}
public function envelope(): Envelope
{
return new Envelope(
subject: str_replace('{$domain_name}', $this->data['domain_name'] ?? '', $this->template->subject),
);
}
public function content(): Content
{
$message = str_replace(
['{$company_name}', '{$company_logo}', '{$domain_name}', '{$client_name}', '{$order_num}', '{$reason}'],
[$this->data['company_name'] ?? '', $this->data['company_logo'] ?? '', $this->data['domain_name'] ?? '', $this->data['client_name'] ?? '', $this->data['order_num'] ?? '', $this->data['reason'] ?? ''],
$this->template->message
);
return new Content(view: 'emails.template', with: ['template' => $message]);
}
public function attachments(): array
{
return [];
}
}
+40 -22
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
@@ -11,40 +12,21 @@ use Illuminate\Queue\SerializesModels;
class HostingAccountCreated extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
$appName = $this->payload()['company_name'] ?? config('app.name', 'The Gioi So');
return new Envelope(
subject: 'Hosting của bạn đã sẵn sàng — ' . ($this->data['domain_name'] ?? '') . ' — ' . $appName,
subject: $this->renderFromTemplate('hosting_account_created', $this->vars())['subject'],
);
}
public function content(): Content
{
$data = $this->payload();
return new Content(
view: 'emails.customer.hosting-account-created',
with: [
'appName' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'fullName' => $data['customer_name'] ?? 'Quý khách',
'domainName' => $data['domain_name'] ?? '',
'hostingPlan' => $data['hosting_plan'] ?? '',
'serverHost' => $data['server_host'] ?? '',
'ftpUsername' => $data['ftp_username'] ?? '',
'ftpPassword' => $data['ftp_password'] ?? '',
'pleskLogin' => $data['plesk_login'] ?? '',
'pleskPassword' => $data['plesk_password'] ?? '',
'pleskPanelUrl' => $data['plesk_panel_url'] ?? '',
'loginUrl' => $data['login_url'] ?? rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
'supportEmail' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'supportPhone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
],
htmlString: $this->renderFromTemplate('hosting_account_created', $this->vars())['html'],
);
}
@@ -69,4 +51,40 @@ class HostingAccountCreated extends Mailable
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
], $this->data);
}
private function vars(): array
{
$data = $this->payload();
$row = fn (string $label, ?string $value) => $value
? "<tr><td style=\"padding: 7px 11px; border-right: 1px solid #e8e8e8;\">{$label}</td><td style=\"padding: 7px 11px; border-right: 1px solid #e8e8e8;\"><strong>{$value}</strong></td></tr>"
: '';
$pleskBlock = '';
if (!empty($data['plesk_login'])) {
$pleskBlock = '<p style="color: #f16723;"><strong>TÀI KHOẢN ĐĂNG NHẬP PLESK PANEL</strong></p>'
. '<table cellpadding="0" cellspacing="0" border="0" style="width: 100%; table-layout: fixed; border: 1px solid #e8e8e8; border-right: 0;"><tbody>'
. '<tr><td style="padding: 7px 11px; border-right: 1px solid #e8e8e8; width: 200px;">Địa chỉ Panel:</td><td style="padding: 7px 11px; border-right: 1px solid #e8e8e8;"><a style="color: #f16723; text-decoration: none;" href="' . ($data['plesk_panel_url'] ?? '') . '" target="_blank" rel="noopener">' . ($data['plesk_panel_url'] ?? '') . '</a></td></tr>'
. '<tr bgcolor="#FFF1E6"><td style="padding: 7px 11px; border-right: 1px solid #e8e8e8;">Tên đăng nhập:</td><td style="padding: 7px 11px; border-right: 1px solid #e8e8e8;"><strong>' . ($data['plesk_login'] ?? '') . '</strong></td></tr>'
. (!empty($data['plesk_password']) ? '<tr><td style="padding: 7px 11px; border-right: 1px solid #e8e8e8;">Mật khẩu:</td><td style="padding: 7px 11px; border-right: 1px solid #e8e8e8;"><strong>' . $data['plesk_password'] . '</strong></td></tr>' : '')
. '</tbody></table>';
}
return [
'app_name' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'full_name' => $data['customer_name'] ?? 'Quý khách',
'domain_name' => $data['domain_name'] ?? '',
'hosting_plan' => $data['hosting_plan'] ?? '',
'server_host_row' => $row('Máy chủ / FTP Host:', $data['server_host'] ?? null),
'ftp_username_row' => $row('Tài khoản FTP:', $data['ftp_username'] ?? null),
'ftp_password_row' => $row('Mật khẩu FTP:', $data['ftp_password'] ?? null),
'ftp_password_notice' => !empty($data['ftp_password'])
? '<p style="text-align: justify; color: #b45309; font-size: 13px;">Lưu ý: Vì lý do bảo mật, mật khẩu FTP chỉ được gửi một lần duy nhất qua email và không được lưu trữ trên hệ thống. Vui lòng lưu lại ở nơi an toàn.</p>'
: '',
'plesk_block' => $pleskBlock,
'login_url' => $data['login_url'] ?? rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
'support_email' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
];
}
}
+2 -1
View File
@@ -3,12 +3,13 @@
namespace App\Mail\Customer;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class ManualCustomerEmail extends Mailable
class ManualCustomerEmail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
+28 -22
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
@@ -11,40 +12,21 @@ use Illuminate\Queue\SerializesModels;
class ManualDepositStatus extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->payload()['subject'] ?? 'Thông báo trạng thái nạp tiền',
subject: $this->renderFromTemplate('manual_deposit_status', $this->vars())['subject'],
);
}
public function content(): Content
{
$data = $this->payload();
return new Content(
view: 'emails.customer.manual-deposit-status',
with: [
'companyName' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'companyLogo' => $data['company_logo'] ?? '',
'customerName' => $data['customer_name'] ?? 'Quý khách',
'transactionCode' => $data['transaction_code'] ?? 'N/A',
'amount' => $data['amount'] ?? 0,
'amountFormatted' => number_format((float) ($data['amount'] ?? 0), 0, ',', '.'),
'statusLabel' => $data['status_label'] ?? 'Đang chờ duyệt',
'statusColor' => $data['status_color'] ?? '#f16723',
'statusBg' => $data['status_bg'] ?? '#fff7ed',
'statusMessage' => $data['status_message'] ?? ($data['message'] ?? ''),
'depositDate' => $data['deposit_date'] ?? now()->format('d/m/Y H:i:s'),
'processedDate' => $data['processed_date'] ?? null,
'portalUrl' => $data['portal_url'] ?? rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/nap-tien',
'supportEmail' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'supportPhone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
],
htmlString: $this->renderFromTemplate('manual_deposit_status', $this->vars())['html'],
);
}
@@ -70,4 +52,28 @@ class ManualDepositStatus extends Mailable
'portal_url' => rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/nap-tien',
], $this->data);
}
private function vars(): array
{
$data = $this->payload();
$amount = (float) ($data['amount'] ?? 0);
return [
'company_name' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'customer_name' => $data['customer_name'] ?? 'Quý khách',
'transaction_code' => $data['transaction_code'] ?? 'N/A',
'amount_formatted' => number_format($amount, 0, ',', '.'),
'status_label' => $data['status_label'] ?? 'Đang chờ duyệt',
'status_color' => $data['status_color'] ?? '#f16723',
'status_bg' => $data['status_bg'] ?? '#fff7ed',
'status_message' => $data['status_message'] ?? ($data['message'] ?? ''),
'deposit_date' => $data['deposit_date'] ?? now()->format('d/m/Y H:i:s'),
'processed_date_row' => !empty($data['processed_date'])
? '<tr><td style="padding:12px 16px;background-color:#fafafa;color:#78909c;width:42%">Thời gian xử lý</td><td style="padding:12px 16px;color:#263238">' . $data['processed_date'] . '</td></tr>'
: '',
'portal_url' => $data['portal_url'] ?? rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/nap-tien',
'support_email' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
];
}
}
-64
View File
@@ -1,64 +0,0 @@
<?php
namespace App\Mail\Customer;
use App\Models\Template;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class OrderCreated extends Mailable
{
use Queueable, SerializesModels;
protected Template $template;
protected array $data;
public function __construct(Template $template, array $data)
{
$this->template = $template;
$this->data = $data;
}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->template->subject,
);
}
public function content(): Content
{
$message = str_replace(
[
'{\$company_name}',
'{\$company_logo}',
'{\$client_name}',
'{\$order_num}',
'{\$order_total}',
'{\$invoice_num}',
],
[
$this->data['company_name'],
$this->data['company_logo'],
$this->data['client_name'],
$this->data['order_num'],
$this->data['order_total'],
$this->data['invoice_num'],
],
$this->template->message
);
return new Content(
view: 'emails.template',
with: ['template' => $message],
);
}
public function attachments(): array
{
return [];
}
}
+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'),
];
}
}
+19 -16
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
@@ -11,34 +12,21 @@ use Illuminate\Queue\SerializesModels;
class PasswordResetByAdmin extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
$appName = $this->payload()['company_name'] ?? config('app.name', 'The Gioi So');
return new Envelope(
subject: 'Mật khẩu của bạn đã được cập nhật — ' . $appName,
subject: $this->renderFromTemplate('password_reset_admin', $this->vars())['subject'],
);
}
public function content(): Content
{
$data = $this->payload();
return new Content(
view: 'emails.customer.password-reset-admin',
with: [
'appName' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'fullName' => $data['fullname'] ?? 'Quý khách',
'email' => $data['email'] ?? '',
'password' => $data['password'] ?? '',
'loginUrl' => $data['login_url'] ?? rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
'supportEmail' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'supportPhone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
],
htmlString: $this->renderFromTemplate('password_reset_admin', $this->vars())['html'],
);
}
@@ -63,4 +51,19 @@ class PasswordResetByAdmin extends Mailable
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
], $this->data);
}
private function vars(): array
{
$data = $this->payload();
return [
'app_name' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'full_name' => $data['fullname'] ?? 'Quý khách',
'email' => $data['email'] ?? '',
'password' => $data['password'] ?? '',
'login_url' => $data['login_url'] ?? rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
'support_email' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
];
}
}
+33 -25
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
@@ -11,41 +12,27 @@ use Illuminate\Queue\SerializesModels;
class SnapshotActionMail extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
private const LABELS = [
'create' => ['icon' => '📸', 'title' => 'Tạo Snapshot thành công', 'desc' => 'Snapshot máy chủ ảo của bạn đã được tạo thành công', 'status' => 'Tạo thành công ✓'],
'remove' => ['icon' => '🗑️', 'title' => 'Xóa Snapshot thành công', 'desc' => 'Snapshot máy chủ ảo của bạn đã được xóa thành công', 'status' => 'Xóa thành công ✓'],
'revert' => ['icon' => '🔄', 'title' => 'Khôi phục Snapshot thành công', 'desc' => 'Máy chủ ảo của bạn đã được khôi phục về snapshot thành công', 'status' => 'Khôi phục thành công ✓'],
];
public function __construct(public array $data) {}
public function envelope(): Envelope
{
$subjects = [
'create' => 'Tạo Snapshot thành công',
'remove' => 'Xóa Snapshot thành công',
'revert' => 'Khôi phục Snapshot thành công',
];
$appName = $this->payload()['company_name'] ?? config('app.name', 'The Gioi So');
$subject = $subjects[$this->data['action'] ?? 'create'] ?? 'Thông báo Snapshot';
return new Envelope(subject: "{$subject} — {$appName}");
return new Envelope(
subject: $this->renderFromTemplate('snapshot_action', $this->vars())['subject'],
);
}
public function content(): Content
{
$data = $this->payload();
return new Content(
view: 'emails.customer.snapshot-action',
with: [
'appName' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'fullName' => $data['fullname'] ?? 'Quý khách',
'vmName' => $data['vm_name'] ?? '',
'snapshotName' => $data['snapshot_name'] ?? '',
'action' => $data['action'] ?? 'create',
'actionAt' => $data['action_at'] ?? now()->format('d/m/Y H:i:s'),
'loginUrl' => $data['login_url'] ?? rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
'supportEmail' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'supportPhone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
],
htmlString: $this->renderFromTemplate('snapshot_action', $this->vars())['html'],
);
}
@@ -70,4 +57,25 @@ class SnapshotActionMail extends Mailable
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
], $this->data);
}
private function vars(): array
{
$data = $this->payload();
$label = self::LABELS[$data['action'] ?? 'create'] ?? self::LABELS['create'];
return [
'app_name' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'full_name' => $data['fullname'] ?? 'Quý khách',
'vm_name' => $data['vm_name'] ?? '',
'snapshot_name' => $data['snapshot_name'] ?? '',
'action_at' => $data['action_at'] ?? now()->format('d/m/Y H:i:s'),
'action_icon' => $label['icon'],
'action_title' => $label['title'],
'action_desc' => $label['desc'],
'action_status' => $label['status'],
'login_url' => $data['login_url'] ?? rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
'support_email' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
];
}
}
+18 -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,44 @@ use Illuminate\Queue\SerializesModels;
class VMCreationFailed 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: 'Thông báo: Không thể khởi tạo máy chủ ảo - Đơn hàng #' . ($this->data['order_num'] ?? 'N/A'),
subject: $this->renderFromTemplate('vm_creation_failed', $this->vars())['subject'],
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'emails.customer.vm-creation-failed',
with: [
'customerName' => $this->data['customer_name'] ?? 'Khách hàng',
'productName' => $this->data['product_name'] ?? 'Sản phẩm',
'orderId' => $this->data['order_id'] ?? 'N/A',
'orderNum' => $this->data['order_num'] ?? 'N/A',
'errorMessage' => $this->data['error_message'] ?? 'Lỗi không xác định',
'supportEmail' => config('mail.support_email', 'support@example.com'),
'supportPhone' => config('mail.support_phone', '1900-xxxx'),
'invoiceUrl' => rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/hoa-don/' . ($this->data['order_id'] ?? ''),
],
htmlString: $this->renderFromTemplate('vm_creation_failed', $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
{
return [
'app_name' => config('app.name', 'Thế Giới Số'),
'full_name' => $this->data['customer_name'] ?? 'Khách hàng',
'order_num' => $this->data['order_num'] ?? 'N/A',
'product_name' => $this->data['product_name'] ?? 'Sản phẩm',
'invoice_url' => rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/hoa-don/' . ($this->data['order_id'] ?? ''),
'support_email' => config('mail.support_email', 'support@example.com'),
'support_phone' => config('mail.support_phone', '1900-xxxx'),
];
}
}
+17 -14
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
@@ -11,32 +12,21 @@ use Illuminate\Queue\SerializesModels;
class VerifyAccount extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
$appName = $this->payload()['company_name'] ?? config('app.name', 'The Gioi So');
return new Envelope(
subject: '[' . $appName . '] Mã xác thực tài khoản của bạn',
subject: $this->renderFromTemplate('verify_account_welcome', $this->vars())['subject'],
);
}
public function content(): Content
{
$data = $this->payload();
return new Content(
view: 'emails.customer.verify-account-welcome',
with: [
'appName' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'fullName' => $data['fullname'] ?? 'Quý khách',
'verifyCode' => $data['verify_code'] ?? '',
'supportEmail' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'supportPhone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
],
htmlString: $this->renderFromTemplate('verify_account_welcome', $this->vars())['html'],
);
}
@@ -60,4 +50,17 @@ class VerifyAccount extends Mailable
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
], $this->data);
}
private function vars(): array
{
$data = $this->payload();
return [
'app_name' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'full_name' => $data['fullname'] ?? 'Quý khách',
'verify_code' => $data['verify_code'] ?? '',
'support_email' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
];
}
}
+22 -16
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
@@ -11,34 +12,21 @@ use Illuminate\Queue\SerializesModels;
class VmPasswordChanged extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
$appName = $this->payload()['company_name'] ?? config('app.name', 'The Gioi So');
return new Envelope(
subject: 'Mật khẩu VM của bạn đã được thay đổi — ' . $appName,
subject: $this->renderFromTemplate('vm_password_changed', $this->vars())['subject'],
);
}
public function content(): Content
{
$data = $this->payload();
return new Content(
view: 'emails.customer.vm-password-changed',
with: [
'appName' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'fullName' => $data['fullname'] ?? 'Quý khách',
'vmName' => $data['vm_name'] ?? '',
'newPassword' => $data['newPassword'] ?? '',
'loginUrl' => $data['login_url'] ?? rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
'supportEmail' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'supportPhone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
],
htmlString: $this->renderFromTemplate('vm_password_changed', $this->vars())['html'],
);
}
@@ -63,4 +51,22 @@ class VmPasswordChanged extends Mailable
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
], $this->data);
}
private function vars(): array
{
$data = $this->payload();
$newPassword = $data['newPassword'] ?? '';
return [
'app_name' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'full_name' => $data['fullname'] ?? 'Quý khách',
'vm_name' => $data['vm_name'] ?? '',
'new_password_row' => $newPassword
? '<div>Mật khẩu mới: <strong style="font-family: \'Menlo\',\'Consolas\',monospace; color: #111827;">' . $newPassword . '</strong></div>'
: '',
'login_url' => $data['login_url'] ?? rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
'support_email' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
];
}
}
+17 -12
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,7 +11,7 @@ use Illuminate\Queue\SerializesModels;
class VmRebuildFailed extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public array $data;
@@ -23,22 +23,14 @@ class VmRebuildFailed extends Mailable
public function envelope(): Envelope
{
return new Envelope(
subject: 'Thông báo: Cài lại hệ điều hành thất bại - ' . ($this->data['vm_name'] ?? 'VPS'),
subject: $this->renderFromTemplate('vm_rebuild_failed', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.customer.vm-rebuild-failed',
with: [
'customerName' => $this->data['customer_name'] ?? 'Khách hàng',
'vmName' => $this->data['vm_name'] ?? 'N/A',
'ip' => $this->data['ip'] ?? 'N/A',
'supportEmail' => config('mail.support_email', 'support@example.com'),
'supportPhone' => config('mail.support_phone', '1900-xxxx'),
'serviceUrl' => rtrim((string) env('FRONTEND_URL', config('app.url')), '/') . '/dich-vu',
],
htmlString: $this->renderFromTemplate('vm_rebuild_failed', $this->vars())['html'],
);
}
@@ -46,4 +38,17 @@ class VmRebuildFailed extends Mailable
{
return [];
}
private function vars(): array
{
return [
'app_name' => config('app.name', 'Thế Giới Số'),
'full_name' => $this->data['customer_name'] ?? 'Khách hàng',
'vm_name' => $this->data['vm_name'] ?? 'N/A',
'ip' => $this->data['ip'] ?? 'N/A',
'service_url' => rtrim((string) env('FRONTEND_URL', config('app.url')), '/') . '/dich-vu',
'support_email' => config('mail.support_email', 'support@example.com'),
'support_phone' => config('mail.support_phone', '1900-xxxx'),
];
}
}
+17 -14
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
@@ -11,32 +12,21 @@ use Illuminate\Queue\SerializesModels;
class Welcome extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
$appName = $this->payload()['company_name'] ?? config('app.name', 'The Gioi So');
return new Envelope(
subject: 'Chào mừng bạn đến với ' . $appName,
subject: $this->renderFromTemplate('customer_welcome', $this->vars())['subject'],
);
}
public function content(): Content
{
$data = $this->payload();
return new Content(
view: 'emails.customer.welcome',
with: [
'appName' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'fullName' => $data['fullname'] ?? 'Quý khách',
'loginUrl' => $data['login_url'] ?? rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/dang-nhap',
'supportEmail' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'supportPhone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
],
htmlString: $this->renderFromTemplate('customer_welcome', $this->vars())['html'],
);
}
@@ -45,6 +35,19 @@ class Welcome extends Mailable
return [];
}
private function vars(): array
{
$data = $this->payload();
return [
'app_name' => $data['company_name'] ?? config('app.name', 'The Gioi So'),
'full_name' => $data['fullname'] ?? 'Quý khách',
'login_url' => $data['login_url'] ?? rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/dang-nhap',
'support_email' => $data['support_email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $data['support_phone'] ?? config('mail.support_phone', '1900.xxxx'),
];
}
private function payload(): array
{
try {