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:
@@ -8,6 +8,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\Admin\Domain\ConfirmRegistrationRequest;
|
||||
use App\Http\Requests\Api\Admin\Domain\RejectAndRefundRequest;
|
||||
use App\Http\Requests\Api\Admin\Domain\UpdateKycUrlRequest;
|
||||
use App\Http\Requests\Api\Admin\Domain\UpdateRegistrantInfoRequest;
|
||||
use App\Mail\Customer\DomainOrderStatusMail;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Order;
|
||||
@@ -16,16 +17,19 @@ use App\Models\Setting;
|
||||
use App\Models\Template;
|
||||
use App\Repositories\Api\Domain\DomainOrderRepository;
|
||||
use App\Services\Api\Domain\DomainOrderService;
|
||||
use App\Services\Api\Domain\DomainRegistrantService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class AdminDomainOrderController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DomainOrderRepository $repo,
|
||||
private readonly DomainOrderService $service,
|
||||
private readonly DomainOrderRepository $repo,
|
||||
private readonly DomainOrderService $service,
|
||||
private readonly DomainRegistrantService $registrantService,
|
||||
) {}
|
||||
|
||||
public function pendingCount(): JsonResponse
|
||||
@@ -188,6 +192,65 @@ class AdminDomainOrderController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function getRegistrant(int $id): JsonResponse
|
||||
{
|
||||
$order = $this->repo->findDomainOrder($id);
|
||||
$service = $order?->orderItems->first()?->service;
|
||||
|
||||
if (!$order || !$service) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Không tìm thấy đơn hàng domain.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $this->registrantService->get($service, $order->customer),
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateRegistrant(UpdateRegistrantInfoRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$order = $this->repo->findDomainOrder($id);
|
||||
$service = $order?->orderItems->first()?->service;
|
||||
|
||||
if (!$order || !$service) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Không tìm thấy đơn hàng domain.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$data = $request->validated();
|
||||
$service = $this->registrantService->update($service, $data['registrant_type'], $data['registrant_info']);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Cập nhật thông tin đăng ký thành công.',
|
||||
'data' => $this->formatService($service),
|
||||
]);
|
||||
}
|
||||
|
||||
public function downloadRegistrantDocx(int $id): Response
|
||||
{
|
||||
$order = $this->repo->findDomainOrder($id);
|
||||
$item = $order?->orderItems->first();
|
||||
$service = $item?->service;
|
||||
|
||||
abort_if(!$order || !$service, 404, 'Không tìm thấy đơn hàng domain.');
|
||||
|
||||
$registrant = $this->registrantService->get($service, $order->customer);
|
||||
$docx = $this->registrantService->renderDocx($item->domain_name, $registrant['type'], $registrant['info']);
|
||||
|
||||
$filename = 'phieu-dang-ky-' . $item->domain_name . '.docx';
|
||||
|
||||
return response($docx, 200, [
|
||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
|
||||
]);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Private helpers
|
||||
// =========================================================================
|
||||
@@ -280,6 +343,8 @@ class AdminDomainOrderController extends Controller
|
||||
'registrar_reference' => $service->registrar_reference,
|
||||
'kyc_url' => $service->kyc_url,
|
||||
'rejection_reason' => $service->rejection_reason,
|
||||
'registrant_type' => $service->registrant_type,
|
||||
'registrant_info' => $service->registrant_info,
|
||||
'auto_renew' => $service->auto_renew,
|
||||
'started_at' => $service->started_at?->toIso8601String(),
|
||||
'expires_at' => $service->expires_at?->toIso8601String(),
|
||||
|
||||
@@ -5,85 +5,67 @@ declare(strict_types=1);
|
||||
namespace App\Http\Controllers\Api\Admin\Domain;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Setting;
|
||||
use App\Models\DomainPricing;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class AdminDomainPricingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Default domain pricing data (used as fallback and for seeding)
|
||||
*/
|
||||
private function getDefaultData(): 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'],
|
||||
],
|
||||
];
|
||||
}
|
||||
private const DEFAULT_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],
|
||||
];
|
||||
|
||||
private const DEFAULT_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 /administrator/domain-pricing
|
||||
*/
|
||||
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.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => $this->getDefaultData(),
|
||||
'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.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /administrator/domain-pricing
|
||||
* Full replace of domains/services, mirroring the admin table's "save whole blob" UX.
|
||||
*/
|
||||
public function update(Request $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'domains' => 'sometimes|array',
|
||||
'services' => 'sometimes|array',
|
||||
'domains' => 'sometimes|array',
|
||||
'services' => 'sometimes|array',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
@@ -93,25 +75,22 @@ class AdminDomainPricingController extends Controller
|
||||
], 422);
|
||||
}
|
||||
|
||||
$current = Setting::where('key', 'domain_pricing')->first();
|
||||
$existing = $current ? json_decode((string) $current->value, true) : $this->getDefaultData();
|
||||
DB::transaction(function () use ($request) {
|
||||
if ($request->has('domains')) {
|
||||
DomainPricing::domains()->delete();
|
||||
$this->insertDomains($request->input('domains'));
|
||||
}
|
||||
|
||||
if ($request->has('domains')) {
|
||||
$existing['domains'] = $request->input('domains');
|
||||
}
|
||||
if ($request->has('services')) {
|
||||
$existing['services'] = $request->input('services');
|
||||
}
|
||||
|
||||
Setting::updateOrCreate(
|
||||
['key' => 'domain_pricing'],
|
||||
['value' => json_encode($existing, JSON_UNESCAPED_UNICODE)]
|
||||
);
|
||||
if ($request->has('services')) {
|
||||
DomainPricing::services()->delete();
|
||||
$this->insertServices($request->input('services'));
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Cập nhật bảng giá tên miền thành công.',
|
||||
'data' => $existing,
|
||||
'data' => DomainPricing::toResponseArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -121,17 +100,44 @@ class AdminDomainPricingController extends Controller
|
||||
*/
|
||||
public function reset(): JsonResponse
|
||||
{
|
||||
$default = $this->getDefaultData();
|
||||
|
||||
Setting::updateOrCreate(
|
||||
['key' => 'domain_pricing'],
|
||||
['value' => json_encode($default, JSON_UNESCAPED_UNICODE)]
|
||||
);
|
||||
DB::transaction(function () {
|
||||
DomainPricing::query()->delete();
|
||||
$this->insertDomains(self::DEFAULT_DOMAINS);
|
||||
$this->insertServices(self::DEFAULT_SERVICES);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Đã reset bảng giá tên miền về mặc định.',
|
||||
'data' => $default,
|
||||
'data' => DomainPricing::toResponseArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function insertDomains(array $domains): void
|
||||
{
|
||||
foreach (array_values($domains) as $i => $d) {
|
||||
DomainPricing::create([
|
||||
'type' => 'domain',
|
||||
'tld' => $d['tld'] ?? null,
|
||||
'setup_fee' => (string) ($d['setupFee'] ?? 'Miễn phí'),
|
||||
'first_year' => (int) ($d['firstYear'] ?? 0),
|
||||
'recurring_fee' => (string) ($d['renewal'] ?? 0),
|
||||
'sort_order' => $i,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function insertServices(array $services): void
|
||||
{
|
||||
foreach (array_values($services) as $i => $s) {
|
||||
DomainPricing::create([
|
||||
'type' => 'service',
|
||||
'name' => $s['name'] ?? null,
|
||||
'setup_fee' => (string) ($s['setupFee'] ?? 'Miễn phí'),
|
||||
'recurring_fee' => (string) ($s['maintenance'] ?? 'Miễn phí'),
|
||||
'note' => $s['note'] ?? null,
|
||||
'sort_order' => $i,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user