feat: implement VMware vCenter integration, enhance product pricing display, and update order processing logic.

This commit is contained in:
pbao9
2026-03-01 23:10:35 +07:00
parent 6b18c3ff12
commit 1cfcaee871
27 changed files with 1738 additions and 104 deletions
@@ -14,6 +14,22 @@ class ServiceResource extends JsonResource
*/
public function toArray(Request $request): array
{
$billingCycleLabels = [
'monthly' => 'Hàng tháng',
'quarterly' => 'Hàng quý',
'semi_annually' => 'Nửa năm',
'annually' => 'Hàng năm',
'onetime' => 'Một lần',
];
$periodUnits = [
'monthly' => 'month',
'quarterly' => 'quarter',
'semi_annually' => 'semi_year',
'annually' => 'year',
'onetime' => 'none',
];
return [
'uuid' => $this->uuid,
'name' => $this->name,
@@ -23,27 +39,42 @@ class ServiceResource extends JsonResource
'thumbnail' => $this->thumbnail ? asset($this->thumbnail) : null,
'product_type' => $this->product_type,
'specs' => [
'cpu' => $this->cpu,
'ram' => $this->ram,
'disk' => $this->disk,
'bandwidth' => $this->bandwidth,
'cpu' => (int) $this->cpu,
'ram' => (int) $this->ram,
'disk' => (int) $this->disk,
'bandwidth' => (int) $this->bandwidth,
'gpu' => $this->gpu
],
'stock' => $this->stock,
'price' => $this->price,
'price_sale' => $this->price_sale,
'group' => $this->category->name,
'price' => (int) $this->price,
'price_sale' => $this->price_sale ? (int) $this->price_sale : null,
'group' => $this->category->name ?? null,
'os' => $this->osVersions->groupBy('os_group_id')->map(function ($versions) {
$group = $versions->first()->osGroup;
return [
'name' => $group?->name,
'thumbnail' => $group?->thumbnail,
'versions' => $versions->map(fn($os) => [
'id' => $os->id,
'version' => $os->version,
'name' => $os->name,
])->values(),
];
})->values(),
'pricing' => $this->pricings->map(fn($p) => [
'id' => $p->id,
'name' => $billingCycleLabels[$p->billing_cycle] ?? $p->billing_cycle,
'price' => (int) $p->price,
'price_sale' => $p->price_sale ? (int) $p->price_sale : null,
'period' => $p->billing_cycle ? (int) match($p->billing_cycle) {
'monthly' => 1,
'quarterly' => 3,
'semi_annually' => 6,
'annually' => 12,
default => 1,
} : 1,
'period_unit' => $periodUnits[$p->billing_cycle] ?? 'month',
]),
];
}
}