feat: Add service date handling and enhance service details in response
This commit is contained in:
@@ -1151,6 +1151,11 @@ class CustomerController extends Controller
|
||||
'price' => $basePrice,
|
||||
]);
|
||||
|
||||
// Ngày bắt đầu/hết hạn dùng chung cho cả module_vmware (next_due_date/next_invoice) và services.
|
||||
$startedAt = $data['started_at'] ?? now();
|
||||
$expiresAt = $data['expires_at']
|
||||
?? \Carbon\Carbon::parse($startedAt)->addMonths($months);
|
||||
|
||||
// 2) ModuleVmware: snapshot từ virtual_machines. `order_id` phải trỏ về
|
||||
// order vừa tạo — client console-ticket/rebuild resolve VM qua
|
||||
// service->orderItem->order->vmWare, không qua services.vm_id.
|
||||
@@ -1181,6 +1186,10 @@ class CustomerController extends Controller
|
||||
'plain_password' => $data['vm_password'] ?? null,
|
||||
'port' => $data['vm_port'] ?? null,
|
||||
'status' => 1,
|
||||
'first_payment' => $basePrice,
|
||||
'next_payment' => $basePrice,
|
||||
'next_due_date' => \Carbon\Carbon::parse($expiresAt)->timestamp,
|
||||
'next_invoice' => \Carbon\Carbon::parse($expiresAt)->timestamp,
|
||||
]
|
||||
);
|
||||
$vmId = $moduleVm->id;
|
||||
@@ -1234,10 +1243,6 @@ class CustomerController extends Controller
|
||||
]);
|
||||
|
||||
// 5) Service — updateOrCreate để tránh trùng khi cùng VM được gán lại
|
||||
$startedAt = $data['started_at'] ?? now();
|
||||
$expiresAt = $data['expires_at']
|
||||
?? \Carbon\Carbon::parse($startedAt)->addMonths($months);
|
||||
|
||||
$serviceLookup = $vmId
|
||||
? ['customer_id' => $customer->id, 'vm_id' => $vmId]
|
||||
: [
|
||||
@@ -1264,6 +1269,11 @@ class CustomerController extends Controller
|
||||
]
|
||||
);
|
||||
|
||||
// module_vmware.service_id chỉ biết được sau khi Service đã tồn tại.
|
||||
if ($vmId) {
|
||||
\App\Models\ModuleVmware::where('id', $vmId)->update(['service_id' => $service->id]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
|
||||
Reference in New Issue
Block a user