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:
baodev0
2026-10-11 09:56:18 +07:00
co-authored by Claude Opus 5.5
parent 30898ea46f
commit 94614d9cb3
55 changed files with 1190 additions and 236 deletions
@@ -70,6 +70,7 @@ class OrderResource extends JsonResource
'attachments' => $invoice->relationLoaded('attachments')
? $invoice->attachments->map(fn($attachment) => [
'id' => $attachment->id,
'type' => $attachment->type,
'filename' => $attachment->filename,
'url' => $attachment->url,
'mime_type' => $attachment->mime_type,
@@ -2,6 +2,7 @@
namespace App\Http\Resources\Api\Client\Service;
use App\Models\DnsDomain;
use App\Models\ModuleHostingPleskClient;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
@@ -27,6 +28,18 @@ class ServiceClientDetailResource extends JsonResource
];
}
private function resolveDnsZone(): ?DnsDomain
{
if ($this->type !== 'domain' || !$this->server_name) {
return null;
}
return DnsDomain::query()
->whereRaw('LOWER(domain_name) = ?', [mb_strtolower(trim($this->server_name))])
->whereHas('customer', fn ($query) => $query->where('customers.id', $this->customer_id))
->first(['id', 'is_created']);
}
/**
* Transform the resource into an array.
*
@@ -72,6 +85,8 @@ class ServiceClientDetailResource extends JsonResource
$product = $orderItem?->product;
$hosting = $this->resource->hostingAccount;
$pleskCredentials = $hosting ? $this->resolvePleskCredentials($hosting) : null;
$dnsZone = $this->resolveDnsZone();
$dnsCancelled = $dnsZone !== null && (int) $dnsZone->is_created === DnsDomain::STATUS_CANCELLED;
return [
'id' => $this->id,
@@ -115,6 +130,8 @@ class ServiceClientDetailResource extends JsonResource
'password' => $pleskCredentials['password'] ?? null,
'status' => $hosting->status,
] : null,
'dns_domain_id' => $dnsZone && !$dnsCancelled ? $dnsZone->id : null,
'dns_cancelled' => $dnsCancelled,
];
}
}
@@ -1,34 +0,0 @@
<?php
namespace App\Http\Resources\Api\Service;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
class DomainCollection extends ResourceCollection
{
public $collects = DomainResource::class;
/**
* Transform the resource collection into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$data = [
'items' => $this->collection,
];
if (method_exists($this->resource, 'total')) {
$data['pagination'] = [
'total' => $this->resource->total(),
'per_page' => $this->resource->perPage(),
'current_page' => $this->resource->currentPage(),
'last_page' => $this->resource->lastPage(),
];
}
return $data;
}
}
@@ -20,8 +20,7 @@ class DomainDetailResource extends JsonResource
public function toArray(Request $request): array
{
return [
'domain' => new DomainResource($this->resource),
'ns_count' => (int) ($this->record_count ?? 0),
'domain_name' => $this->domain_name,
'records' => $this->records ? new DomainNSCollection($this->records) : [
'items' => [],
'pagination' => [
@@ -16,10 +16,8 @@ class DomainNSResource extends JsonResource
{
return [
'id' => $this->id,
'dns_manager_domain_id' => $this->dns_manager_domain_id,
'name' => $this->name,
'type' => $this->type,
'type_valid' => $this->type_valid,
'priority' => $this->priority,
'weight' => $this->weight,
'port' => $this->port,
@@ -27,9 +25,6 @@ class DomainNSResource extends JsonResource
'protocol' => $this->protocol,
'value' => $this->value,
'ttl' => isset($this->ttl) ? (int) $this->ttl : null,
'plesk_id' => $this->plesk_id,
'created_at' => optional($this->created_at)->toISOString(),
'updated_at' => optional($this->updated_at)->toISOString(),
];
}
}
@@ -1,30 +0,0 @@
<?php
namespace App\Http\Resources\Api\Service;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class DomainResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'domain_name' => $this->domain_name,
'dns_manager_server_id' => $this->dns_manager_server_id,
'server_name' => $this->server?->name,
'server_ip' => $this->server?->ip_address,
'is_created' => isset($this->is_created) ? (int) $this->is_created : null,
'plesk_id' => $this->plesk_id,
'record_count' => $this->whenCounted('record'),
'created_at' => optional($this->created_at)->toISOString(),
'updated_at' => optional($this->updated_at)->toISOString(),
];
}
}
@@ -3,6 +3,7 @@
namespace App\Http\Resources\Api\Service\Order;
use App\Enums\Invoice\InvoiceStatus;
use App\Models\InvoiceAttachment;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
@@ -46,7 +47,10 @@ class InvoiceDetailResource extends JsonResource
'months' => $item->months,
'os_id' => $item->os_id,
])->values()->all()),
'attachments' => $this->whenLoaded('attachments', fn () => $this->attachments->map(fn ($a) => [
'attachments' => $this->whenLoaded('attachments', fn () => $this->attachments
->where('type', '!=', InvoiceAttachment::TYPE_DEPLOYMENT)
->values()
->map(fn ($a) => [
'filename' => $a->filename,
'url' => $a->url,
'mime_type' => $a->mime_type,