feat: Implement UUID-based customer routing, enhance order request validation, and refactor VM creation job with updated payment logic and ModuleVmware handling.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Enums\Product\ProductBillingCycle;
|
||||
use App\Enums\Product\ProductTypeEnums;
|
||||
use App\Http\Helpers\Helper;
|
||||
use App\Jobs\Hosting\CreateHostingJobs;
|
||||
use App\Jobs\Mail\Customer\OrderCreatedJob;
|
||||
@@ -117,9 +118,10 @@ class OrderService
|
||||
'updated_at' => $now,
|
||||
], $productItems));
|
||||
|
||||
$vpsTypes = ['vps', 'cloud'];
|
||||
$vmTypes = [ProductTypeEnums::VPS, ProductTypeEnums::CLOUD];
|
||||
foreach (OrderItem::where('order_id', $order->id)->get() as $orderItem) {
|
||||
if (in_array($orderItem->product?->product_type, $vpsTypes)) {
|
||||
$type = ProductTypeEnums::tryFrom($orderItem->product?->category?->type ?? '');
|
||||
if (in_array($type, $vmTypes)) {
|
||||
CreateVirtualMachineJob::dispatch($orderItem)->delay(now()->addSeconds(10));
|
||||
}
|
||||
}
|
||||
@@ -163,10 +165,11 @@ class OrderService
|
||||
throw new \InvalidArgumentException("Sản phẩm không tồn tại (ID: {$item['product_id']}).");
|
||||
}
|
||||
|
||||
$moduleType = match ($product->product_type) {
|
||||
'hosting' => 3,
|
||||
'vps' => 4,
|
||||
default => 0,
|
||||
$categoryType = ProductTypeEnums::tryFrom($product->category?->type ?? '');
|
||||
$moduleType = match ($categoryType) {
|
||||
ProductTypeEnums::HOSTING => 3,
|
||||
ProductTypeEnums::VPS, ProductTypeEnums::CLOUD => 4,
|
||||
default => 0,
|
||||
};
|
||||
|
||||
$billingDetails = $this->calculateBillingDetails($item['billing']);
|
||||
@@ -177,12 +180,12 @@ class OrderService
|
||||
|
||||
$productItems[$key] = [
|
||||
'product_id' => $product->id,
|
||||
'product_type' => $product->product_type,
|
||||
'product_type' => $categoryType?->value,
|
||||
'months' => $billingCycle->months(),
|
||||
'billing_cycle' => $billingCycle->value,
|
||||
'os_id' => $item['os_id'] ?? null,
|
||||
'quantity' => (int) ($item['quantity'] ?? 1),
|
||||
'server_name' => $item['domain'] ?? null,
|
||||
'server_name' => $item['server_name'] ?? $item['domain'] ?? null,
|
||||
'price' => (int) $priceSelect,
|
||||
'invoice_type' => 1,
|
||||
'code' => $generalCode,
|
||||
@@ -194,7 +197,7 @@ class OrderService
|
||||
'data' => [
|
||||
'customer_id' => $data['customer_id'],
|
||||
'status' => 0,
|
||||
'name' => $item['domain'] ?? $product->name,
|
||||
'name' => $item['server_name'] ?? $item['domain'] ?? $product->name,
|
||||
'first_payment' => $priceSelect * $billingDetails['billing'],
|
||||
'next_payment' => ($item['price_custom'] ?? $product->price) * $billingDetails['billing'],
|
||||
...$billingDetails,
|
||||
@@ -220,7 +223,8 @@ class OrderService
|
||||
foreach ($relIdData as $item) {
|
||||
match ($item['type']) {
|
||||
3 => $this->moduleHostingRepository->create($item['data']),
|
||||
4 => $this->moduleVmwareRepository->create(array_merge($item['data'], ['status' => 2])),
|
||||
// type=4 (VPS): không pre-create ở đây.
|
||||
// CreateVirtualMachineJob sẽ tạo module_vmware sau khi VM provisioned xong.
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user