Files
portal-api/app/Mail/Customer/SnapshotActionMail.php

74 lines
2.7 KiB
PHP

<?php
namespace App\Mail\Customer;
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 SnapshotActionMail extends Mailable
{
use Queueable, SerializesModels;
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}");
}
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'),
],
);
}
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);
}
}