91 lines
4.6 KiB
PHP
91 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Mail\Customer;
|
|
|
|
use App\Mail\Concerns\RequiresDbTemplate;
|
|
use App\Models\Setting;
|
|
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
|
|
{
|
|
use Queueable, SerializesModels, RequiresDbTemplate;
|
|
|
|
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
|
|
{
|
|
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);
|
|
}
|
|
|
|
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'),
|
|
];
|
|
}
|
|
}
|