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 VpsServiceResource 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
{
$orderItem = $this->orderItem;
@@ -43,13 +62,7 @@ class VpsServiceResource extends JsonResource
'product_type' => $product->product_type,
'page_type' => 'service_vps',
] : null,
'specs' => $product ? [
'cpu' => (int) ($product->cpu ?? 0),
'ram' => (int) ($product->ram ?? 0),
'disk' => (int) ($product->disk ?? 0),
'bandwidth' => (int) ($product->bandwidth ?? 0),
'gpu' => $product->gpu,
] : null,
'specs' => $this->resolveSpecs($product),
];
}
}