Refactor VM resource specs resolution and enhance order payment success email with addon summary; add UpdateVmConfigJob for CPU/RAM updates

This commit is contained in:
baodev0
2026-07-17 14:00:42 +07:00
parent d9da3b5bb3
commit ad20cd5bdc
12 changed files with 458 additions and 33 deletions
+2
View File
@@ -308,6 +308,8 @@ class OrderService
$qty = max(1, (int) ($entry['qty'] ?? 1));
$resolved[] = [
'addon_id' => $addon->id,
'code' => strtolower((string) $addon->code),
'name' => $addon->name,
'qty' => $qty,
'price' => $addon->price,
'subtotal' => $addon->price * $qty,
+18
View File
@@ -7,6 +7,7 @@ use App\Enums\Order\OrderStatus;
use App\Enums\TransactionStatus;
use App\Jobs\VirtualMachine\Action\VMJobs;
use App\Jobs\VirtualMachine\Create\CreateVirtualMachineJob;
use App\Models\Addon;
use App\Models\Customer;
use App\Models\Invoice;
use App\Models\Log as CustomerActivityLog;
@@ -210,6 +211,23 @@ class InvoicePaymentService
}
}
}
$addonsMeta = is_array($item->addons_meta)
? $item->addons_meta
: json_decode($item->addons_meta ?? '[]', true);
foreach ((array) $addonsMeta as $meta) {
$addon = Addon::find($meta['addon_id'] ?? null);
if (!$addon) {
continue;
}
ServiceAddon::create([
'service_id' => $service->id,
'addon_type' => strtolower((string) $addon->code),
'addon_value' => (string) ($meta['qty'] ?? 1),
'price' => (int) ($meta['price'] ?? $addon->price),
]);
}
}
private function cycleToMonths(?string $cycle): int
+46
View File
@@ -36,6 +36,9 @@ final class VsphereHostSshService
private const SCRIPT_CHANGE_PWD_LINUX = 'changePwdLinux.ps1';
private const SCRIPT_CHANGE_PWD_WINDOWS = 'changePwdWindows.ps1';
private const ADDON_DIR = 'C:\\CLISave\\Addon';
private const SCRIPT_UPDATE_VM_CONFIG = 'updateVMConfig.ps1';
private const CONNECT_TIMEOUT = 20;
// ─────────────────────────────────────────────────────────────────────────
@@ -257,6 +260,49 @@ final class VsphereHostSshService
];
}
/**
* Update VM CPU and memory via updateVMConfig.ps1.
*
* Script path: C:\CLISave\Addon\updateVMConfig.ps1
* Params: $server_name $cpu $memoryGB $vcenter_host $vcenter_user $vcenter_password
* Output: "SUCCESS" or "FAIL"
*
* PS1 must call Connect-VIServer before Get-VM — see updateVMConfig.ps1 on vSphere host.
*/
public function updateVmConfig(
string $serverName,
int $cpu,
int $memoryGB,
string $vcenterHost,
string $vcenterUser,
string $vcenterPassword,
): string {
$remoteCmd = $this->windowsPowerShellCommand(self::ADDON_DIR, self::SCRIPT_UPDATE_VM_CONFIG, [
$serverName,
(string) $cpu,
(string) $memoryGB,
$vcenterHost,
$vcenterUser,
$vcenterPassword,
]);
Log::info('VsphereHostSshService: executing updateVmConfig', [
'server_name' => $serverName,
'cpu' => $cpu,
'memoryGB' => $memoryGB,
'vcenter_host' => $vcenterHost,
]);
$output = $this->sshExec($remoteCmd);
Log::info('VsphereHostSshService: updateVmConfig output', [
'server_name' => $serverName,
'output' => trim($output),
]);
return $output;
}
/**
* Customer-initiated VM password change.
*