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
+33 -5
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
@@ -12,23 +13,21 @@ use Illuminate\Queue\SerializesModels;
class AdminOrderNotification extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public readonly array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: '[ADMIN] Đơn hàng mới #' . ($this->data['order_num'] ?? 'N/A')
. ' — ' . ($this->data['customer_email'] ?? ''),
subject: $this->renderFromTemplate('admin_order_notification', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.admin.order-notification',
with: $this->data,
htmlString: $this->renderFromTemplate('admin_order_notification', $this->vars())['html'],
);
}
@@ -36,4 +35,33 @@ class AdminOrderNotification extends Mailable
{
return [];
}
private function vars(): array
{
$vmFields = ['ip' => '🌐 IP Address', 'username' => '👤 Username', 'password' => '🔑 Password'];
$vmRows = '';
foreach ($vmFields as $field => $label) {
if (!empty($this->data[$field])) {
$vmRows .= '<div class="vm-row"><span class="vm-label">' . $label . '</span><span class="vm-value">' . e($this->data[$field]) . '</span></div>';
}
}
return [
'order_num' => $this->data['order_num'] ?? 'N/A',
'created_at' => $this->data['created_at'] ?? now()->format('d/m/Y H:i:s'),
'customer_name' => $this->data['customer_name'] ?? 'N/A',
'customer_email' => $this->data['customer_email'] ?? 'N/A',
'client_ip_row' => !empty($this->data['client_ip'])
? '<tr><td>IP đặt hàng</td><td>' . e($this->data['client_ip']) . '</td></tr>'
: '',
'product_name' => $this->data['product_name'] ?? 'N/A',
'product_type' => $this->data['product_type'] ?? 'N/A',
'billing_cycle' => $this->data['billing_cycle'] ?? 'N/A',
'total_formatted' => number_format((float) ($this->data['total'] ?? 0), 0, ',', '.') . ' VNĐ',
'vm_block' => $vmRows
? '<div class="section-label">Thông tin dịch vụ Cloud VPS</div><div class="vm-box">' . $vmRows . '</div>'
: '',
'company_name' => $this->data['company_name'] ?? 'Portal Admin',
];
}
}
+18 -8
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Admin;
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 DomainOrderNewNotification extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(
protected array $data,
@@ -20,19 +21,28 @@ class DomainOrderNewNotification extends Mailable implements ShouldQueue
public function envelope(): Envelope
{
return new Envelope(
subject: "[ADMIN] Đơn đăng ký tên miền mới - {$this->data['domain_name']}",
subject: $this->renderFromTemplate('admin_domain_order_new', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.layouts.notification',
with: [
'companyName' => $this->data['company_name'] ?? config('app.name'),
'title' => 'Thông báo đơn đăng ký tên miền mới',
'body' => view('emails.admin.domain-order-new', $this->data)->render(),
],
htmlString: $this->renderFromTemplate('admin_domain_order_new', $this->vars())['html'],
);
}
private function vars(): array
{
return [
'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'] ?? '',
'customer_name' => $this->data['customer_name'] ?? '',
'customer_email' => $this->data['customer_email'] ?? '',
'created_at' => $this->data['created_at'] ?? now()->format('d/m/Y H:i:s'),
'admin_url' => $this->data['admin_url'] ?? '',
];
}
}
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
@@ -12,22 +13,21 @@ use Illuminate\Queue\SerializesModels;
class HostingAccountCreatedAdminNotification extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public readonly array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: '[ADMIN] Hosting account mới — ' . ($this->data['domain_name'] ?? 'N/A'),
subject: $this->renderFromTemplate('admin_hosting_account_created', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.admin.hosting-account-created',
with: $this->data,
htmlString: $this->renderFromTemplate('admin_hosting_account_created', $this->vars())['html'],
);
}
@@ -35,4 +35,29 @@ class HostingAccountCreatedAdminNotification extends Mailable
{
return [];
}
private function vars(): array
{
$row = fn (string $label, ?string $value) => $value
? '<div class="cred-row"><span class="cred-label">' . $label . '</span><span class="cred-value">' . e($value) . '</span></div>'
: '';
return [
'domain_name' => $this->data['domain_name'] ?? 'N/A',
'created_at' => $this->data['created_at'] ?? now()->format('d/m/Y H:i:s'),
'customer_name' => $this->data['customer_name'] ?? 'N/A',
'customer_email' => $this->data['customer_email'] ?? 'N/A',
'hosting_plan' => $this->data['hosting_plan'] ?? 'N/A',
'server_name' => $this->data['server_name'] ?? 'N/A',
'server_ip' => $this->data['server_ip'] ?? 'N/A',
'plesk_client_id' => $this->data['plesk_client_id'] ?? 'N/A',
'plesk_subscription_id' => $this->data['plesk_subscription_id'] ?? 'N/A',
'ftp_username' => $this->data['ftp_username'] ?? 'N/A',
'ftp_password_row' => $row('🔑 FTP Password', $this->data['ftp_password'] ?? null),
'plesk_panel_url' => $this->data['plesk_panel_url'] ?? 'N/A',
'plesk_login' => $this->data['plesk_login'] ?? 'N/A',
'plesk_password_row' => $row('🔑 Password', $this->data['plesk_password'] ?? null),
'company_name' => $this->data['company_name'] ?? 'Portal Admin',
];
}
}
@@ -2,6 +2,7 @@
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
@@ -10,22 +11,21 @@ use Illuminate\Queue\SerializesModels;
class ManualDepositPendingNotification extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: '[ADMIN] Yêu cầu nạp tiền chờ duyệt - ' . ($this->data['transaction_code'] ?? 'N/A'),
subject: $this->renderFromTemplate('admin_manual_deposit_pending', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.admin.manual-deposit-pending',
with: $this->data,
htmlString: $this->renderFromTemplate('admin_manual_deposit_pending', $this->vars())['html'],
);
}
@@ -33,4 +33,25 @@ class ManualDepositPendingNotification extends Mailable
{
return [];
}
private function vars(): array
{
return [
'transaction_code' => $this->data['transaction_code'] ?? 'N/A',
'created_at' => $this->data['created_at'] ?? now()->format('d/m/Y H:i:s'),
'customer_name' => $this->data['customer_name'] ?? 'N/A',
'customer_email' => $this->data['customer_email'] ?? 'N/A',
'customer_phone_row' => !empty($this->data['customer_phone'])
? '<tr><td>Số điện thoại</td><td>' . e($this->data['customer_phone']) . '</td></tr>'
: '',
'client_ip_row' => !empty($this->data['client_ip'])
? '<tr><td>IP gửi yêu cầu</td><td>' . e($this->data['client_ip']) . '</td></tr>'
: '',
'amount_formatted' => number_format((float) ($this->data['amount'] ?? 0), 0, ',', '.') . ' VNĐ',
'proof_row' => !empty($this->data['proof_image_url'])
? '<tr><td>Chứng từ</td><td><a href="' . e($this->data['proof_image_url']) . '">Xem chứng từ chuyển khoản</a></td></tr>'
: '',
'company_name' => $this->data['company_name'] ?? 'Portal Admin',
];
}
}
+30 -14
View File
@@ -2,33 +2,49 @@
namespace App\Mail\Admin;
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;
use Illuminate\Queue\SerializesModels;
class TicketAdminNotification extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(
public readonly mixed $ticket,
public readonly mixed $customer,
) {}
public function build(): static
public function envelope(): Envelope
{
return $this
->subject("[ADMIN] Ticket mới #{$this->ticket->ticket_num} — {$this->customer->email}")
->view('emails.admin.ticket-notification')
->with([
'ticketNum' => $this->ticket->ticket_num,
'subject' => $this->ticket->subject,
'room' => $this->ticket->room,
'description' => strip_tags($this->ticket->description),
'customerName' => trim($this->customer->firstname . ' ' . $this->customer->lastname),
'customerEmail' => $this->customer->email,
'ticketUrl' => config('app.frontend_url') . '/tickets/' . $this->ticket->ticket_num,
]);
return new Envelope(
subject: $this->renderFromTemplate('admin_ticket_notification', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('admin_ticket_notification', $this->vars())['html'],
);
}
private function vars(): array
{
$description = strip_tags($this->ticket->description ?? '');
return [
'ticket_num' => $this->ticket->ticket_num,
'subject_text' => $this->ticket->subject,
'room' => $this->ticket->room ?? 'N/A',
'customer_name' => trim($this->customer->firstname . ' ' . $this->customer->lastname) ?: 'N/A',
'customer_email'=> $this->customer->email,
'description' => mb_substr($description, 0, 500) . (mb_strlen($description) > 500 ? '…' : ''),
'ticket_url' => config('app.frontend_url') . '/tickets/' . $this->ticket->ticket_num,
];
}
}
+22 -4
View File
@@ -2,6 +2,7 @@
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
@@ -10,22 +11,21 @@ use Illuminate\Queue\SerializesModels;
class TrialRegistrationRequest extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: '[ADMIN] Yêu cầu dùng thử Cloud VPS - ' . ($this->data['customer_name'] ?? 'N/A'),
subject: $this->renderFromTemplate('admin_trial_registration_request', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.admin.trial-registration-request',
with: $this->data,
htmlString: $this->renderFromTemplate('admin_trial_registration_request', $this->vars())['html'],
);
}
@@ -33,4 +33,22 @@ class TrialRegistrationRequest extends Mailable
{
return [];
}
private function vars(): array
{
return [
'customer_name' => $this->data['customer_name'] ?? 'N/A',
'customer_email' => $this->data['customer_email'] ?? 'N/A',
'customer_phone' => $this->data['customer_phone'] ?? 'N/A',
'cpu' => $this->data['cpu'] ?? '-',
'ram' => $this->data['ram'] ?? '-',
'ssd' => $this->data['ssd'] ?? '-',
'os' => $this->data['os'] ?? '-',
'other_row' => !empty($this->data['other'])
? '<tr><td>Yêu cầu khác</td><td>' . e($this->data['other']) . '</td></tr>'
: '',
'company_name' => $this->data['company_name'] ?? 'Portal Admin',
'created_at' => $this->data['created_at'] ?? now()->format('d/m/Y H:i:s'),
];
}
}
+21 -5
View File
@@ -2,8 +2,8 @@
namespace App\Mail;
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,16 +11,32 @@ use Illuminate\Queue\SerializesModels;
class ChangePortRemote extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(
public string $vmName,
public string $newPort
) {}
public function build(): ChangePortRemote
public function envelope(): Envelope
{
return $this->subject('Port VPS của bạn đã được thay đổi')
->view('emails.vm_port_change');
return new Envelope(
subject: $this->renderFromTemplate('vm_port_change', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('vm_port_change', $this->vars())['html'],
);
}
private function vars(): array
{
return [
'vm_name' => $this->vmName,
'new_port' => $this->newPort,
];
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Mail\Concerns;
use App\Services\Email\EmailTemplateService;
/**
* Render subject+html từ Template DB (EmailTemplateService) theo scenario.
* Không còn fallback về Blade view — nếu template thiếu/tắt hoặc chứa
* variable không hợp lệ, exception sẽ propagate rõ ràng thay vì gửi email rỗng.
*/
trait RequiresDbTemplate
{
private ?array $dbRendered = null;
/** @return array{subject: string, html: string} */
protected function renderFromTemplate(string $scenario, array $vars): array
{
return $this->dbRendered ??= app(EmailTemplateService::class)->preview($scenario, $vars);
}
}
+27 -69
View File
@@ -2,9 +2,8 @@
namespace App\Mail;
use App\Models\Template;
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;
@@ -12,86 +11,45 @@ use Illuminate\Queue\SerializesModels;
class CreateHosting extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
protected $template = null;
protected $data;
/** @param int $template Không còn dùng — scenario cố định 'hosting_information'. Giữ tham số để không phá vỡ caller hiện tại. */
public function __construct($template = 0, public $data = []) {}
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($template = 0, $data = [])
{
$this->data = $data;
$this->template = Template::find($template);
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
public function envelope(): Envelope
{
return new Envelope(
subject: str_replace("{\$product_name}", $this->data['product_name'], $this->template->subject),
subject: $this->renderFromTemplate('hosting_information', $this->vars())['subject'],
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
public function content(): Content
{
return new Content(
view: 'emails.template',
with: [
'template' => str_replace(
[
"{\$company_name}",
"{\$company_logo}",
"{\$client_name}",
"{\$product_name}",
"{\$product_billing}",
"{\$product_price}",
"{\$service_host}",
"{\$service_username}",
"{\$service_password}",
"{\$service_password}",
"{\$ftp_account}",
"{\$ftp_password}",
],
[
$this->data['company_name'],
$this->data['company_logo'],
$this->data['client_name'],
$this->data['product_name'],
$this->data['product_billing'],
$this->data['product_price'],
$this->data['service_host'],
$this->data['service_username'],
$this->data['service_password'],
$this->data['service_due_exp'],
$this->data['ftp_account'],
$this->data['ftp_password'],
],
$this->template->message)
]
htmlString: $this->renderFromTemplate('hosting_information', $this->vars())['html'],
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
public function attachments(): array
{
return [];
}
private function vars(): array
{
return [
'company_name' => $this->data['company_name'] ?? '',
'company_logo' => $this->data['company_logo'] ?? '',
'client_name' => $this->data['client_name'] ?? '',
'product_name' => $this->data['product_name'] ?? '',
'product_billing' => $this->data['product_billing'] ?? '',
'product_price' => $this->data['product_price'] ?? '',
'service_host' => $this->data['service_host'] ?? '',
'service_username'=> $this->data['service_username'] ?? '',
'service_password'=> $this->data['service_password'] ?? '',
'service_due_exp' => $this->data['service_due_exp'] ?? '',
'ftp_account' => $this->data['ftp_account'] ?? '',
'ftp_password' => $this->data['ftp_password'] ?? '',
];
}
}
-96
View File
@@ -1,96 +0,0 @@
<?php
namespace App\Mail;
use App\Models\Template;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class CreateVirtualMachine extends Mailable
{
use Queueable, SerializesModels;
protected $template = null;
protected $data;
protected ?string $invoicePdf = null;
protected ?string $invoicePdfFileName = null;
public function __construct($template = 0, $data = [], ?string $invoicePdf = null, ?string $invoicePdfFileName = null)
{
$this->data = $data;
$this->template = Template::find($template);
$this->invoicePdf = $invoicePdf;
$this->invoicePdfFileName = $invoicePdfFileName;
}
public function envelope()
{
if (!$this->template) {
throw new \RuntimeException('Email template ID=2 (CreateVirtualMachine) not found in database.');
}
return new Envelope(
subject: str_replace("{\$os_name}", $this->data['os_name'] ?? '', $this->template->subject),
);
}
public function content()
{
if (!$this->template) {
throw new \RuntimeException('Email template ID=2 (CreateVirtualMachine) not found in database.');
}
return new Content(
view: 'emails.template',
with: [
'template' => str_replace(
[
"{\$company_name}",
"{\$company_logo}",
"{\$client_name}",
"{\$product_name}",
"{\$product_billing}",
"{\$product_price}",
"{\$service_host}",
"{\$service_username}",
"{\$service_port}",
"{\$service_password}",
"{\$os_name}",
"{\$service_due_exp}"
],
[
$this->data['company_name'],
$this->data['company_logo'],
$this->data['client_name'],
$this->data['product_name'],
$this->data['product_billing'],
$this->data['product_price'],
$this->data['service_host'],
$this->data['service_username'],
$this->data['service_port'],
$this->data['service_password'],
$this->data['os_name'],
$this->data['service_due_exp'],
],
$this->template->message)
]
);
}
public function attachments(): array
{
if ($this->invoicePdf !== null && $this->invoicePdfFileName !== null) {
return [
Attachment::fromData(fn () => $this->invoicePdf, $this->invoicePdfFileName)
->withMime('application/pdf'),
];
}
return [];
}
}
+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 {
+18 -50
View File
@@ -2,9 +2,8 @@
namespace App\Mail;
use App\Models\Template;
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;
@@ -12,67 +11,36 @@ use Illuminate\Queue\SerializesModels;
class CustomerRegister 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_signup_verify'. Giữ tham số để không phá vỡ caller hiện tại. */
public function __construct($template = 0, public $data = []) {}
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($template = 0,$data = [])
{
$this->data = $data;
$this->template = Template::find($template);
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
public function envelope(): Envelope
{
return new Envelope(
subject: $this->template->subject,
subject: $this->renderFromTemplate('customer_signup_verify', $this->vars())['subject'],
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
public function content(): Content
{
return new Content(
view: 'emails.template',
with: [
'template' => str_replace(
[
"{\$company_name}",
"{\$company_logo}",
"{\$link_verify}",
],
[
$this->data['company_name'],
$this->data['company_logo'],
$this->data['link_verify'],
],
$this->template->message)
]
htmlString: $this->renderFromTemplate('customer_signup_verify', $this->vars())['html'],
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
public function attachments(): array
{
return [];
}
private function vars(): array
{
return [
'company_name' => $this->data['company_name'] ?? '',
'company_logo' => $this->data['company_logo'] ?? '',
'link_verify' => $this->data['link_verify'] ?? '',
];
}
}
+20 -56
View File
@@ -2,9 +2,8 @@
namespace App\Mail;
use App\Models\Template;
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;
@@ -12,73 +11,38 @@ use Illuminate\Queue\SerializesModels;
class ExpiryService extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
protected $template = null;
protected $data;
/** @param int $template Không còn dùng — scenario cố định 'service_expiry'. Giữ tham số để không phá vỡ caller hiện tại. */
public function __construct($template = 0, public $data = []) {}
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($template = 0, $data = [])
{
$this->data = $data;
$this->template = Template::find($template);
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
public function envelope(): Envelope
{
return new Envelope(
subject: $this->template->subject
subject: $this->renderFromTemplate('service_expiry', $this->vars())['subject'],
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
public function content(): Content
{
return new Content(
view: 'emails.template',
with: [
'template' => str_replace(
[
"{\$company_name}",
"{\$company_logo}",
"{\$client_name}",
"{\$product_name}",
"{\$service_due_exp}",
"{\$service_remaining}"
],
[
$this->data['company_name'],
$this->data['company_logo'],
$this->data['client_name'],
$this->data['product_name'],
$this->data['service_due_exp'],
$this->data['service_remaining'],
],
$this->template->message)
]
htmlString: $this->renderFromTemplate('service_expiry', $this->vars())['html'],
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
public function attachments(): array
{
return [];
}
private function vars(): array
{
return [
'company_name' => $this->data['company_name'] ?? '',
'company_logo' => $this->data['company_logo'] ?? '',
'product_name' => $this->data['product_name'] ?? '',
'service_due_exp' => $this->data['service_due_exp'] ?? '',
'service_remaining' => $this->data['service_remaining'] ?? '',
];
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
/**
* Mailable dùng chung cho mọi email render từ Template (EmailTemplateService).
* Không hardcode from/replyTo — lấy từ mailConfig của template, null thì Laravel
* tự fallback về config('mail.from') mặc định.
*/
class GenericTemplateMail extends Mailable
{
use Queueable, SerializesModels;
public function __construct(
public readonly string $renderedSubject,
public readonly string $renderedHtml,
public readonly array $mailConfig = [],
) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderedSubject,
from: $this->address($this->mailConfig['from_email'] ?? null, $this->mailConfig['from_name'] ?? null),
replyTo: array_filter([$this->address($this->mailConfig['reply_to'] ?? null, $this->mailConfig['reply_to_name'] ?? null)]),
cc: $this->mailConfig['cc'] ?? [],
bcc: $this->mailConfig['bcc'] ?? [],
);
}
public function content(): Content
{
return new Content(htmlString: $this->renderedHtml);
}
private function address(?string $email, ?string $name): ?Address
{
return $email ? new Address($email, $name) : null;
}
}
+17 -50
View File
@@ -2,9 +2,8 @@
namespace App\Mail;
use App\Models\Template;
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;
@@ -12,67 +11,35 @@ use Illuminate\Queue\SerializesModels;
class PasswordReset extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
protected $template = null;
protected $data;
public function __construct(public $data = []) {}
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data = [])
{
$this->data = $data;
$this->template = Template::find(4);
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
public function envelope(): Envelope
{
return new Envelope(
subject: $this->template->subject,
subject: $this->renderFromTemplate('customer_password_reset', $this->vars())['subject'],
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
public function content(): Content
{
return new Content(
view: 'emails.template',
with: [
'template' => str_replace(
[
"{\$company_name}",
"{\$company_logo}",
"{\$password}",
],
[
$this->data['company_name'],
$this->data['company_logo'],
$this->data['password'],
],
$this->template->message)
]
htmlString: $this->renderFromTemplate('customer_password_reset', $this->vars())['html'],
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
public function attachments(): array
{
return [];
}
private function vars(): array
{
return [
'company_name' => $this->data['company_name'] ?? '',
'company_logo' => $this->data['company_logo'] ?? '',
'password' => $this->data['password'] ?? '',
];
}
}
+29 -16
View File
@@ -2,6 +2,7 @@
namespace App\Mail;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Customer;
use App\Models\Service;
use Illuminate\Bus\Queueable;
@@ -12,7 +13,7 @@ use Illuminate\Queue\SerializesModels;
class ServiceRenewalReminderMail extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(
public readonly Customer $customer,
@@ -21,26 +22,38 @@ class ServiceRenewalReminderMail extends Mailable
public function envelope(): Envelope
{
$name = $this->service->server_name ?? $this->service->product?->name ?? 'dịch vụ';
return new Envelope(subject: "Nhắc gia hạn dịch vụ {$name}");
return new Envelope(
subject: $this->renderFromTemplate('service_renewal_reminder', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.customer.service-renewal-reminder',
with: [
'clientName' => $this->customer->fullname ?? '',
'productName' => $this->service->product?->name ?? 'Dịch vụ',
'serverName' => $this->service->server_name ?? '',
'expiresAt' => $this->service->expires_at
? \Carbon\Carbon::parse($this->service->expires_at)->format('d/m/Y')
: 'N/A',
'price' => $this->service->orderItem?->price
? number_format((float) $this->service->orderItem->price, 0, ',', '.')
: null,
],
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',
];
}
}
+22 -10
View File
@@ -2,6 +2,7 @@
namespace App\Mail;
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 TicketCreated extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(
public readonly mixed $ticket,
@@ -21,21 +22,14 @@ class TicketCreated extends Mailable implements ShouldQueue
public function envelope(): Envelope
{
return new Envelope(
subject: "[#{$this->ticket->ticket_num}] Yêu cầu hỗ trợ của bạn đã được tiếp nhận",
subject: $this->renderFromTemplate('ticket_created', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.customer.ticket-created',
with: [
'fullName' => trim("{$this->customer->firstname} {$this->customer->lastname}") ?: 'Quý khách',
'ticketNum' => $this->ticket->ticket_num,
'subject' => $this->ticket->subject,
'room' => $this->ticket->room,
'ticketUrl' => rtrim(config('app.frontend_url', ''), '/') . '/tickets/' . $this->ticket->ticket_num,
],
htmlString: $this->renderFromTemplate('ticket_created', $this->vars())['html'],
);
}
@@ -43,4 +37,22 @@ class TicketCreated extends Mailable implements ShouldQueue
{
return [];
}
private function vars(): array
{
$room = $this->ticket->room ?? null;
return [
'full_name' => trim("{$this->customer->firstname} {$this->customer->lastname}") ?: 'Quý khách',
'ticket_num' => $this->ticket->ticket_num,
'subject' => $this->ticket->subject,
'room_row' => $room
? '<tr><td style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; color: #666666; padding: 4px 0;" valign="top">Phòng ban:</td><td style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; color: #000000; padding: 4px 0;" valign="top">' . $room . '</td></tr>'
: '',
'ticket_url' => rtrim(config('app.frontend_url', ''), '/') . '/tickets/' . $this->ticket->ticket_num,
'app_name' => config('app.name', 'Thế Giới Số'),
'support_email' => 'support@tgs.com.vn',
'support_phone' => '(028) 7309. 7379',
];
}
}
-72
View File
@@ -1,72 +0,0 @@
<?php
namespace App\Mail;
use App\Models\EmailNotificationTemplate;
use App\Models\Invoice;
use App\Services\EmailNotificationTemplateRenderer;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Support\Facades\Log;
/**
* Gửi thông tin VPS + đính kèm PDF hoá đơn.
*
* KHÔNG implement ShouldQueue — mailable này được gọi từ bên trong
* SendInformationVirtualMachine (đã là queued job). Gửi đồng bộ để
* tránh Laravel cố JSON-encode $invoicePdf (binary PDF).
*/
class VmCredentialsMail extends Mailable
{
public function __construct(
public readonly EmailNotificationTemplate $template,
public readonly array $emailData,
public readonly ?Invoice $invoice,
public readonly ?string $invoicePdf,
public readonly ?string $invoicePdfFileName,
) {}
public function envelope(): Envelope
{
$subject = str_replace(
['{{os_name}}', '{{client_name}}', '{{company_name}}'],
[
$this->emailData['os_name'] ?? '',
$this->emailData['client_name'] ?? '',
$this->emailData['company_name'] ?? '',
],
$this->template->subject
);
return new Envelope(subject: $subject);
}
public function content(): Content
{
try {
$renderer = app(EmailNotificationTemplateRenderer::class);
$html = $renderer->renderVmCredentials($this->template, $this->emailData, $this->invoice);
return new Content(htmlString: $html);
} catch (\Throwable $e) {
Log::warning('VmCredentialsMail: renderer failed, falling back to plain message', [
'template_id' => $this->template->id,
'error' => $e->getMessage(),
]);
return new Content(htmlString: '<p>Thông tin dịch vụ đã được chuẩn bị. Vui lòng liên hệ hỗ trợ nếu cần.</p>');
}
}
public function attachments(): array
{
if ($this->invoicePdf !== null && $this->invoicePdfFileName !== null) {
return [
Attachment::fromData(fn() => $this->invoicePdf, $this->invoicePdfFileName)
->withMime('application/pdf'),
];
}
return [];
}
}
+23 -4
View File
@@ -2,22 +2,41 @@
namespace App\Mail;
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 VmPasswordResetSuccess extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(
public string $vmName,
public string $newPassword
) {}
public function build()
public function envelope(): Envelope
{
return $this->subject('Mật khẩu VPS của bạn đã được đặt lại')
->view('emails.vm_password_reset_success');
return new Envelope(
subject: $this->renderFromTemplate('vm_password_reset_success', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('vm_password_reset_success', $this->vars())['html'],
);
}
private function vars(): array
{
return [
'vm_name' => $this->vmName,
'new_password' => $this->newPassword,
];
}
}
+17 -8
View File
@@ -2,6 +2,7 @@
namespace App\Mail;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Customer;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -12,7 +13,7 @@ use Illuminate\Queue\SerializesModels;
class VmSuspendedMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(
public readonly Customer $customer,
@@ -23,19 +24,14 @@ class VmSuspendedMail extends Mailable implements ShouldQueue
public function envelope(): Envelope
{
return new Envelope(
subject: '[Thế Giới Số] Dịch vụ Cloud VPS của bạn đã bị tạm ngưng',
subject: $this->renderFromTemplate('vm_suspended', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
view: 'emails.customer.vm-suspended',
with: [
'customerName' => $this->customer->fullname,
'vmName' => $this->vmName,
'vmwareId' => $this->vmwareId,
],
htmlString: $this->renderFromTemplate('vm_suspended', $this->vars())['html'],
);
}
@@ -43,4 +39,17 @@ class VmSuspendedMail extends Mailable implements ShouldQueue
{
return [];
}
private function vars(): array
{
return [
'customer_name' => $this->customer->fullname,
'vm_name' => $this->vmName,
'vmware_id' => $this->vmwareId,
'suspended_at' => now()->setTimezone('Asia/Ho_Chi_Minh')->format('d/m/Y H:i'),
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
'support_email' => 'support@tgs.com.vn',
'support_phone' => '(028) 7309. 7379',
];
}
}