feat: nạp tiền thủ công mã 30 phút, gia hạn trừ số dư, đồng bộ domain từ Plesk

- Nạp tiền: mã thanh toán sống 30 phút (ManualDepositDraft), khôi phục/huỷ mã, lệnh dọn mã hết hạn; total_pending chỉ tính giao dịch đã nộp chứng từ, admin duyệt/từ chối/xoá giao dịch
- Gia hạn dịch vụ: phát hành invoice gia hạn trên order gốc và trừ số dư ngay
- Đồng bộ domain từ Plesk theo server, ServiceOrderRecorder tạo order/invoice cho dịch vụ admin dựng
- Danh sách dịch vụ trả field theo loại (service_plan, dns_records_count), đếm dịch vụ theo loại

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
baodev0
2026-10-11 23:07:51 +07:00
co-authored by Claude Opus 5.5
parent 10af41c5cf
commit c5115b52dd
53 changed files with 1887 additions and 613 deletions
@@ -2,6 +2,7 @@
namespace App\Http\Resources\Api\Client;
use App\Services\Api\ServiceClient\ServiceClientService;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\URL;
@@ -51,11 +52,8 @@ class ClientResource extends JsonResource
'point_total' => $this->point,
],
'service' => [
'vps' => $this->vps_count ?? $this->vps()->count(),
'proxy' => 0,
'server' => 0,
'hosting' => $this->hosting_count ?? $this->hosting()->count(),
'domain' => $this->domain_count ?? $this->domain()->count(),
...app(ServiceClientService::class)->countByType((int) $this->id),
]
];
}
@@ -82,7 +82,7 @@ class ServiceClientDetailResource extends JsonResource
$orderItem = $this->orderItem;
$order = $orderItem?->order;
$vm = $this->resource->vmware;
$product = $orderItem?->product;
$product = $orderItem?->product ?? $this->resource->product;
$hosting = $this->resource->hostingAccount;
$pleskCredentials = $hosting ? $this->resolvePleskCredentials($hosting) : null;
$dnsZone = $this->resolveDnsZone();
@@ -91,6 +91,7 @@ class ServiceClientDetailResource extends JsonResource
return [
'id' => $this->id,
'uuid' => $this->uuid,
'type' => $this->type,
'server_name' => $this->server_name,
'status' => $this->status,
'auto_renew' => $this->auto_renew,
@@ -100,11 +101,16 @@ class ServiceClientDetailResource extends JsonResource
'version' => $orderItem?->os?->version ?? $vm?->os?->version,
'group' => $orderItem?->os?->osGroup?->name ?? $vm?->os?->osGroup?->name,
],
'specs' => $this->resolveSpecs($vm, $product),
'specs' => $this->type === 'hosting' ? null : $this->resolveSpecs($vm, $product),
'service_plan' => $this->type === 'hosting' ? $product?->servicePlan?->summary() : null,
'order' => $order ? [
'total' => (float) $order->total,
'months' => (int) $orderItem->months,
'billing_label' => $orderItem->billing_label,
'cycle_price' => (float) ($product?->pricings()
->where('billing_cycle', $orderItem->billing_cycle)
->where('is_active', 1)
->value('price') ?? 0),
'addon_total' => \App\Support\RenewalPricing::addonTotal($this->resource, 1),
] : null,
'vm' => $vm ? [
@@ -87,6 +87,9 @@ class ServiceResource extends JsonResource
'period' => $periodMonths[$p->billing_cycle] ?? 1,
'period_unit' => $periodUnits[$p->billing_cycle] ?? 'month',
]),
$this->mergeWhen($this->product_type === 'hosting', fn () => [
'service_plan' => $this->servicePlan?->summary(),
]),
];
}
@@ -2,17 +2,13 @@
namespace App\Http\Resources\Api\Service;
use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class VpsServiceResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
private function resolveSpecs($product): ?array
private function resolveSpecs(?Product $product): ?array
{
$addons = $this->addons ?? collect();
if ($addons->isNotEmpty()) {
@@ -37,22 +33,19 @@ class VpsServiceResource extends JsonResource
$invoice = $this->invoice;
$order = $orderItem?->order ?? $invoice?->order;
$product = $orderItem?->product ?? $this->product;
$type = $this->type ?? $product?->product_type;
return [
'uuid' => $this->uuid,
'type' => $type,
'server_name' => $this->server_name,
'invoice_num' => $invoice?->invoice_number,
'order_item_id' => $this->order_item_id,
'order_num' => $order?->order_num,
'status' => $this->status,
'status_label' => $this->status_label,
'auto_renew' => (bool) $this->auto_renew,
'started_at' => $this->started_at?->toISOString(),
'expires_at' => $this->expires_at?->toISOString(),
'os' => [
'version' => $orderItem?->os?->version,
'group' => $orderItem?->os?->osGroup?->name,
],
'product' => $product ? [
'uuid' => $product->uuid,
'name' => $product->name,
@@ -60,7 +53,19 @@ class VpsServiceResource extends JsonResource
'product_type' => $product->product_type,
'page_type' => 'service_' . str_replace(' ', '_', $product->product_type),
] : null,
'specs' => $this->resolveSpecs($product),
$this->mergeWhen($type === 'vps', fn () => [
'os' => [
'version' => $orderItem?->os?->version,
'group' => $orderItem?->os?->osGroup?->name,
],
'specs' => $this->resolveSpecs($product),
]),
$this->mergeWhen($type === 'hosting', fn () => [
'service_plan' => $product?->servicePlan?->summary(),
]),
$this->mergeWhen($type === 'domain', fn () => [
'dns_records_count' => $this->dns_records_count,
]),
];
}
}