feat: bật/tắt yêu cầu hoàn tất hồ sơ, xoá dịch vụ kèm đơn/hoá đơn, sync tên VM đã gán
- setting.require_complete_profile (mặc định bật), trả qua GET v1/setting - bulkDeleteServices xoá mềm invoice nâng cấp + order mồ côi (ServiceOrderRecorder::discardOrder) - createService trỏ dịch vụ sang order mới thì bỏ order cũ - SyncVirtualMachine cập nhật name + gắn virtual_machine_id cho module_vmware Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
bf78f3b810
commit
0bd15f6018
@@ -67,6 +67,7 @@ class SettingController extends Controller
|
||||
$validator = Validator::make($request->all(), [
|
||||
'setting' => 'sometimes|array',
|
||||
'setting.api_inet' => 'sometimes|string|nullable',
|
||||
'setting.require_complete_profile' => 'sometimes|boolean',
|
||||
'smtp' => 'sometimes|array',
|
||||
'smtp.host' => 'sometimes|string',
|
||||
'smtp.port' => 'sometimes|integer',
|
||||
|
||||
@@ -24,7 +24,7 @@ class SettingController extends Controller
|
||||
* operationId="getSetting",
|
||||
* tags={"Settings"},
|
||||
* summary="Get application settings",
|
||||
* description="Returns the public application settings (title, company, logo, favi_icon, brand_color)",
|
||||
* description="Returns the public application settings (title, company, logo, favi_icon, brand_color, require_complete_profile)",
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Successful operation",
|
||||
@@ -39,7 +39,9 @@ class SettingController extends Controller
|
||||
public function getSetting(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'data' => PublicSetting::values(),
|
||||
'data' => PublicSetting::values() + [
|
||||
'require_complete_profile' => PublicSetting::requireCompleteProfile(),
|
||||
],
|
||||
'message' => 'Get setting successfully',
|
||||
'error' => false
|
||||
]);
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Http\Services\Telegram;
|
||||
use App\Http\Services\vCenter as ServiceVCenter;
|
||||
use App\Models\ModuleDatacenter;
|
||||
use App\Models\ModuleHost;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\VirtualMachines;
|
||||
use App\Models\vCenter;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@@ -178,12 +179,26 @@ class SyncVirtualMachine implements ShouldQueue
|
||||
$vmObj->last_synced_at = now();
|
||||
|
||||
$vmObj->save();
|
||||
$this->syncAssignedVm($vmObj);
|
||||
$syncedVmIds[] = $vmData['vm'];
|
||||
$count++;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
private function syncAssignedVm(VirtualMachines $vm): void
|
||||
{
|
||||
ModuleVmware::query()
|
||||
->where(fn ($query) => $query
|
||||
->where('virtual_machine_id', $vm->id)
|
||||
->orWhere(fn ($legacy) => $legacy->whereNull('virtual_machine_id')->where('vmware_id', $vm->vm_id)))
|
||||
->where(fn ($query) => $query
|
||||
->whereNull('virtual_machine_id')
|
||||
->orWhereNull('name')
|
||||
->orWhere('name', '!=', $vm->name))
|
||||
->update(['name' => $vm->name, 'virtual_machine_id' => $vm->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete VMs in DB that belong to the given vCenter but no longer exist on vCenter.
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Services\Customer;
|
||||
use App\Helpers\OrderHelper;
|
||||
use App\Mail\ServiceRenewalReminderMail;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\Order;
|
||||
use App\Models\Product;
|
||||
@@ -54,15 +55,21 @@ class CustomerServiceProvisioningService
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Xoá nhiều dịch vụ của khách hàng. Chỉ xoá bản ghi trong bảng `services`,
|
||||
* không xoá VM (module_vmware / virtual_machines) liên kết.
|
||||
*/
|
||||
public function bulkDeleteServices(string $uuid, array $ids): int
|
||||
{
|
||||
$customer = $this->resolveCustomer($uuid);
|
||||
|
||||
return Service::where('customer_id', $customer->id)->whereIn('id', $ids)->delete();
|
||||
return DB::transaction(function () use ($customer, $ids) {
|
||||
$services = Service::where('customer_id', $customer->id)->whereIn('id', $ids)->get();
|
||||
|
||||
foreach ($services as $service) {
|
||||
$service->delete();
|
||||
Invoice::where('service_id', $service->id)->delete();
|
||||
$this->orderRecorder->discardOrder($service->order_item_id);
|
||||
}
|
||||
|
||||
return $services->count();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,6 +293,8 @@ class CustomerServiceProvisioningService
|
||||
'server_name' => $data['server_name'] ?? null,
|
||||
];
|
||||
|
||||
$replacedOrderItemId = Service::where($serviceLookup)->value('order_item_id');
|
||||
|
||||
$service = Service::updateOrCreate($serviceLookup, [
|
||||
'customer_id' => $customer->id,
|
||||
'product_id' => $product->id,
|
||||
@@ -300,6 +309,8 @@ class CustomerServiceProvisioningService
|
||||
'note' => $data['note'] ?? null,
|
||||
]);
|
||||
|
||||
$this->orderRecorder->discardOrder($replacedOrderItemId);
|
||||
|
||||
// module_vmware.service_id chỉ biết được sau khi Service đã tồn tại.
|
||||
if ($vmId) {
|
||||
ModuleVmware::where('id', $vmId)->update(['service_id' => $service->id]);
|
||||
|
||||
@@ -143,6 +143,21 @@ class ServiceOrderRecorder
|
||||
$invoice->order?->update(['status' => OrderStatus::CANCELLED->value]);
|
||||
}
|
||||
|
||||
public function discardOrder(?int $orderItemId): void
|
||||
{
|
||||
$order = $orderItemId ? OrderItem::find($orderItemId)?->order : null;
|
||||
if (! $order) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Service::whereIn('order_item_id', $order->orderItems()->pluck('id'))->exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order->invoices()->delete();
|
||||
$order->delete();
|
||||
}
|
||||
|
||||
public function listPrice(?Product $product, string $billingCycle, ?string $serverName): ?int
|
||||
{
|
||||
if ($product?->product_type === 'domain') {
|
||||
|
||||
@@ -13,8 +13,21 @@ final class PublicSetting
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
$value = json_decode((string) Setting::where('key', 'setting')->value('value'), true) ?: [];
|
||||
$value = self::raw();
|
||||
|
||||
return array_map(fn (string $field) => (string) ($value[$field] ?? ''), array_combine(self::FIELDS, self::FIELDS));
|
||||
}
|
||||
|
||||
public static function requireCompleteProfile(): bool
|
||||
{
|
||||
return (bool) (self::raw()['require_complete_profile'] ?? true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private static function raw(): array
|
||||
{
|
||||
return json_decode((string) Setting::where('key', 'setting')->value('value'), true) ?: [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user