feat: implement VMware vCenter integration, enhance product pricing display, and update order processing logic.
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Models\Os;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\ModuleIpAddress;
|
||||
use App\Models\IpPool;
|
||||
use App\Models\Log as CustomerLog;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@@ -52,15 +53,33 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
|
||||
if (!$this->isRetry) {
|
||||
$this->sendFailureNotification($errorMessage);
|
||||
$this->writeCustomerFailureLog($errorMessage);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$host = $product->host; // từ module_host_id
|
||||
$osModel = Os::with('osGroup.host.datacenter.vcenter')->find($this->item->os_id);
|
||||
|
||||
if (!$osModel) {
|
||||
$errorMessage = "Không tìm thấy OS id={$this->item->os_id} trong OrderItem #{$this->item->id}. os_id không hợp lệ.";
|
||||
Log::error($errorMessage);
|
||||
$telegram->SendErrorMessage([
|
||||
'error' => $errorMessage,
|
||||
'os_id' => $this->item->os_id,
|
||||
'order_item_id' => $this->item->id,
|
||||
'product_id' => $product->id,
|
||||
], 'CreateVirtualMachineJob - Invalid OS ID');
|
||||
if (!$this->isRetry) {
|
||||
$this->sendFailureNotification($errorMessage);
|
||||
$this->writeCustomerFailureLog($errorMessage);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$template = $osModel->template_id;
|
||||
$host = $osModel->osGroup?->host; // từ os_group.module_host_id
|
||||
$datacenter = $host?->datacenter;
|
||||
$vcenter = $datacenter?->vcenter;
|
||||
$osModel = Os::find($this->item->os_id);
|
||||
$template = $osModel?->template_id;
|
||||
|
||||
if (!$vcenter || !$host || !$datacenter) {
|
||||
$errorMessage = "Thiếu thông tin host/datacenter/vcenter từ sản phẩm ID #{$product->id}";
|
||||
@@ -76,6 +95,7 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
|
||||
if (!$this->isRetry) {
|
||||
$this->sendFailureNotification($errorMessage);
|
||||
$this->writeCustomerFailureLog($errorMessage);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -94,6 +114,7 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
|
||||
if (!$this->isRetry) {
|
||||
$this->sendFailureNotification($errorMessage);
|
||||
$this->writeCustomerFailureLog($errorMessage);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -154,6 +175,7 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
|
||||
if (!$this->isRetry) {
|
||||
$this->sendFailureNotification($errorMessage);
|
||||
$this->writeCustomerFailureLog($errorMessage);
|
||||
}
|
||||
return false;
|
||||
} elseif ($result === 'Login_Again') {
|
||||
@@ -168,6 +190,7 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
|
||||
if (!$this->isRetry) {
|
||||
$this->sendFailureNotification($errorMessage);
|
||||
$this->writeCustomerFailureLog($errorMessage);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
@@ -261,6 +284,7 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
'vm_started' => isset($startResult) && is_array($startResult) && $startResult['error'] === false
|
||||
]
|
||||
);
|
||||
$this->writeCustomerSuccessLog();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -282,11 +306,58 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
|
||||
if (!$this->isRetry) {
|
||||
$this->sendFailureNotification($errorMessage);
|
||||
$this->writeCustomerFailureLog($errorMessage);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function writeCustomerSuccessLog(): void
|
||||
{
|
||||
try {
|
||||
$order = $this->item->order;
|
||||
$customer = $order?->customer;
|
||||
|
||||
if (!$order || !$customer) {
|
||||
return;
|
||||
}
|
||||
|
||||
CustomerLog::create([
|
||||
'agent' => 'system',
|
||||
'client_ip' => null,
|
||||
'customer_id' => $customer->id,
|
||||
'description' => 'Khởi tạo dịch vụ thành công cho đơn hàng #' . $order->order_num
|
||||
. ' (product_id: ' . $this->item->product_id . ', os_id: ' . $this->item->os_id . ').',
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Không thể ghi log thành công khởi tạo VM: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function writeCustomerFailureLog(string $errorMessage): void
|
||||
{
|
||||
try {
|
||||
$order = $this->item->order;
|
||||
$customer = $order?->customer;
|
||||
|
||||
if (!$order || !$customer) {
|
||||
return;
|
||||
}
|
||||
|
||||
CustomerLog::create([
|
||||
'agent' => 'system',
|
||||
'client_ip' => null,
|
||||
'customer_id' => $customer->id,
|
||||
'description' => 'Khởi tạo dịch vụ thất bại cho đơn hàng #' . $order->order_num
|
||||
. ' (product_id: ' . $this->item->product_id . ', os_id: ' . $this->item->os_id . ').'
|
||||
. ' Lỗi: ' . $errorMessage . '. '
|
||||
. 'Nếu có lỗi xảy ra khi khởi tạo dịch vụ quý khách nhấn khởi tạo tại đây, hoặc quý khách có thể liên hệ với kỹ thuật support@tgs.com.vn',
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Không thể ghi log thất bại khởi tạo VM: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function getAvailableIPFromPool(int $networkId): string
|
||||
{
|
||||
// Lấy tất cả IP từ IPPool theo network_id, order by ip_address
|
||||
|
||||
Reference in New Issue
Block a user