feat: Implement client-facing service management API with UUID for services and bulk actions for product services.
This commit is contained in:
@@ -345,6 +345,74 @@ class OrderController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /v1/client/dich-vu/{uuid} — service detail by UUID
|
||||
*/
|
||||
public function getClientServiceDetail(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
try {
|
||||
$service = Service::query()
|
||||
->with(['product', 'addons', 'invoice', 'orderItem'])
|
||||
->where('uuid', $uuid)
|
||||
->where('customer_id', $request->user()->id)
|
||||
->first();
|
||||
|
||||
if (!$service) {
|
||||
return $this->notFound('Không tìm thấy dịch vụ.');
|
||||
}
|
||||
|
||||
$vmware = $service->vm_id
|
||||
? ModuleVmware::with(['ipAddress', 'os', 'vCenter'])->find((int) $service->vm_id)
|
||||
: null;
|
||||
|
||||
$data = [
|
||||
'id' => $service->id,
|
||||
'uuid' => $service->uuid,
|
||||
'service_name' => $service->product?->name ?? $service->server_name,
|
||||
'server_name' => $service->server_name,
|
||||
'product_type' => $service->product?->product_type,
|
||||
'billing_cycle' => $service->orderItem?->billing_cycle,
|
||||
'status' => $service->status,
|
||||
'status_text' => $service->status_label,
|
||||
'auto_renew' => (bool) $service->auto_renew,
|
||||
'started_at' => $this->isoDate($service->started_at),
|
||||
'expires_at' => $this->isoDate($service->expires_at),
|
||||
'note' => $service->note,
|
||||
'invoice_id' => $service->invoice_id,
|
||||
'invoice_number' => $service->invoice?->invoice_number,
|
||||
'product' => $service->product ? [
|
||||
'id' => $service->product->id,
|
||||
'uuid' => $service->product->uuid,
|
||||
'name' => $service->product->name,
|
||||
'product_type' => $service->product->product_type,
|
||||
'specs' => [
|
||||
'cpu' => $service->product->cpu,
|
||||
'ram' => $service->product->ram,
|
||||
'disk' => $service->product->disk,
|
||||
'bandwidth' => $service->product->bandwidth,
|
||||
],
|
||||
] : null,
|
||||
'addons' => $service->addons->map(fn($a) => [
|
||||
'type' => $a->addon_type,
|
||||
'value' => $a->addon_value,
|
||||
'price' => $a->price,
|
||||
])->all(),
|
||||
'vmware' => $vmware ? [
|
||||
'id' => $vmware->id,
|
||||
'name' => $vmware->name,
|
||||
'hostname' => $vmware->hostname,
|
||||
'ip_address' => $vmware->ipAddress?->ip,
|
||||
'os_name' => $vmware->os?->name,
|
||||
'status' => $vmware->status,
|
||||
] : null,
|
||||
];
|
||||
|
||||
return response()->json(['success' => true, 'data' => $data]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PATCH /v1/client/dich-vu/{id}/auto-renew — toggle auto-renewal on a service
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user