feat: add GeneratesUniqueSlug class for unique slug generation

feat: create PostCategoryFactory for generating post category data

feat: create PostFactory for generating post data

feat: add retry_requested_at column to services table

feat: add vcenter provisioning fields to products table

feat: add module_host_id to os table

feat: create email_notification_templates table for email templates

feat: add scenario and format fields to template table

feat: add admin fields to transactions table

fix: update ticket table columns and types

feat: add uuid to ticket table and backfill existing records

fix: make ticket_reply user_id nullable

feat: create notifications table for user notifications

fix: make ticket uuid nullable

feat: create post_categories table for blog categories

feat: create posts table for blog posts

feat: add invoice email template for PDF generation
This commit is contained in:
baodev0
2026-05-25 15:39:42 +07:00
parent a31d238135
commit 520f21cb11
73 changed files with 4682 additions and 440 deletions
@@ -13,6 +13,7 @@ use App\Services\ActivityLogger;
use App\Services\Api\ServiceClient\ServiceClientService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ServiceController extends Controller
{
@@ -182,4 +183,123 @@ class ServiceController extends Controller
]);
}
public function getAvailableOs(Request $request, string $uuid): JsonResponse
{
$customer = $request->user();
$service = Service::with([
'product.osVersions' => fn ($q) => $q->where('status', 1)->with('osGroup'),
])
->where('uuid', $uuid)
->where('customer_id', $customer->id)
->first();
if (!$service) {
return response()->json(['success' => false, 'message' => 'Không tìm thấy dịch vụ'], 404);
}
if (!in_array($service->status, ['active', 'suspended'], true)) {
return response()->json(['success' => false, 'message' => 'Dịch vụ không ở trạng thái hợp lệ để xem OS'], 422);
}
if (!$service->product) {
return response()->json(['success' => false, 'message' => 'Không tìm thấy product của dịch vụ'], 404);
}
$grouped = $service->product->osVersions
->groupBy(fn ($os) => $os->osGroup?->id ?? 0)
->map(fn ($items) => [
'group' => [
'id' => $items->first()->osGroup?->id,
'name' => $items->first()->osGroup?->name,
'thumbnail' => $items->first()->osGroup?->thumbnail,
],
'items' => $items->map(fn ($os) => [
'id' => $os->id,
'version' => $os->version,
'template_id' => $os->template_id,
])->values(),
])
->values();
return response()->json([
'success' => true,
'data' => $grouped,
]);
}
public function rebuild(Request $request, string $uuid, vCenter $serviceVCenter): JsonResponse
{
$customer = $request->user();
$payload = $request->validate([
'os_id' => ['required', 'integer', 'exists:os,id'],
'password' => ['nullable', 'string', 'max:255'],
]);
$service = Service::with(['product.osVersions', 'vmware'])
->where('uuid', $uuid)
->where('customer_id', $customer->id)
->first();
if (!$service) {
return response()->json(['success' => false, 'message' => 'Không tìm thấy dịch vụ'], 404);
}
if ($service->status === 'suspended') {
return response()->json(['success' => false, 'message' => 'Dịch vụ đang bị tạm ngưng, không thể rebuild'], 422);
}
if (!$service->isActive()) {
return response()->json(['success' => false, 'message' => 'Dịch vụ không ở trạng thái active'], 422);
}
$allowedOsIds = $service->product?->osVersions()
->where('status', 1)
->pluck('os.id')
->map('intval')
->toArray() ?? [];
if (!in_array((int) $payload['os_id'], $allowedOsIds, true)) {
return response()->json(['success' => false, 'message' => 'OS không hợp lệ cho sản phẩm hiện tại'], 422);
}
$vm = $service->vmware;
if (!$vm) {
return response()->json(['success' => false, 'message' => 'Dịch vụ chưa được cấp phát VM'], 404);
}
DB::table('reinstall_logs')->insert([
'product_id' => $vm->id,
'product_type' => 4,
'custome_id' => $customer->id,
'os_id' => $payload['os_id'],
'status' => 'pending',
'initiator' => 'client',
'note' => 'Client rebuild via service UUID: ' . $uuid,
'created_at' => now(),
'updated_at' => now(),
]);
$result = $serviceVCenter->reBuildVPS((string) $vm->name);
if (is_string($result) || ($result['error'] ?? false)) {
return response()->json([
'success' => false,
'message' => is_string($result) ? $result : ($result['message'] ?? 'Không thể rebuild VM'),
], 400);
}
$this->activityLogger->log(
event: 'rebuild',
logName: 'VM',
description: "Customer {$customer->email} rebuild VM: {$vm->name} với OS ID: {$payload['os_id']} qua service UUID: {$uuid}",
subject: $vm,
newValues: ['os_id' => $payload['os_id'], 'service_uuid' => $uuid],
);
return response()->json([
'success' => true,
'message' => 'Đã gửi yêu cầu rebuild VM',
]);
}
}