feat: khởi tạo/huỷ domain Plesk qua job, gửi mail hoá đơn qua queue, đính kèm triển khai
- ProvisionDnsDomainJob/SuspendDnsDomainJob: tạo domain admin lên Plesk, huỷ = suspend (is_created=3) - Khách xem zone DNS được gán ở /dich-vu/domain, quản lý bản ghi A/AAAA/CNAME/TXT/MX/SRV - send-mail hoá đơn đẩy SendInvoiceMailJob, preview + sửa nội dung, ghi mail.order_id - invoice_attachments.type (payment_proof/deployment) - CacheService xoá theo SCAN pattern, Redis không persistent mặc định - Backfill transactions.public_code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
30898ea46f
commit
94614d9cb3
@@ -3,7 +3,6 @@
|
||||
namespace App\Http\Controllers\Api\Client\Service;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Service\DomainCollection;
|
||||
use App\Http\Resources\Api\Service\DomainDetailResource;
|
||||
use App\Http\Resources\Api\Service\DomainNSResource;
|
||||
use App\Models\DnsDomain;
|
||||
@@ -13,35 +12,17 @@ use App\Services\ServerService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class DomainController extends Controller
|
||||
{
|
||||
public const CLIENT_EDITABLE_TYPES = ['A', 'AAAA', 'CNAME', 'TXT', 'MX', 'SRV'];
|
||||
|
||||
public function __construct(
|
||||
protected ActivityLogger $activityLogger,
|
||||
protected ServerService $serverService,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$customer = $request->user();
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
|
||||
$domains = DnsDomain::query()
|
||||
->with('server')
|
||||
->withCount('record')
|
||||
->whereHas('customer', fn ($query) => $query->where('customers.id', $customer->id))
|
||||
->orderByDesc('id')
|
||||
->paginate($perPage);
|
||||
|
||||
return (new DomainCollection($domains))
|
||||
->additional([
|
||||
'error' => false,
|
||||
'message' => 'Lấy dữ liệu thành công',
|
||||
'page_type' => 'service_domain',
|
||||
])
|
||||
->response();
|
||||
}
|
||||
|
||||
public function show(Request $request, int $domainId): JsonResponse
|
||||
{
|
||||
$domain = $this->resolveCustomerDomain($request, $domainId);
|
||||
@@ -52,8 +33,6 @@ class DomainController extends Controller
|
||||
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
|
||||
$domain->load('server')->loadCount('record');
|
||||
|
||||
$records = DnsManagerNS::query()
|
||||
->where('dns_manager_domain_id', $domain->id)
|
||||
->orderBy('type')
|
||||
@@ -155,6 +134,10 @@ class DomainController extends Controller
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy bản ghi DNS'], 404);
|
||||
}
|
||||
|
||||
if ($locked = $this->lockedRecordResponse($record)) {
|
||||
return $locked;
|
||||
}
|
||||
|
||||
$payload = $this->validateDomainRecordPayload($request);
|
||||
|
||||
if (! empty($record->plesk_id)) {
|
||||
@@ -223,6 +206,10 @@ class DomainController extends Controller
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy bản ghi DNS'], 404);
|
||||
}
|
||||
|
||||
if ($locked = $this->lockedRecordResponse($record)) {
|
||||
return $locked;
|
||||
}
|
||||
|
||||
if (! empty($record->plesk_id)) {
|
||||
$this->serverService->findServerByID($domain->dns_manager_server_id);
|
||||
$serverPayload = $this->serverService->deleteRecord((int) $record->plesk_id);
|
||||
@@ -258,11 +245,20 @@ class DomainController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
private function lockedRecordResponse(DnsManagerNS $record): ?JsonResponse
|
||||
{
|
||||
return in_array(strtoupper((string) $record->type), self::CLIENT_EDITABLE_TYPES, true) ? null : response()->json([
|
||||
'error' => true,
|
||||
'message' => "Bản ghi {$record->type} không thể tự thay đổi. Vui lòng liên hệ bộ phận kỹ thuật.",
|
||||
], 403);
|
||||
}
|
||||
|
||||
private function resolveCustomerDomain(Request $request, int $domainId): ?DnsDomain
|
||||
{
|
||||
$customer = $request->user();
|
||||
|
||||
return DnsDomain::query()
|
||||
->notCancelled()
|
||||
->with('server')
|
||||
->where('id', $domainId)
|
||||
->whereHas('customer', fn ($query) => $query->where('customers.id', $customer->id))
|
||||
@@ -272,7 +268,7 @@ class DomainController extends Controller
|
||||
private function validateDomainRecordPayload(Request $request): array
|
||||
{
|
||||
return $request->validate([
|
||||
'type' => ['required', 'string', 'in:A,AAAA,CNAME,TXT,MX,NS,SRV'],
|
||||
'type' => ['required', 'string', Rule::in(self::CLIENT_EDITABLE_TYPES)],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'value' => ['required', 'string'],
|
||||
'ttl' => ['nullable', 'integer', 'min:60', 'max:86400'],
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Http\Resources\Api\Service\VpsServiceCollection;
|
||||
use App\Http\Resources\Api\Service\Order\InvoiceSummaryResource;
|
||||
use App\Http\Resources\Api\Client\Service\ServiceClientDetailResource;
|
||||
use App\Http\Services\vCenter;
|
||||
use App\Models\DnsDomain;
|
||||
use App\Models\Order;
|
||||
use App\Models\Service;
|
||||
use App\Repositories\Api\ServiceClient\ServiceClientRepository;
|
||||
@@ -67,6 +68,56 @@ class ServiceController extends Controller
|
||||
->response();
|
||||
}
|
||||
|
||||
public function indexDomain(Request $request): JsonResponse
|
||||
{
|
||||
$customerId = $request->user()->id;
|
||||
|
||||
$zones = DnsDomain::query()
|
||||
->whereHas('customer', fn ($query) => $query->where('customers.id', $customerId))
|
||||
->get(['id', 'domain_name', 'is_created'])
|
||||
->keyBy(fn (DnsDomain $zone) => mb_strtolower(trim($zone->domain_name)));
|
||||
|
||||
$zoneFields = fn (?DnsDomain $zone) => [
|
||||
'dns_domain_id' => $zone && !$this->isCancelledZone($zone) ? $zone->id : null,
|
||||
'cancelled' => $zone !== null && $this->isCancelledZone($zone),
|
||||
];
|
||||
|
||||
$items = Service::query()
|
||||
->where('customer_id', $customerId)
|
||||
->where('type', 'domain')
|
||||
->orderByDesc('id')
|
||||
->get(['uuid', 'server_name', 'status', 'started_at', 'expires_at'])
|
||||
->map(fn (Service $service) => [
|
||||
'domain_name' => $service->server_name,
|
||||
'service_uuid' => $service->uuid,
|
||||
'status' => $service->status,
|
||||
'started_at' => $service->started_at?->toISOString(),
|
||||
'expires_at' => $service->expires_at?->toISOString(),
|
||||
...$zoneFields($zones->pull(mb_strtolower(trim((string) $service->server_name)))),
|
||||
])
|
||||
->concat($zones->values()->map(fn (DnsDomain $zone) => [
|
||||
'domain_name' => $zone->domain_name,
|
||||
'service_uuid' => null,
|
||||
'status' => null,
|
||||
'started_at' => null,
|
||||
'expires_at' => null,
|
||||
...$zoneFields($zone),
|
||||
]))
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Lấy dữ liệu thành công',
|
||||
'page_type' => 'service_domain',
|
||||
'data' => ['items' => $items],
|
||||
]);
|
||||
}
|
||||
|
||||
private function isCancelledZone(DnsDomain $zone): bool
|
||||
{
|
||||
return (int) $zone->is_created === DnsDomain::STATUS_CANCELLED;
|
||||
}
|
||||
|
||||
public function overview(Request $request, OrderQueryService $orderQueryService): JsonResponse
|
||||
{
|
||||
$customerId = (int) $request->user()->id;
|
||||
|
||||
Reference in New Issue
Block a user