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:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,50 +3,11 @@
|
||||
namespace App\Http\Controllers\Api\Client\Domain;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use App\Models\DomainPricing;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class DomainPricingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Default domain pricing data (fallback when settings not configured)
|
||||
*/
|
||||
private function getDefaultDomainPricing(): array
|
||||
{
|
||||
return [
|
||||
'domains' => [
|
||||
['tld' => '.vn', 'setupFee' => 'Miễn phí', 'firstYear' => 400000, 'renewal' => 400000],
|
||||
['tld' => '.com.vn', 'setupFee' => 'Miễn phí', 'firstYear' => 300000, 'renewal' => 300000],
|
||||
['tld' => '.net.vn', 'setupFee' => 'Miễn phí', 'firstYear' => 300000, 'renewal' => 300000],
|
||||
['tld' => '.org.vn', 'setupFee' => 'Miễn phí', 'firstYear' => 300000, 'renewal' => 300000],
|
||||
['tld' => '.com', 'setupFee' => 'Miễn phí', 'firstYear' => 320000, 'renewal' => 340000],
|
||||
['tld' => '.net', 'setupFee' => 'Miễn phí', 'firstYear' => 369000, 'renewal' => 409000],
|
||||
['tld' => '.org', 'setupFee' => 'Miễn phí', 'firstYear' => 339000, 'renewal' => 369000],
|
||||
['tld' => '.biz', 'setupFee' => 'Miễn phí', 'firstYear' => 399000, 'renewal' => 409000],
|
||||
['tld' => '.info', 'setupFee' => 'Miễn phí', 'firstYear' => 490000, 'renewal' => 509000],
|
||||
['tld' => '.pro', 'setupFee' => 'Miễn phí', 'firstYear' => 469000, 'renewal' => 489000],
|
||||
['tld' => '.name', 'setupFee' => 'Miễn phí', 'firstYear' => 259000, 'renewal' => 259000],
|
||||
['tld' => '.ws', 'setupFee' => 'Miễn phí', 'firstYear' => 909000, 'renewal' => 909000],
|
||||
['tld' => '.tv', 'setupFee' => 'Miễn phí', 'firstYear' => 765000, 'renewal' => 819000],
|
||||
['tld' => '.mobi', 'setupFee' => 'Miễn phí', 'firstYear' => 589000, 'renewal' => 589000],
|
||||
['tld' => '.uk', 'setupFee' => 'Miễn phí', 'firstYear' => 537000, 'renewal' => 537000],
|
||||
['tld' => '.asia', 'setupFee' => 'Miễn phí', 'firstYear' => 380000, 'renewal' => 452000],
|
||||
['tld' => '.me', 'setupFee' => 'Miễn phí', 'firstYear' => 1029000, 'renewal' => 1029000],
|
||||
['tld' => '.us', 'setupFee' => 'Miễn phí', 'firstYear' => 323000, 'renewal' => 323000],
|
||||
],
|
||||
'services' => [
|
||||
['name' => 'Chứng thực Rapid SSL', 'setupFee' => 230000, 'maintenance' => 750000, 'note' => '01 Domain'],
|
||||
['name' => 'Chứng thực Quick SSL', 'setupFee' => 230000, 'maintenance' => 2300000, 'note' => '01 Domain'],
|
||||
['name' => 'Chứng thực Wildcard SSL', 'setupFee' => 230000, 'maintenance' => 3300000, 'note' => 'Unlimited Subdomain'],
|
||||
['name' => 'Chứng thực True BusinessID', 'setupFee' => 540000, 'maintenance' => 3900000, 'note' => '01 Domain'],
|
||||
['name' => 'Chứng thực True BusinessID WildCard', 'setupFee' => 900000, 'maintenance' => 15000000, 'note' => 'Unlimited Subdomain'],
|
||||
['name' => 'Đăng ký DNS riêng', 'setupFee' => 200000, 'maintenance' => 'Miễn phí', 'note' => "dns1.tenmiencuaban.com\ndns2.tenmiencuaban.com"],
|
||||
['name' => 'Bảo mật thông tin tên miền', 'setupFee' => 'Miễn phí', 'maintenance' => 90000, 'note' => 'Toàn bộ thông tin Whois tên miền của bạn sẽ được giấu kín hoàn toàn với mọi công cụ Whois'],
|
||||
['name' => 'Khóa tên miền', 'setupFee' => 'Miễn phí', 'maintenance' => 'Miễn phí', 'note' => 'Tăng cường bảo mật cho tên miền'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /v1/domain-pricing
|
||||
* Returns domain pricing list and addon services.
|
||||
@@ -54,24 +15,10 @@ class DomainPricingController extends Controller
|
||||
*/
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$setting = Setting::where('key', 'domain_pricing')->first();
|
||||
|
||||
if ($setting && !empty($setting->value)) {
|
||||
$value = json_decode((string) $setting->value, true);
|
||||
if (is_array($value) && !empty($value)) {
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $value,
|
||||
'message' => 'Lấy bảng giá tên miền thành công.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to default data
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $this->getDefaultDomainPricing(),
|
||||
'message' => 'Lấy bảng giá tên miền thành công (mặc định).',
|
||||
'data' => DomainPricing::toResponseArray(),
|
||||
'message' => 'Lấy bảng giá tên miền thành công.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user