This commit is contained in:
baodev0
2026-10-05 09:30:24 +07:00
parent a1aeb88061
commit 1544629a1f
53 changed files with 1292 additions and 963 deletions
+9 -21
View File
@@ -4,39 +4,27 @@ declare(strict_types=1);
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class AdminOrderNotification extends Mailable
class AdminOrderNotification extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public readonly array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('admin_order_notification', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('admin_order_notification', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'admin_order_notification';
}
protected function variables(): array
{
$vmFields = ['ip' => '🌐 IP Address', 'username' => '👤 Username', 'password' => '🔑 Password'];
$vmRows = '';
+6 -18
View File
@@ -2,37 +2,25 @@
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
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 DomainOrderNewNotification extends Mailable implements ShouldQueue
class DomainOrderNewNotification extends TemplateMailable implements ShouldQueue
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(
protected array $data,
) {}
public function envelope(): Envelope
protected function scenario(): string
{
return new Envelope(
subject: $this->renderFromTemplate('admin_domain_order_new', $this->vars())['subject'],
);
return 'admin_domain_order_new';
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('admin_domain_order_new', $this->vars())['html'],
);
}
private function vars(): array
protected function variables(): array
{
return [
'company_name' => $this->data['company_name'] ?? config('app.name'),
@@ -4,39 +4,27 @@ declare(strict_types=1);
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class HostingAccountCreatedAdminNotification extends Mailable
class HostingAccountCreatedAdminNotification extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public readonly array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('admin_hosting_account_created', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('admin_hosting_account_created', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'admin_hosting_account_created';
}
protected function variables(): 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>'
@@ -2,39 +2,27 @@
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class ManualDepositPendingNotification extends Mailable
class ManualDepositPendingNotification extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('admin_manual_deposit_pending', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('admin_manual_deposit_pending', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'admin_manual_deposit_pending';
}
protected function variables(): array
{
return [
'transaction_code' => $this->data['transaction_code'] ?? 'N/A',
+6 -18
View File
@@ -2,38 +2,26 @@
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
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
class TicketAdminNotification extends TemplateMailable implements ShouldQueue
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(
public readonly mixed $ticket,
public readonly mixed $customer,
) {}
public function envelope(): Envelope
protected function scenario(): string
{
return new Envelope(
subject: $this->renderFromTemplate('admin_ticket_notification', $this->vars())['subject'],
);
return 'admin_ticket_notification';
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('admin_ticket_notification', $this->vars())['html'],
);
}
private function vars(): array
protected function variables(): array
{
$description = strip_tags($this->ticket->description ?? '');
+9 -21
View File
@@ -2,39 +2,27 @@
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class TrialRegistrationRequest extends Mailable
class TrialRegistrationRequest extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('admin_trial_registration_request', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('admin_trial_registration_request', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'admin_trial_registration_request';
}
protected function variables(): array
{
return [
'customer_name' => $this->data['customer_name'] ?? 'N/A',
@@ -0,0 +1,25 @@
<?php
namespace App\Mail\Concerns;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Envelope;
trait BuildsTemplateEnvelope
{
protected function templateEnvelope(string $subject, array $mailConfig): Envelope
{
return new Envelope(
subject: $subject,
from: $this->templateAddress($mailConfig['from_email'] ?? null, $mailConfig['from_name'] ?? null),
replyTo: array_filter([$this->templateAddress($mailConfig['reply_to'] ?? null, $mailConfig['reply_to_name'] ?? null)]),
cc: $mailConfig['cc'] ?? [],
bcc: $mailConfig['bcc'] ?? [],
);
}
private function templateAddress(?string $email, ?string $name): ?Address
{
return $email ? new Address($email, $name) : null;
}
}
-21
View File
@@ -1,21 +0,0 @@
<?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);
}
}
+8 -21
View File
@@ -2,40 +2,27 @@
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 CreateHosting extends Mailable
class CreateHosting extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
/** @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 = []) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('hosting_information', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('hosting_information', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'hosting_information';
}
protected function variables(): array
{
return [
'company_name' => $this->data['company_name'] ?? '',
+6 -18
View File
@@ -2,16 +2,13 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class DepositSuccess extends Mailable
class DepositSuccess extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public array $data;
@@ -20,21 +17,12 @@ class DepositSuccess extends Mailable
$this->data = $data;
}
public function envelope(): Envelope
protected function scenario(): string
{
return new Envelope(
subject: $this->renderFromTemplate('customer_deposit_success', $this->vars())['subject'],
);
return 'customer_deposit_success';
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('customer_deposit_success', $this->vars())['html'],
);
}
private function vars(): array
protected function variables(): array
{
return [
'customer_name' => $this->data['customer_name'] ?? 'Khách hàng',
@@ -2,37 +2,25 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
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 DomainOrderReceivedNotification extends Mailable implements ShouldQueue
class DomainOrderReceivedNotification extends TemplateMailable implements ShouldQueue
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(
protected array $data,
) {}
public function envelope(): Envelope
protected function scenario(): string
{
return new Envelope(
subject: $this->renderFromTemplate('domain_order_received', $this->vars())['subject'],
);
return 'domain_order_received';
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('domain_order_received', $this->vars())['html'],
);
}
private function vars(): array
protected function variables(): array
{
return [
'customer_name' => $this->data['customer_name'] ?? 'Quý khách',
+8 -40
View File
@@ -2,59 +2,30 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class HostingAccountCreated extends Mailable
class HostingAccountCreated extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('hosting_account_created', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('hosting_account_created', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function payload(): array
protected function scenario(): string
{
try {
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
} catch (\Throwable) {
$settingValue = [];
}
return array_merge([
'company_name' => $settingValue['company'] ?? config('app.name', 'The Gioi So'),
'support_email' => $settingValue['email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
], $this->data);
return 'hosting_account_created';
}
private function vars(): array
protected function variables(): array
{
$data = $this->payload();
$data = [...MailGlobals::values(), ...$this->data];
$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>"
@@ -82,9 +53,6 @@ class HostingAccountCreated extends Mailable
? '<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'),
];
}
}
+9 -42
View File
@@ -2,64 +2,33 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class ManualDepositStatus extends Mailable
class ManualDepositStatus extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('manual_deposit_status', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('manual_deposit_status', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function payload(): array
protected function scenario(): string
{
try {
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
} catch (\Throwable) {
$settingValue = [];
}
return array_merge([
'company_name' => $settingValue['company'] ?? config('app.name', 'The Gioi So'),
'company_logo' => $settingValue['logo'] ?? '',
'support_email' => $settingValue['email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
'portal_url' => rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/nap-tien',
], $this->data);
return 'manual_deposit_status';
}
private function vars(): array
protected function variables(): array
{
$data = $this->payload();
$data = [...MailGlobals::values(), ...$this->data];
$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, ',', '.'),
@@ -71,9 +40,7 @@ class ManualDepositStatus extends Mailable
'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'),
'portal_url' => $data['portal_url'] ?? MailGlobals::frontendUrl() . '/nap-tien',
];
}
}
+8 -40
View File
@@ -2,68 +2,36 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class PasswordResetByAdmin extends Mailable
class PasswordResetByAdmin extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('password_reset_admin', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('password_reset_admin', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function payload(): array
protected function scenario(): string
{
try {
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
} catch (\Throwable) {
$settingValue = [];
}
return array_merge([
'company_name' => $settingValue['company'] ?? config('app.name', 'The Gioi So'),
'support_email' => $settingValue['email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
], $this->data);
return 'password_reset_admin';
}
private function vars(): array
protected function variables(): array
{
$data = $this->payload();
$data = [...MailGlobals::values(), ...$this->data];
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'),
];
}
}
+6 -18
View File
@@ -2,34 +2,22 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class PasswordResetLink extends Mailable
class PasswordResetLink extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public array $data) {}
public function envelope(): Envelope
protected function scenario(): string
{
return new Envelope(
subject: $this->renderFromTemplate('customer_password_reset_link', $this->vars())['subject'],
);
return 'customer_password_reset_link';
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('customer_password_reset_link', $this->vars())['html'],
);
}
private function vars(): array
protected function variables(): array
{
return [
'full_name' => $this->data['fullname'] ?? 'Quý khách',
+8 -40
View File
@@ -2,17 +2,14 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class SnapshotActionMail extends Mailable
class SnapshotActionMail extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
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 ✓'],
@@ -22,45 +19,19 @@ class SnapshotActionMail extends Mailable
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('snapshot_action', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('snapshot_action', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function payload(): array
protected function scenario(): string
{
try {
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
} catch (\Throwable) {
$settingValue = [];
}
return array_merge([
'company_name' => $settingValue['company'] ?? config('app.name', 'The Gioi So'),
'support_email' => $settingValue['email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
], $this->data);
return 'snapshot_action';
}
private function vars(): array
protected function variables(): array
{
$data = $this->payload();
$data = [...MailGlobals::values(), ...$this->data];
$label = self::LABELS[$data['action'] ?? 'create'] ?? self::LABELS['create'];
return [
@@ -73,9 +44,6 @@ class SnapshotActionMail extends Mailable
'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'),
];
}
}
+11 -22
View File
@@ -2,16 +2,14 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class VMCreationFailed extends Mailable
class VMCreationFailed extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public array $data;
@@ -20,33 +18,24 @@ class VMCreationFailed extends Mailable
$this->data = $data;
}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('vm_creation_failed', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('vm_creation_failed', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'vm_creation_failed';
}
protected function variables(): 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'] ?? ''),
'invoice_url' => MailGlobals::frontendUrl() . '/hoa-don/' . ($this->data['order_id'] ?? ''),
'support_email' => config('mail.support_email', 'support@example.com'),
'support_phone' => config('mail.support_phone', '1900-xxxx'),
];
+8 -38
View File
@@ -2,65 +2,35 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class VerifyAccount extends Mailable
class VerifyAccount extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('verify_account_welcome', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('verify_account_welcome', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function payload(): array
protected function scenario(): string
{
try {
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
} catch (\Throwable) {
$settingValue = [];
}
return array_merge([
'company_name' => $settingValue['company'] ?? config('app.name', 'The Gioi So'),
'support_email' => $settingValue['email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
], $this->data);
return 'verify_account_welcome';
}
private function vars(): array
protected function variables(): array
{
$data = $this->payload();
$data = [...MailGlobals::values(), ...$this->data];
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'),
];
}
}
+8 -39
View File
@@ -2,22 +2,19 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
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;
/**
* Email thông tin truy cập VPS sau khi khởi tạo — render từ Template DB
* (scenario=vm_credentials), thay cho blade tĩnh send-info-vps trước đây.
*/
class VmCredentials extends Mailable
class VmCredentials extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(
public array $data,
@@ -25,20 +22,6 @@ class VmCredentials extends Mailable
public readonly ?string $invoicePdfFileName = null,
) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('vm_credentials', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('vm_credentials', $this->vars())['html'],
);
}
public function attachments(): array
{
if ($this->invoicePdf !== null && $this->invoicePdfFileName !== null) {
@@ -51,25 +34,14 @@ class VmCredentials extends Mailable
return [];
}
private function payload(): array
protected function scenario(): string
{
try {
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
} catch (\Throwable) {
$settingValue = [];
}
return array_merge([
'support_email' => $settingValue['email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
'login_url' => rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/dang-nhap',
], $this->data);
return 'vm_credentials';
}
private function vars(): array
protected function variables(): array
{
$data = $this->payload();
$data = [...MailGlobals::values(), ...$this->data];
$row = fn (string $label, ?string $value) => $value
? "<tr bgcolor=\"#FFF1E6\"><td style=\"padding: 7px 11px; border-right: 1px solid #e8e8e8; width: 200px;\">{$label}</td><td style=\"padding: 7px 11px; border-right: 1px solid #e8e8e8;\"><strong>{$value}</strong></td></tr>"
@@ -87,9 +59,6 @@ class VmCredentials extends Mailable
'service_password' => $data['service_password'] ?? '',
'service_port_row' => $row('Cổng kết nối:', $data['service_port'] ?? null),
'service_due_exp_row' => $row('Hạn sử dụng:', $data['service_due_exp'] ?? null),
'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'),
];
}
}
+8 -40
View File
@@ -2,59 +2,30 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class VmPasswordChanged extends Mailable
class VmPasswordChanged extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('vm_password_changed', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('vm_password_changed', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function payload(): array
protected function scenario(): string
{
try {
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
} catch (\Throwable) {
$settingValue = [];
}
return array_merge([
'company_name' => $settingValue['company'] ?? config('app.name', 'The Gioi So'),
'support_email' => $settingValue['email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
'login_url' => rtrim(config('app.frontend_url', ''), '/') . '/dang-nhap',
], $this->data);
return 'vm_password_changed';
}
private function vars(): array
protected function variables(): array
{
$data = $this->payload();
$data = [...MailGlobals::values(), ...$this->data];
$newPassword = $data['newPassword'] ?? '';
return [
@@ -64,9 +35,6 @@ class VmPasswordChanged extends Mailable
'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'),
];
}
}
+11 -22
View File
@@ -2,16 +2,14 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class VmRebuildFailed extends Mailable
class VmRebuildFailed extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public array $data;
@@ -20,33 +18,24 @@ class VmRebuildFailed extends Mailable
$this->data = $data;
}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('vm_rebuild_failed', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('vm_rebuild_failed', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'vm_rebuild_failed';
}
protected function variables(): 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',
'service_url' => MailGlobals::frontendUrl() . '/dich-vu',
'support_email' => config('mail.support_email', 'support@example.com'),
'support_phone' => config('mail.support_phone', '1900-xxxx'),
];
+11 -43
View File
@@ -2,66 +2,34 @@
namespace App\Mail\Customer;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Setting;
use App\Mail\TemplateMailable;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class Welcome extends Mailable
class Welcome extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(public array $data) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('customer_welcome', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('customer_welcome', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
$data = $this->payload();
return 'customer_welcome';
}
protected function variables(): array
{
$data = [...MailGlobals::values(), ...$this->data];
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 {
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
} catch (\Throwable) {
$settingValue = [];
}
return array_merge([
'company_name' => $settingValue['company'] ?? config('app.name', 'The Gioi So'),
'support_email' => $settingValue['email'] ?? config('mail.support_email', 'support@thegioiso.com'),
'support_phone' => $settingValue['hotline'] ?? ($settingValue['phone'] ?? config('mail.support_phone', '1900.xxxx')),
'login_url' => rtrim(env('FRONTEND_URL', config('app.url')), '/') . '/dang-nhap',
], $this->data);
}
}
+8 -21
View File
@@ -2,40 +2,27 @@
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 ExpiryService extends Mailable
class ExpiryService extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
/** @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 = []) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('service_expiry', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('service_expiry', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'service_expiry';
}
protected function variables(): array
{
return [
'company_name' => $this->data['company_name'] ?? '',
+3 -14
View File
@@ -2,9 +2,9 @@
namespace App\Mail;
use App\Mail\Concerns\BuildsTemplateEnvelope;
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;
@@ -16,7 +16,7 @@ use Illuminate\Queue\SerializesModels;
*/
class GenericTemplateMail extends Mailable
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, BuildsTemplateEnvelope;
public function __construct(
public readonly string $renderedSubject,
@@ -26,22 +26,11 @@ class GenericTemplateMail extends Mailable
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'] ?? [],
);
return $this->templateEnvelope($this->renderedSubject, $this->mailConfig);
}
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;
}
}
+7 -22
View File
@@ -3,15 +3,11 @@
namespace App\Mail;
use App\Enums\Invoice\InvoiceStatus;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Invoice;
use App\Services\InvoicePaymentService;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
/**
* KHÔNG implement ShouldQueue — gọi từ trong queued job, gửi đồng bộ.
@@ -20,10 +16,8 @@ use Illuminate\Mail\Mailables\Envelope;
* đi qua bảng email_notification_templates riêng và rơi về blade khi không có template —
* hai hệ template song song cho cùng một email, admin sửa một nơi thì nơi kia vẫn nguyên.
*/
class InvoiceNotificationMail extends Mailable
class InvoiceNotificationMail extends TemplateMailable
{
use RequiresDbTemplate;
public function __construct(
public readonly Invoice $invoice,
public readonly Collection $invoiceAttachments,
@@ -36,20 +30,6 @@ class InvoiceNotificationMail extends Mailable
public readonly ?string $paymentUrl = null,
) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('invoice_notification', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('invoice_notification', $this->vars())['html'],
);
}
public function attachments(): array
{
if ($this->invoicePdf !== null && $this->invoicePdfFileName !== null) {
@@ -62,7 +42,12 @@ class InvoiceNotificationMail extends Mailable
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'invoice_notification';
}
protected function variables(): array
{
$isRenewal = $this->type === 'renewal';
+5 -18
View File
@@ -2,39 +2,26 @@
namespace App\Mail;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\Customer;
use App\Models\Service;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class ServiceRenewalReminderMail extends Mailable
class ServiceRenewalReminderMail extends TemplateMailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(
public readonly Customer $customer,
public readonly Service $service,
) {}
public function envelope(): Envelope
protected function scenario(): string
{
return new Envelope(
subject: $this->renderFromTemplate('service_renewal_reminder', $this->vars())['subject'],
);
return 'service_renewal_reminder';
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('service_renewal_reminder', $this->vars())['html'],
);
}
private function vars(): array
protected function variables(): array
{
$serverName = $this->service->server_name ?? '';
$price = $this->service->orderItem?->price
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace App\Mail;
use App\Mail\Concerns\BuildsTemplateEnvelope;
use App\Models\Template;
use App\Services\Email\EmailTemplateRenderer;
use App\Services\Email\EmailTemplateService;
use App\Support\MailGlobals;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
abstract class TemplateMailable extends Mailable
{
use BuildsTemplateEnvelope;
private ?array $rendered = null;
abstract protected function scenario(): string;
/**
* @return array<string, mixed>
*/
abstract protected function variables(): array;
public function envelope(): Envelope
{
return $this->templateEnvelope($this->rendered()['subject'], $this->template()->mailConfig());
}
public function content(): Content
{
return new Content(htmlString: $this->rendered()['html']);
}
/**
* @return array{subject: string, html: string}
*/
private function rendered(): array
{
return $this->rendered ??= app(EmailTemplateRenderer::class)->render(
$this->template(),
[...MailGlobals::values(), ...$this->variables()],
);
}
private function template(): Template
{
return app(EmailTemplateService::class)->loadTemplate($this->scenario());
}
}
+8 -21
View File
@@ -2,43 +2,30 @@
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;
use Illuminate\Queue\SerializesModels;
class TicketCreated extends Mailable implements ShouldQueue
class TicketCreated extends TemplateMailable implements ShouldQueue
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(
public readonly mixed $ticket,
public readonly mixed $customer,
) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('ticket_created', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('ticket_created', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'ticket_created';
}
protected function variables(): array
{
$room = $this->ticket->room ?? null;
+8 -21
View File
@@ -2,18 +2,14 @@
namespace App\Mail;
use App\Mail\Concerns\RequiresDbTemplate;
use App\Models\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 VmSuspendedMail extends Mailable implements ShouldQueue
class VmSuspendedMail extends TemplateMailable implements ShouldQueue
{
use Queueable, SerializesModels, RequiresDbTemplate;
use Queueable, SerializesModels;
public function __construct(
public readonly Customer $customer,
@@ -21,26 +17,17 @@ class VmSuspendedMail extends Mailable implements ShouldQueue
public readonly string $vmwareId,
) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('vm_suspended', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('vm_suspended', $this->vars())['html'],
);
}
public function attachments(): array
{
return [];
}
private function vars(): array
protected function scenario(): string
{
return 'vm_suspended';
}
protected function variables(): array
{
return [
'customer_name' => $this->customer->fullname,