feat(service): huỷ dịch vụ, SSL, đổi mật khẩu hosting, lịch sử thanh toán theo hình thức
- Lịch sử thanh toán hoá đơn trả thêm `method` (tự động gia hạn / số dư / admin / chuyển khoản / hoàn tiền), bỏ đuôi `(method)` khỏi ghi chú - `DnsServer::panelUrl()` = https://<domain>/ dùng cho email cấp hosting và nút Plesk của khách - Order item trả thêm `uuid`/`type` của dịch vụ để FE dẫn tới trang quản lý - Yêu cầu huỷ dịch vụ, chứng chỉ SSL, lịch sử gia hạn, đổi mật khẩu hosting cho khách Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
a6b641015e
commit
b44a88bb52
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Mail\ServiceRenewedMail;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Service;
|
||||
use App\Models\Setting;
|
||||
use App\Support\AutoEmailGate;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class CustomerRenewalNotifier
|
||||
{
|
||||
public const SCENARIO = 'admin_customer_service_renewed';
|
||||
|
||||
public const SOURCE_CUSTOMER = 'customer';
|
||||
|
||||
public const SOURCE_SYSTEM = 'system';
|
||||
|
||||
public function notify(Service $service, Invoice $invoice, int $months, ?CarbonInterface $previousExpiresAt, string $source): void
|
||||
{
|
||||
$service->loadMissing(['customer', 'product']);
|
||||
$customer = $service->customer;
|
||||
if (! $customer) {
|
||||
return;
|
||||
}
|
||||
|
||||
$productName = $service->product?->name ?? 'Dịch vụ';
|
||||
$serverName = (string) $service->server_name;
|
||||
$expiresAt = $service->expires_at?->format('d/m/Y') ?? 'N/A';
|
||||
$auto = $source === self::SOURCE_SYSTEM;
|
||||
$amount = number_format((float) $invoice->total, 0, ',', '.') . ' VNĐ';
|
||||
|
||||
Notification::notifyAdmins([
|
||||
'type' => 'service_renewed_by_customer',
|
||||
'title' => $auto ? 'Dịch vụ được tự động gia hạn' : 'Khách hàng gia hạn dịch vụ',
|
||||
'body' => "{$customer->fullname} " . ($auto ? 'được tự động gia hạn' : 'đã gia hạn') . " {$productName}" . ($serverName !== '' ? " ({$serverName})" : '') . " thêm {$months} tháng ({$amount}), hạn mới {$expiresAt}.",
|
||||
'link' => '/services/' . $service->id,
|
||||
'data' => ['service_id' => $service->id, 'invoice_id' => $invoice->id, 'months' => $months],
|
||||
]);
|
||||
|
||||
$adminEmail = json_decode((string) Setting::where('key', 'setting')->value('value'), true)['admin_email'] ?? null;
|
||||
if (! $adminEmail || ! AutoEmailGate::allows(self::SCENARIO)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Mail::to($adminEmail)->queue(new ServiceRenewedMail(self::SCENARIO, [
|
||||
'customer_name' => (string) $customer->fullname,
|
||||
'customer_email' => (string) $customer->email,
|
||||
'product_name' => $productName,
|
||||
'server_name_suffix' => $serverName !== '' ? ' (' . e($serverName) . ')' : '',
|
||||
'months_label' => "{$months} tháng",
|
||||
'old_expires_at' => $previousExpiresAt?->format('d/m/Y') ?? 'N/A',
|
||||
'expires_at' => $expiresAt,
|
||||
'invoice_number' => (string) $invoice->invoice_number,
|
||||
'amount_formatted' => $amount,
|
||||
'payment_method_label' => $invoice->payment_method === 'balance' ? 'Trừ số dư tài khoản' : (string) ($invoice->payment_method ?: 'N/A'),
|
||||
'renewal_source_label' => $auto ? 'Tự động gia hạn (hệ thống)' : 'Khách hàng tự gia hạn',
|
||||
'admin_url' => rtrim(env('ADMIN_URL', config('app.url')), '/') . '/services/' . $service->id,
|
||||
]));
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('CustomerRenewalNotifier: không gửi được email admin', ['service_id' => $service->id, 'error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user