Files
portal-api/app/Mail/Customer/ManualDepositStatus.php
T
2026-09-09 16:56:22 +07:00

80 lines
3.2 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 ManualDepositStatus extends Mailable
{
use Queueable, SerializesModels, RequiresDbTemplate;
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
{
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);
}
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'),
];
}
}