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
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user