feat(admin): improve payments and server settings
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Jobs\Mail\Admin\AdminPaymentReceivedJob;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Notification;
|
||||
|
||||
class AdminPaymentNotifier
|
||||
{
|
||||
public function notify(Invoice $invoice, int $amount, string $paymentType): void
|
||||
{
|
||||
$invoice->loadMissing(['customer', 'order']);
|
||||
$outstanding = InvoicePaymentService::outstanding($invoice);
|
||||
$reference = $invoice->order?->order_num ?? $invoice->invoice_number;
|
||||
$label = $paymentType === 'order' ? 'đơn hàng' : 'hóa đơn';
|
||||
$amountFormatted = number_format($amount, 0, ',', '.') . ' VNĐ';
|
||||
|
||||
Notification::notifyAdmins([
|
||||
'type' => 'payment_received',
|
||||
'title' => 'Khách hàng thanh toán ' . $label,
|
||||
'body' => "{$invoice->customer->fullname} đã thanh toán {$amountFormatted} cho {$label} #{$reference}.",
|
||||
'link' => '/order-invoice',
|
||||
'data' => [
|
||||
'invoice_id' => $invoice->id,
|
||||
'order_id' => $invoice->order_id,
|
||||
'amount' => $amount,
|
||||
'outstanding' => $outstanding,
|
||||
],
|
||||
]);
|
||||
|
||||
AdminPaymentReceivedJob::dispatch([
|
||||
'payment_type' => $paymentType === 'order' ? 'Đơn hàng' : 'Hóa đơn',
|
||||
'reference' => $reference,
|
||||
'invoice_number' => $invoice->invoice_number,
|
||||
'customer_name' => (string) $invoice->customer->fullname,
|
||||
'customer_email' => (string) $invoice->customer->email,
|
||||
'amount' => $amount,
|
||||
'outstanding' => $outstanding,
|
||||
'created_at' => now()->format('d/m/Y H:i:s'),
|
||||
])->afterCommit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user