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
@@ -265,21 +265,51 @@ class ProcessOrderPaymentJob implements ShouldQueue
{
try {
$customer = $this->order->customer;
// Gửi email thông báo thành công
\App\Jobs\Mail\Customer\OrderPaymentSuccessJob::dispatch([
'customer_email' => $customer->email,
'customer_name' => trim($customer->firstname . ' ' . $customer->lastname),
'order_id' => $this->order->id,
'order_num' => $this->order->order_num,
'amount' => $this->order->amount,
'vm_results' => $vmResults
'customer_name' => trim($customer->firstname . ' ' . $customer->lastname),
'order_id' => $this->order->id,
'order_num' => $this->order->order_num,
'amount' => $this->order->amount,
'vm_results' => $vmResults,
'addons_summary' => $this->resolveAddonsSummary(),
]);
} catch (\Throwable $e) {
Log::error('Không thể gửi email thông báo thành công: ' . $e->getMessage());
}
}
/**
* Resolve addon display rows from all order items' addons_meta.
* Returns array of [{name, qty, subtotal}] for email rendering.
*
* @return array<int, array{name:string, qty:int, subtotal:int}>
*/
private function resolveAddonsSummary(): array
{
$rows = [];
$this->order->load('orderItems');
foreach ($this->order->orderItems as $item) {
$meta = is_array($item->addons_meta) ? $item->addons_meta : [];
foreach ($meta as $entry) {
$addon = \App\Models\Addon::find($entry['addon_id'] ?? null);
if (!$addon) {
continue;
}
$qty = (int) ($entry['qty'] ?? 0);
$rows[] = [
'name' => $addon->name,
'qty' => $qty,
'subtotal' => (int) ($entry['subtotal'] ?? $addon->price * $qty),
];
}
}
return $rows;
}
/**
* Check if the error is a timeout error
*/