feat: add domain registration form and email notifications

- Create a new Blade view for domain registration (`registrant-tochuc.blade.php`) to capture organization and manager details.
- Implement email templates for new domain orders for both admin (`domain-order-new.blade.php`) and customers (`domain-order-received.blade.php`).
- Add CSV exports for client and domain data.
- Introduce tests for customer mass assignment, password reset, login throttling, and permission gating.
- Ensure service renewals use current pricing and validate ownership for virtual machines.
- Validate mass assignment behavior in service model.
This commit is contained in:
baodev0
2026-08-22 17:30:55 +07:00
parent eec2c5906e
commit c377c7e195
58 changed files with 3063 additions and 418 deletions
@@ -7,9 +7,10 @@ namespace App\Http\Controllers\Api\Client\Domain;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\Client\Domain\StoreDomainOrderRequest;
use App\Mail\Admin\DomainOrderNewNotification;
use App\Mail\Customer\DomainOrderReceivedNotification;
use App\Models\Customer;
use App\Models\Notification;
use App\Models\Setting;
use App\Models\Template;
use App\Services\Api\Domain\DomainOrderService;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
@@ -26,7 +27,7 @@ class DomainOrderController extends Controller
try {
$result = $this->domainOrderService->placeOrder($request->validated(), $request->user());
$this->notifyAdminNewDomainOrder($request->user(), $result);
$this->notifyDomainOrderPlaced($request->user(), $result);
return response()->json([
'success' => true,
@@ -59,11 +60,12 @@ class DomainOrderController extends Controller
}
}
private function notifyAdminNewDomainOrder($customer, array $result): void
private function notifyDomainOrderPlaced(Customer $customer, array $result): void
{
$domainName = $result['order']->orderItems->first()?->domain_name ?? '';
$orderNum = $result['order']->order_num;
$total = number_format((int) $result['invoice']->total) . ' VNĐ';
$createdAt = now()->format('d/m/Y H:i:s');
Notification::notifyAdmins([
'type' => 'domain_order_new',
@@ -72,35 +74,41 @@ class DomainOrderController extends Controller
'link' => '/domain-orders',
]);
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
$companyName = $settingValue['company'] ?? config('app.name');
$adminEmail = $settingValue['admin_email'] ?? null;
$mailData = [
'company_name' => $companyName,
'domain_name' => $domainName,
'customer_name' => $customer->fullname,
'customer_email' => $customer->email,
'order_num' => $orderNum,
'order_total' => $total,
'created_at' => $createdAt,
];
if (!empty($adminEmail)) {
try {
$adminUrl = rtrim(env('ADMIN_URL', config('app.url')), '/') . '/domain-orders';
Mail::to($adminEmail)->send(
new DomainOrderNewNotification([...$mailData, 'admin_url' => $adminUrl])
);
} catch (\Throwable $e) {
Log::error('DomainOrderController: không thể gửi email admin: ' . $e->getMessage());
}
}
try {
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value, true) : [];
$adminEmail = $settingValue['admin_email'] ?? null;
$orderUrl = rtrim(config('app.frontend_url', ''), '/') . '/don-hang';
if (empty($adminEmail)) {
return;
}
$template = Template::where('name', 'Domain Order New')->first();
if (!$template) {
return;
}
$adminUrl = rtrim(env('ADMIN_URL', config('app.url')), '/') . '/domain-orders';
Mail::to($adminEmail)->send(new DomainOrderNewNotification($template, [
'company_name' => $settingValue['company'] ?? config('app.name'),
'company_logo' => $settingValue['logo'] ?? '',
'domain_name' => $domainName,
'customer_name' => $customer->fullname,
'customer_email' => $customer->email,
'order_num' => $orderNum,
'order_total' => $total,
'created_at' => now()->format('d/m/Y H:i:s'),
'admin_url' => $adminUrl,
]));
Mail::to($customer->email)->send(
new DomainOrderReceivedNotification([...$mailData, 'order_url' => $orderUrl])
);
} catch (\Throwable $e) {
Log::error('DomainOrderController: không thể gửi email admin: ' . $e->getMessage());
Log::error('DomainOrderController: không thể gửi email khách hàng: ' . $e->getMessage());
}
}
}