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
@@ -12,6 +12,25 @@ class ServiceClientDetailResource extends JsonResource
*
* @return array<string, mixed>
*/
private function resolveSpecs($product): ?array
{
$addons = $this->addons ?? collect();
if ($addons->isNotEmpty()) {
return [
'cpu' => (int) $addons->where('addon_type', 'cpu')->sum('addon_value'),
'ram' => (int) $addons->where('addon_type', 'ram')->sum('addon_value'),
'disk' => (int) $addons->where('addon_type', 'disk')->sum('addon_value'),
'bandwidth' => (int) $addons->where('addon_type', 'bandwidth')->sum('addon_value'),
];
}
return $product ? [
'cpu' => (int) ($product->cpu ?? 0),
'ram' => (int) ($product->ram ?? 0),
'disk' => (int) ($product->disk ?? 0),
'bandwidth' => (int) ($product->bandwidth ?? 0),
] : null;
}
public function toArray(Request $request): array
{
if (!$this->resource) {
@@ -35,12 +54,7 @@ class ServiceClientDetailResource extends JsonResource
'version' => $orderItem?->os?->version,
'group' => $orderItem?->os?->osGroup?->name,
],
'specs' => $product ? [
'cpu' => (int) ($product->cpu ?? 0),
'ram' => (int) ($product->ram ?? 0),
'disk' => (int) ($product->disk ?? 0),
'bandwidth' => (int) ($product->bandwidth ?? 0),
] : null,
'specs' => $this->resolveSpecs($product),
'order' => $order ? [
'total' => (float) $order->total,
'months' => (int) $orderItem->months,