update
This commit is contained in:
@@ -26,6 +26,9 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Enums\Order\OrderStatus;
|
||||
use App\Helpers\OrderHelper;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
@@ -292,6 +295,70 @@ class CustomerController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tạo mã impersonate một lần (one-time code) để admin đăng nhập hộ khách hàng
|
||||
* vào giao diện portal-client. Trả về `code` (hiệu lực 120s) — portal-client
|
||||
* sẽ đổi code lấy token qua endpoint public `v1/client/impersonate/exchange`.
|
||||
*/
|
||||
public function loginAs(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$customer = $this->customerRepository->findBy('uuid', $uuid);
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => "Can't find customer by UUID #" . $uuid,
|
||||
], 404);
|
||||
}
|
||||
|
||||
if ((int) $customer->status !== 1) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Khách hàng không hoạt động, không thể đăng nhập hộ.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$token = \Tymon\JWTAuth\Facades\JWTAuth::fromUser($customer);
|
||||
$refreshToken = app(\App\Services\Api\Client\ClientAuthService::class)
|
||||
->createRefreshToken($customer->id);
|
||||
|
||||
$clientResource = (new \App\Http\Resources\Api\Client\ClientResource(
|
||||
$customer->loadCount(['vps', 'hosting', 'domain'])
|
||||
))->resolve($request);
|
||||
|
||||
$code = Str::random(48);
|
||||
\Illuminate\Support\Facades\Cache::put("impersonate:{$code}", [
|
||||
'token' => $token,
|
||||
'refresh_token' => $refreshToken,
|
||||
'client' => $clientResource,
|
||||
], 120);
|
||||
|
||||
$admin = Auth::guard('admin')->user();
|
||||
|
||||
Log::create([
|
||||
'agent' => 'admin',
|
||||
'client_ip' => $request->ip(),
|
||||
'description' => sprintf(
|
||||
'%s đăng nhập hộ khách hàng %s',
|
||||
$admin->username ?? $admin->email ?? 'Admin',
|
||||
$customer->email,
|
||||
),
|
||||
'customer_id' => $customer->id,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => ['code' => $code],
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function resetPassword(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$customer = $this->customerRepository->findBy('uuid', $uuid);
|
||||
@@ -709,6 +776,85 @@ class CustomerController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, Request $request): JsonResponse
|
||||
{
|
||||
$customer = $this->customerRepository->findBy('uuid', $uuid);
|
||||
if (!$customer) {
|
||||
return response()->json(['error' => true, 'message' => "Can't find customer"], 404);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'ids' => 'required|array|min:1',
|
||||
'ids.*' => 'integer',
|
||||
]);
|
||||
|
||||
$deleted = \App\Models\Service::where('customer_id', $customer->id)
|
||||
->whereIn('id', $data['ids'])
|
||||
->delete();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Đã xoá ' . $deleted . ' dịch vụ',
|
||||
'data' => ['deleted' => $deleted],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cập nhật thông tin dịch vụ của khách hàng (server_name/hostname, status, ngày,...).
|
||||
* Đồng bộ hostname sang module_vmware nếu service đã gắn VM.
|
||||
*/
|
||||
public function updateService(string $uuid, int $serviceId, Request $request): JsonResponse
|
||||
{
|
||||
$customer = $this->customerRepository->findBy('uuid', $uuid);
|
||||
if (!$customer) {
|
||||
return response()->json(['error' => true, 'message' => "Can't find customer"], 404);
|
||||
}
|
||||
|
||||
$service = \App\Models\Service::where('customer_id', $customer->id)
|
||||
->where('id', $serviceId)
|
||||
->first();
|
||||
if (!$service) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy dịch vụ'], 404);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'server_name' => 'nullable|string|max:255',
|
||||
'status' => 'nullable|in:pending,active,suspended,expired,cancelled,terminated',
|
||||
'auto_renew' => 'nullable|boolean',
|
||||
'started_at' => 'nullable|date',
|
||||
'expires_at' => 'nullable|date',
|
||||
'note' => 'nullable|string',
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$service->fill($data);
|
||||
$service->save();
|
||||
|
||||
// Đồng bộ hostname sang module_vmware nếu có gán VM
|
||||
if ($service->vm_id && array_key_exists('server_name', $data)) {
|
||||
\App\Models\ModuleVmware::where('id', $service->vm_id)
|
||||
->update(['hostname' => $data['server_name']]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Cập nhật dịch vụ thành công',
|
||||
'data' => $service->load(['product', 'orderItem', 'invoice']),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
return response()->json(['error' => true, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a service for a customer. For VPS products, accepts a
|
||||
* `virtual_machine_id` from the vCenter inventory and auto-creates the
|
||||
@@ -730,9 +876,14 @@ class CustomerController extends Controller
|
||||
'started_at' => 'nullable|date',
|
||||
'expires_at' => 'nullable|date',
|
||||
'note' => 'nullable|string',
|
||||
// New: billing & payment
|
||||
'billing_cycle' => 'nullable|in:monthly,quarterly,semi_annually,annually,biennially,triennially',
|
||||
'payment_method' => 'required|in:transfer,balance',
|
||||
'proof_images' => 'nullable|array',
|
||||
'proof_images.*' => 'file|image|max:5120',
|
||||
]);
|
||||
|
||||
$product = \App\Models\Product::find($data['product_id']);
|
||||
$product = \App\Models\Product::with('pricings')->find($data['product_id']);
|
||||
if ($product->product_type === 'vps' && empty($data['virtual_machine_id'])) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
@@ -740,35 +891,164 @@ class CustomerController extends Controller
|
||||
], 422);
|
||||
}
|
||||
|
||||
$billingCycle = $data['billing_cycle'] ?? 'monthly';
|
||||
$months = $this->cycleToMonths($billingCycle);
|
||||
|
||||
$pricing = $product->pricings
|
||||
->where('billing_cycle', $billingCycle)
|
||||
->first();
|
||||
$basePrice = (int) ($pricing->price ?? 0);
|
||||
|
||||
$paymentMethod = $data['payment_method'];
|
||||
|
||||
// Đối với balance: kiểm tra số dư trước khi vào transaction
|
||||
if ($paymentMethod === 'balance' && (int) $customer->total < $basePrice) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => sprintf(
|
||||
'Số dư khách không đủ. Hiện có: %s VNĐ, cần: %s VNĐ.',
|
||||
number_format((int) $customer->total),
|
||||
number_format($basePrice)
|
||||
),
|
||||
], 422);
|
||||
}
|
||||
|
||||
// Upload proof images (chuyển khoản)
|
||||
$proofPaths = [];
|
||||
if ($paymentMethod === 'transfer' && $request->hasFile('proof_images')) {
|
||||
foreach ($request->file('proof_images') as $file) {
|
||||
$proofPaths[] = $file->store('payment-proofs', 'public');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// 1) ModuleVmware: snapshot từ virtual_machines
|
||||
$vmId = null;
|
||||
if (!empty($data['virtual_machine_id'])) {
|
||||
$vm = \App\Models\VirtualMachines::find($data['virtual_machine_id']);
|
||||
$moduleVm = \App\Models\ModuleVmware::create([
|
||||
'customer_id' => $customer->id,
|
||||
'name' => $vm->name,
|
||||
'vmware_id' => $vm->vm_id,
|
||||
'virtual_machine_id' => $vm->id,
|
||||
'hostname' => $data['server_name'] ?? $vm->name,
|
||||
'status' => 1,
|
||||
]);
|
||||
$vm = \App\Models\VirtualMachines::with('datacenter')
|
||||
->find($data['virtual_machine_id']);
|
||||
|
||||
$vcenterId = $vm->datacenter->vcenter_id ?? null;
|
||||
|
||||
$moduleVm = \App\Models\ModuleVmware::updateOrCreate(
|
||||
['virtual_machine_id' => $vm->id],
|
||||
[
|
||||
'customer_id' => $customer->id,
|
||||
'name' => $vm->name,
|
||||
'vmware_id' => $vm->vm_id,
|
||||
'vcenter_id' => $vcenterId,
|
||||
'hostname' => $data['server_name'] ?? $vm->name,
|
||||
'cpu' => $vm->cpu,
|
||||
'ram_mb' => $vm->ram_mb,
|
||||
'disk_gb' => $vm->disk_gb ?? null,
|
||||
'status' => 1,
|
||||
]
|
||||
);
|
||||
$vmId = $moduleVm->id;
|
||||
}
|
||||
|
||||
$service = \App\Models\Service::create([
|
||||
'customer_id' => $customer->id,
|
||||
'product_id' => $data['product_id'],
|
||||
'vm_id' => $vmId,
|
||||
'server_name' => $data['server_name'] ?? null,
|
||||
'status' => $data['status'] ?? 'active',
|
||||
'auto_renew' => (bool) ($data['auto_renew'] ?? false),
|
||||
'started_at' => $data['started_at'] ?? now(),
|
||||
'expires_at' => $data['expires_at'] ?? null,
|
||||
'note' => $data['note'] ?? null,
|
||||
// 2) Order + OrderItem (mô phỏng flow customer đặt hàng)
|
||||
$order = Order::create([
|
||||
'order_num' => OrderHelper::generateOrderNumber(),
|
||||
'customer_id' => $customer->id,
|
||||
'sub_total' => $basePrice,
|
||||
'discount_amount' => 0,
|
||||
'total' => $basePrice,
|
||||
'status' => OrderStatus::ACTIVE->value,
|
||||
'payment_method' => $paymentMethod,
|
||||
'client_ip' => $request->ip(),
|
||||
]);
|
||||
|
||||
$orderItem = \App\Models\OrderItem::create([
|
||||
'order_id' => $order->id,
|
||||
'product_id' => $product->id,
|
||||
'billing_cycle' => $billingCycle,
|
||||
'months' => $months,
|
||||
'server_name' => $data['server_name'] ?? null,
|
||||
'quantity' => 1,
|
||||
'price' => $basePrice,
|
||||
]);
|
||||
|
||||
// 3) Invoice — đánh dấu PAID luôn vì admin đứng ra tạo & xác nhận thanh toán
|
||||
$invoice = Invoice::create([
|
||||
'invoice_number' => OrderHelper::generateOrderNumber('INV'),
|
||||
'customer_id' => $customer->id,
|
||||
'order_id' => $order->id,
|
||||
'invoice_type' => 1,
|
||||
'sub_total' => $basePrice,
|
||||
'discount_amount' => 0,
|
||||
'tax' => 0,
|
||||
'total' => $basePrice,
|
||||
'status' => InvoiceStatus::PAID->value,
|
||||
'payment_method' => $paymentMethod,
|
||||
'paid_at' => now(),
|
||||
'due_date' => now()->addMonths($months)->toDateString(),
|
||||
]);
|
||||
|
||||
\App\Models\InvoiceItem::create([
|
||||
'invoice_id' => $invoice->id,
|
||||
'product_id' => $product->id,
|
||||
'type' => 'service',
|
||||
'description' => $product->name ?? 'Dịch vụ',
|
||||
'months' => $months,
|
||||
'quantity' => 1,
|
||||
'unit_price' => $basePrice,
|
||||
'total_price' => $basePrice,
|
||||
]);
|
||||
|
||||
// 4) Payment processing
|
||||
if ($paymentMethod === 'balance') {
|
||||
$customer->total = (int) $customer->total - $basePrice;
|
||||
$customer->save();
|
||||
}
|
||||
|
||||
Transaction::create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'customer_id' => $customer->id,
|
||||
'user_id' => Auth::id(),
|
||||
'trans' => $order->order_num,
|
||||
'amount' => $basePrice,
|
||||
'type' => $paymentMethod === 'transfer' ? 'transfer' : 'balance',
|
||||
'status' => 1, // paid
|
||||
'note' => $paymentMethod === 'transfer'
|
||||
? 'Admin tạo dịch vụ - thanh toán chuyển khoản'
|
||||
: 'Admin tạo dịch vụ - trừ số dư khách hàng',
|
||||
'proof_image' => !empty($proofPaths) ? json_encode($proofPaths) : null,
|
||||
]);
|
||||
|
||||
// 5) Service — updateOrCreate để tránh trùng khi cùng VM được gán lại
|
||||
$startedAt = $data['started_at'] ?? now();
|
||||
$expiresAt = $data['expires_at']
|
||||
?? \Carbon\Carbon::parse($startedAt)->addMonths($months);
|
||||
|
||||
$serviceLookup = $vmId
|
||||
? ['customer_id' => $customer->id, 'vm_id' => $vmId]
|
||||
: [
|
||||
'customer_id' => $customer->id,
|
||||
'product_id' => $product->id,
|
||||
'vm_id' => null,
|
||||
'server_name' => $data['server_name'] ?? null,
|
||||
];
|
||||
|
||||
$service = \App\Models\Service::updateOrCreate(
|
||||
$serviceLookup,
|
||||
[
|
||||
'customer_id' => $customer->id,
|
||||
'product_id' => $product->id,
|
||||
'vm_id' => $vmId,
|
||||
'order_item_id' => $orderItem->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'server_name' => $data['server_name'] ?? null,
|
||||
'status' => $data['status'] ?? 'active',
|
||||
'auto_renew' => (bool) ($data['auto_renew'] ?? false),
|
||||
'started_at' => $startedAt,
|
||||
'expires_at' => $expiresAt,
|
||||
'note' => $data['note'] ?? null,
|
||||
]
|
||||
);
|
||||
|
||||
DB::commit();
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
@@ -843,4 +1123,17 @@ class CustomerController extends Controller
|
||||
'data' => $orders
|
||||
]);
|
||||
}
|
||||
|
||||
private function cycleToMonths(?string $cycle): int
|
||||
{
|
||||
return match ($cycle) {
|
||||
'monthly' => 1,
|
||||
'quarterly' => 3,
|
||||
'semi_annually' => 6,
|
||||
'annually' => 12,
|
||||
'biennially' => 24,
|
||||
'triennially' => 36,
|
||||
default => 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,6 +309,37 @@ class ClientController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Đổi mã impersonate (do admin cấp) lấy access token + refresh token.
|
||||
* Endpoint public — code chỉ dùng được 1 lần và hết hạn sau 120s.
|
||||
*/
|
||||
public function impersonateExchange(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'code' => ['required', 'string', 'max:128'],
|
||||
]);
|
||||
|
||||
$code = (string) $request->input('code');
|
||||
$payload = \Illuminate\Support\Facades\Cache::pull("impersonate:{$code}");
|
||||
|
||||
if (!$payload) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Mã đăng nhập không hợp lệ hoặc đã hết hạn.',
|
||||
], 401);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'token' => $payload['token'],
|
||||
'refresh_token' => $payload['refresh_token'],
|
||||
'client' => $payload['client'],
|
||||
'expires_in' => config('jwt.ttl', 60) * 60,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function forgotPassword(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
|
||||
@@ -17,7 +17,7 @@ class VpsServiceResource extends JsonResource
|
||||
$orderItem = $this->orderItem;
|
||||
$invoice = $this->invoice;
|
||||
$order = $orderItem?->order ?? $invoice?->order;
|
||||
$product = $orderItem?->product;
|
||||
$product = $orderItem?->product ?? $this->product;
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
|
||||
@@ -46,6 +46,8 @@ class SyncVirtualMachine implements ShouldQueue
|
||||
$vCenterCount = 0;
|
||||
$vmTotalCount = 0;
|
||||
|
||||
$totalDeletedCount = 0;
|
||||
|
||||
foreach ($data as $item) {
|
||||
Log::info("Processing vCenter: {$item->host}");
|
||||
$this->vCenter->apiUri = $item->host;
|
||||
@@ -65,24 +67,27 @@ class SyncVirtualMachine implements ShouldQueue
|
||||
continue;
|
||||
}
|
||||
|
||||
$syncedVmIds = [];
|
||||
$fetchFailed = false;
|
||||
|
||||
$datacenters = ModuleDatacenter::where('vcenter_id', $item->id)->get();
|
||||
if ($datacenters->count() > 0) {
|
||||
foreach ($datacenters as $dc) {
|
||||
// Get all hosts for this datacenter
|
||||
$hosts = ModuleHost::where('module_datacenter_id', $dc->id)->get();
|
||||
|
||||
|
||||
if ($hosts->count() > 0) {
|
||||
foreach ($hosts as $host) {
|
||||
Log::info("Fetching VMs for host: {$host->host_id} in datacenter: {$dc->name}");
|
||||
$vms = $this->vCenter->getAllVirtualMachine($dc->datacenter_id, $host->host_id);
|
||||
$vmCount = $this->processVMs($vms, $item, $dc->id, $host->id);
|
||||
$vmCount = $this->processVMs($vms, $item, $dc->id, $host->id, $syncedVmIds, $fetchFailed);
|
||||
$vmTotalCount += $vmCount;
|
||||
}
|
||||
} else {
|
||||
// Fallback: Sync VMs by datacenter only
|
||||
Log::info("No hosts found for datacenter {$dc->name}, fetching VMs by datacenter only");
|
||||
$vms = $this->vCenter->getAllVirtualMachine($dc->datacenter_id);
|
||||
$vmCount = $this->processVMs($vms, $item, $dc->id, null);
|
||||
$vmCount = $this->processVMs($vms, $item, $dc->id, null, $syncedVmIds, $fetchFailed);
|
||||
$vmTotalCount += $vmCount;
|
||||
}
|
||||
}
|
||||
@@ -90,10 +95,20 @@ class SyncVirtualMachine implements ShouldQueue
|
||||
// Fallback: Sync all VMs without datacenter context
|
||||
Log::info("No datacenters found, fetching all VMs for {$item->host}");
|
||||
$vms = $this->vCenter->getAllVirtualMachine();
|
||||
$vmCount = $this->processVMs($vms, $item, null, null);
|
||||
$vmCount = $this->processVMs($vms, $item, null, null, $syncedVmIds, $fetchFailed);
|
||||
$vmTotalCount += $vmCount;
|
||||
}
|
||||
|
||||
// Cleanup stale VMs in DB that no longer exist on vCenter.
|
||||
// Only run when all fetches succeeded to avoid wiping data on transient failures.
|
||||
if (!$fetchFailed) {
|
||||
$datacenterIds = $datacenters->pluck('id')->all();
|
||||
$deletedCount = $this->cleanupStaleVMs($datacenterIds, $syncedVmIds, $item);
|
||||
$totalDeletedCount += $deletedCount;
|
||||
} else {
|
||||
Log::warning("Skip cleanup for vCenter {$item->host} because some VM fetches failed.");
|
||||
}
|
||||
|
||||
$vCenterCount++; // Increment vCenter synced count
|
||||
}
|
||||
|
||||
@@ -102,6 +117,7 @@ class SyncVirtualMachine implements ShouldQueue
|
||||
'message' => 'Sync VMs completed successfully',
|
||||
'synced_vcenter_count' => $vCenterCount,
|
||||
'synced_vm_count' => $vmTotalCount,
|
||||
'deleted_vm_count' => $totalDeletedCount,
|
||||
]);
|
||||
|
||||
} catch (Throwable $e) {
|
||||
@@ -117,7 +133,7 @@ class SyncVirtualMachine implements ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
private function processVMs($vms, $vCenterItem, $datacenterId, $hostId)
|
||||
private function processVMs($vms, $vCenterItem, $datacenterId, $hostId, array &$syncedVmIds, bool &$fetchFailed)
|
||||
{
|
||||
// If token expired, retry login (handled inside loop in previous logic, but simpler here if we just handle the array check)
|
||||
if ($vms === 'Login_Again') {
|
||||
@@ -139,6 +155,7 @@ class SyncVirtualMachine implements ShouldQueue
|
||||
|
||||
if (!is_array($vms)) {
|
||||
Log::warning("Failed to fetch VMs or empty response. Response: " . json_encode($vms));
|
||||
$fetchFailed = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -161,8 +178,48 @@ class SyncVirtualMachine implements ShouldQueue
|
||||
$vmObj->last_synced_at = now();
|
||||
|
||||
$vmObj->save();
|
||||
$syncedVmIds[] = $vmData['vm'];
|
||||
$count++;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete VMs in DB that belong to the given vCenter but no longer exist on vCenter.
|
||||
*/
|
||||
private function cleanupStaleVMs(array $datacenterIds, array $syncedVmIds, $vCenterItem): int
|
||||
{
|
||||
$syncedVmIds = array_values(array_unique($syncedVmIds));
|
||||
|
||||
if (!empty($datacenterIds)) {
|
||||
$query = VirtualMachines::whereIn('datacenter_id', $datacenterIds);
|
||||
} else {
|
||||
// No datacenter context: fallback - chỉ xoá khi đã sync được ít nhất 1 VM
|
||||
// để tránh xoá nhầm khi vCenter rỗng do lỗi.
|
||||
if (empty($syncedVmIds)) {
|
||||
Log::warning("Skip cleanup for {$vCenterItem->host}: no datacenters and no synced VMs.");
|
||||
return 0;
|
||||
}
|
||||
$query = VirtualMachines::query();
|
||||
}
|
||||
|
||||
if (!empty($syncedVmIds)) {
|
||||
$query->whereNotIn('vm_id', $syncedVmIds);
|
||||
}
|
||||
|
||||
$staleVms = $query->get(['id', 'vm_id', 'name']);
|
||||
|
||||
if ($staleVms->isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($staleVms as $stale) {
|
||||
Log::info("Deleting stale VM removed from vCenter {$vCenterItem->host}: {$stale->name} ({$stale->vm_id})");
|
||||
}
|
||||
|
||||
$deleted = VirtualMachines::whereIn('id', $staleVms->pluck('id')->all())->delete();
|
||||
Log::info("Cleanup vCenter {$vCenterItem->host}: deleted {$deleted} stale VM(s).");
|
||||
|
||||
return (int) $deleted;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ class ModuleVmware extends Model
|
||||
'dns',
|
||||
'plain_password',
|
||||
'virtual_machine_id',
|
||||
'cpu',
|
||||
'ram_mb',
|
||||
'disk_gb',
|
||||
];
|
||||
|
||||
// NOTE: password must NOT use 'hashed' cast — it is a VM guest credential
|
||||
|
||||
@@ -19,6 +19,7 @@ class ServiceClientRepository extends BaseApiRepository implements ServiceClient
|
||||
{
|
||||
$query = $this->model
|
||||
->with([
|
||||
'product',
|
||||
'invoice.order',
|
||||
'orderItem' => fn($q) => $q->with(['product', 'os.osGroup', 'order']),
|
||||
])
|
||||
@@ -27,7 +28,7 @@ class ServiceClientRepository extends BaseApiRepository implements ServiceClient
|
||||
->orderBy('started_at', 'desc');
|
||||
|
||||
if ($productType) {
|
||||
$query->whereHas('orderItem.product', function ($builder) use ($productType) {
|
||||
$query->whereHas('product', function ($builder) use ($productType) {
|
||||
$builder->where('product_type', $productType);
|
||||
});
|
||||
}
|
||||
|
||||
+2
-1
@@ -38,7 +38,8 @@
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
"Database\\Seeders\\": "database/seeders/",
|
||||
"Modules\\": "modules/"
|
||||
},
|
||||
"files": [
|
||||
"app/Http/Helpers/function_helper.php"
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('module_vmware', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('module_vmware', 'cpu')) {
|
||||
$table->integer('cpu')->nullable()->after('hostname');
|
||||
}
|
||||
if (!Schema::hasColumn('module_vmware', 'ram_mb')) {
|
||||
$table->integer('ram_mb')->nullable()->after('cpu');
|
||||
}
|
||||
if (!Schema::hasColumn('module_vmware', 'disk_gb')) {
|
||||
$table->integer('disk_gb')->nullable()->after('ram_mb');
|
||||
}
|
||||
});
|
||||
|
||||
// Backfill vcenter_id, cpu, ram_mb from virtual_machines for rows that are
|
||||
// linked via virtual_machine_id but missing those fields.
|
||||
if (
|
||||
Schema::hasTable('module_vmware')
|
||||
&& Schema::hasTable('virtual_machines')
|
||||
&& Schema::hasTable('module_datacenter')
|
||||
&& Schema::hasColumn('module_vmware', 'virtual_machine_id')
|
||||
) {
|
||||
DB::statement('
|
||||
UPDATE module_vmware mv
|
||||
INNER JOIN virtual_machines vm ON vm.id = mv.virtual_machine_id
|
||||
LEFT JOIN module_datacenter dc ON dc.id = vm.datacenter_id
|
||||
SET
|
||||
mv.vcenter_id = COALESCE(mv.vcenter_id, dc.vcenter_id),
|
||||
mv.cpu = COALESCE(mv.cpu, vm.cpu),
|
||||
mv.ram_mb = COALESCE(mv.ram_mb, vm.ram_mb)
|
||||
WHERE mv.virtual_machine_id IS NOT NULL
|
||||
');
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('module_vmware', function (Blueprint $table) {
|
||||
foreach (['cpu', 'ram_mb', 'disk_gb'] as $col) {
|
||||
if (Schema::hasColumn('module_vmware', $col)) {
|
||||
$table->dropColumn($col);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\DTOs;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class DomainFluctuationDTO
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $domainName,
|
||||
public readonly int $termId,
|
||||
public readonly string $ownerName,
|
||||
public readonly string $ownerType,
|
||||
public readonly string $address,
|
||||
public readonly string $countryCode,
|
||||
public readonly string $adminName,
|
||||
public readonly string $phone,
|
||||
public readonly string $email,
|
||||
public readonly int $registeredDate,
|
||||
public readonly int $expiredDate,
|
||||
public readonly ?string $wardName = null,
|
||||
public readonly ?string $districtName = null,
|
||||
public readonly ?string $cityName = null,
|
||||
public readonly ?string $cityCode = null,
|
||||
public readonly ?string $fax = null,
|
||||
public readonly ?string $businessCode = null,
|
||||
public readonly ?string $eidCode = null,
|
||||
public readonly ?string $personalId = null,
|
||||
public readonly ?string $birthDate = null,
|
||||
public readonly ?string $icannRegistrarName = null,
|
||||
public readonly ?string $icannRegistrarTradeName = null,
|
||||
public readonly ?bool $isAgentManager = null,
|
||||
public readonly ?string $action = null,
|
||||
public readonly ?string $actionReason = null,
|
||||
public readonly ?string $actionSource = null,
|
||||
public readonly ?int $actionDate = null,
|
||||
public readonly ?string $note = null,
|
||||
public readonly ?int $ianaNumber = null,
|
||||
public readonly ?int $status = null,
|
||||
) {}
|
||||
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
return new self(
|
||||
domainName: $data['domainName'],
|
||||
termId: (int) ($data['term_id'] ?? $data['termId']),
|
||||
ownerName: $data['ownerName'],
|
||||
ownerType: $data['ownerType'],
|
||||
address: $data['address'],
|
||||
countryCode: $data['countryCode'],
|
||||
adminName: $data['adminName'],
|
||||
phone: $data['phone'],
|
||||
email: $data['email'],
|
||||
registeredDate: self::toTimestamp($data['registeredDate']),
|
||||
expiredDate: self::toTimestamp($data['expiredDate']),
|
||||
wardName: $data['wardName'] ?? null,
|
||||
districtName: $data['districtName'] ?? null,
|
||||
cityName: $data['cityName'] ?? null,
|
||||
cityCode: $data['cityCode'] ?? null,
|
||||
fax: $data['fax'] ?? null,
|
||||
businessCode: $data['businessCode'] ?? null,
|
||||
eidCode: $data['eidCode'] ?? null,
|
||||
personalId: $data['personalId'] ?? null,
|
||||
birthDate: $data['birthDate'] ?? null,
|
||||
icannRegistrarName: $data['icannRegistrarName'] ?? null,
|
||||
icannRegistrarTradeName: $data['icannRegistrarTradeName'] ?? null,
|
||||
isAgentManager: isset($data['isAgentManager']) ? (bool) $data['isAgentManager'] : null,
|
||||
action: $data['action'] ?? null,
|
||||
actionReason: $data['actionReason'] ?? null,
|
||||
actionSource: $data['actionSource'] ?? null,
|
||||
actionDate: isset($data['actionDate']) ? self::toTimestamp($data['actionDate']) : null,
|
||||
note: $data['note'] ?? null,
|
||||
ianaNumber: isset($data['ianaNumber']) ? (int) $data['ianaNumber'] : null,
|
||||
status: isset($data['status']) ? (int) $data['status'] : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return array_filter([
|
||||
'domainName' => $this->domainName,
|
||||
'term_id' => $this->termId,
|
||||
'ownerName' => $this->ownerName,
|
||||
'ownerType' => $this->ownerType,
|
||||
'address' => $this->address,
|
||||
'countryCode' => $this->countryCode,
|
||||
'adminName' => $this->adminName,
|
||||
'phone' => $this->phone,
|
||||
'email' => $this->email,
|
||||
'registeredDate' => $this->registeredDate,
|
||||
'expiredDate' => $this->expiredDate,
|
||||
'wardName' => $this->wardName,
|
||||
'districtName' => $this->districtName,
|
||||
'cityName' => $this->cityName,
|
||||
'cityCode' => $this->cityCode,
|
||||
'fax' => $this->fax,
|
||||
'businessCode' => $this->businessCode,
|
||||
'eidCode' => $this->eidCode,
|
||||
'personalId' => $this->personalId,
|
||||
'birthDate' => $this->birthDate,
|
||||
'icannRegistrarName' => $this->icannRegistrarName,
|
||||
'icannRegistrarTradeName' => $this->icannRegistrarTradeName,
|
||||
'isAgentManager' => $this->isAgentManager,
|
||||
'action' => $this->action,
|
||||
'actionReason' => $this->actionReason,
|
||||
'actionSource' => $this->actionSource,
|
||||
'actionDate' => $this->actionDate,
|
||||
'note' => $this->note,
|
||||
'ianaNumber' => $this->ianaNumber,
|
||||
'status' => $this->status,
|
||||
], static fn ($value) => $value !== null);
|
||||
}
|
||||
|
||||
private static function toTimestamp(int|string $value): int
|
||||
{
|
||||
if (is_int($value) || ctype_digit((string) $value)) {
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
return Carbon::parse($value)->timestamp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\DTOs;
|
||||
|
||||
class DomainFluctuationFilterDTO
|
||||
{
|
||||
public function __construct(
|
||||
public readonly ?int $termId = null,
|
||||
public readonly ?string $keyword = null,
|
||||
public readonly ?string $ownerType = null,
|
||||
public readonly ?int $status = null,
|
||||
public readonly ?string $action = null,
|
||||
public readonly ?int $from = null,
|
||||
public readonly ?int $to = null,
|
||||
public readonly int $perPage = 20,
|
||||
public readonly int $page = 1,
|
||||
public readonly string $sortBy = 'id',
|
||||
public readonly string $sortDir = 'desc',
|
||||
) {}
|
||||
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
return new self(
|
||||
termId: isset($data['term_id']) ? (int) $data['term_id'] : null,
|
||||
keyword: $data['keyword'] ?? null,
|
||||
ownerType: $data['ownerType'] ?? null,
|
||||
status: isset($data['status']) ? (int) $data['status'] : null,
|
||||
action: $data['action'] ?? null,
|
||||
from: isset($data['from']) ? (int) $data['from'] : null,
|
||||
to: isset($data['to']) ? (int) $data['to'] : null,
|
||||
perPage: (int) ($data['per_page'] ?? 20),
|
||||
page: (int) ($data['page'] ?? 1),
|
||||
sortBy: $data['sort_by'] ?? 'id',
|
||||
sortDir: strtolower($data['sort_dir'] ?? 'desc') === 'asc' ? 'asc' : 'desc',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\DTOs;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class DomainFluctuationTermDTO
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $termName,
|
||||
public readonly string $description,
|
||||
public readonly int $dateCreate,
|
||||
public readonly int $userId,
|
||||
public readonly bool $status = false,
|
||||
public readonly string $type = 'vnnic_06',
|
||||
) {}
|
||||
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
$dateCreate = $data['date_create'] ?? null;
|
||||
if ($dateCreate === null) {
|
||||
$dateCreate = time();
|
||||
} elseif (! is_int($dateCreate) && ! ctype_digit((string) $dateCreate)) {
|
||||
$dateCreate = Carbon::parse($dateCreate)->timestamp;
|
||||
}
|
||||
|
||||
return new self(
|
||||
termName: $data['term_name'],
|
||||
description: $data['description'] ?? '',
|
||||
dateCreate: (int) $dateCreate,
|
||||
userId: (int) $data['user_id'],
|
||||
status: (bool) ($data['status'] ?? false),
|
||||
type: $data['type'] ?? 'vnnic_06',
|
||||
);
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'term_name' => $this->termName,
|
||||
'description' => $this->description,
|
||||
'date_create' => $this->dateCreate,
|
||||
'user_id' => $this->userId,
|
||||
'status' => $this->status,
|
||||
];
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Controllers\Api\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\IndexDomainFluctuationRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\StoreDomainFluctuationRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\UpdateDomainFluctuationRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Resources\DomainFluctuationResource;
|
||||
use Modules\DomainFluctuation\App\Models\DomainFluctuation;
|
||||
|
||||
class DomainFluctuationController extends Controller
|
||||
{
|
||||
public function index(IndexDomainFluctuationRequest $request): JsonResponse
|
||||
{
|
||||
$filter = $request->toDTO();
|
||||
|
||||
$query = DomainFluctuation::query()->with('term');
|
||||
|
||||
if ($filter->termId) {
|
||||
$query->where('term_id', $filter->termId);
|
||||
}
|
||||
|
||||
if ($filter->keyword) {
|
||||
$kw = '%' . $filter->keyword . '%';
|
||||
$query->where(function ($q) use ($kw) {
|
||||
$q->where('domainName', 'like', $kw)
|
||||
->orWhere('ownerName', 'like', $kw)
|
||||
->orWhere('email', 'like', $kw)
|
||||
->orWhere('phone', 'like', $kw);
|
||||
});
|
||||
}
|
||||
|
||||
if ($filter->ownerType) {
|
||||
$query->where('ownerType', $filter->ownerType);
|
||||
}
|
||||
|
||||
if ($filter->status !== null) {
|
||||
$query->where('status', $filter->status);
|
||||
}
|
||||
|
||||
if ($filter->action) {
|
||||
$query->where('action', $filter->action);
|
||||
}
|
||||
|
||||
if ($filter->from) {
|
||||
$query->where('registeredDate', '>=', $filter->from);
|
||||
}
|
||||
|
||||
if ($filter->to) {
|
||||
$query->where('registeredDate', '<=', $filter->to);
|
||||
}
|
||||
|
||||
$query->orderBy($filter->sortBy, $filter->sortDir);
|
||||
|
||||
$paginator = $query->paginate($filter->perPage, ['*'], 'page', $filter->page);
|
||||
|
||||
return DomainFluctuationResource::collection($paginator)->response();
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$domain = DomainFluctuation::with('term')->find($id);
|
||||
|
||||
if (! $domain) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy tên miền',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => DomainFluctuationResource::make($domain),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreDomainFluctuationRequest $request): JsonResponse
|
||||
{
|
||||
$dto = $request->toDTO();
|
||||
|
||||
$domain = DB::transaction(fn () => DomainFluctuation::create($dto->toArray()));
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Tạo tên miền thành công',
|
||||
'data' => DomainFluctuationResource::make($domain),
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(int $id, UpdateDomainFluctuationRequest $request): JsonResponse
|
||||
{
|
||||
$domain = DomainFluctuation::find($id);
|
||||
|
||||
if (! $domain) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy tên miền',
|
||||
], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
DB::transaction(fn () => $domain->update($request->toDTO()->toArray()));
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Cập nhật tên miền thành công',
|
||||
'data' => DomainFluctuationResource::make($domain->fresh('term')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$domain = DomainFluctuation::find($id);
|
||||
|
||||
if (! $domain) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy tên miền',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$domain->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Xoá tên miền thành công',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Controllers\Api\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\StoreTermRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Resources\DomainFluctuationTermResource;
|
||||
use Modules\DomainFluctuation\App\Models\DomainFluctuationTerm;
|
||||
use Modules\DomainFluctuation\App\Models\TermFluctuationType;
|
||||
|
||||
class TermController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = (int) $request->input('per_page', 20);
|
||||
|
||||
$terms = DomainFluctuationTerm::query()
|
||||
->with('type')
|
||||
->withCount('fluctuations')
|
||||
->orderByDesc('id')
|
||||
->paginate($perPage);
|
||||
|
||||
return DomainFluctuationTermResource::collection($terms)->response();
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$term = DomainFluctuationTerm::with('type')->withCount('fluctuations')->find($id);
|
||||
|
||||
if (! $term) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy đợt khai báo',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => DomainFluctuationTermResource::make($term),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreTermRequest $request): JsonResponse
|
||||
{
|
||||
$userId = (int) ($request->user()?->id ?? 0);
|
||||
$dto = $request->toDTO($userId);
|
||||
|
||||
$term = DB::transaction(function () use ($dto, $request) {
|
||||
$term = DomainFluctuationTerm::create($dto->toArray());
|
||||
|
||||
TermFluctuationType::create([
|
||||
'term_fluctuation_id' => $term->id,
|
||||
'type' => $request->input('type', 'vnnic_06'),
|
||||
]);
|
||||
|
||||
return $term->load('type');
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Tạo đợt khai báo thành công',
|
||||
'data' => DomainFluctuationTermResource::make($term),
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(int $id, StoreTermRequest $request): JsonResponse
|
||||
{
|
||||
$term = DomainFluctuationTerm::find($id);
|
||||
|
||||
if (! $term) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy đợt khai báo',
|
||||
], 404);
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($term, $request) {
|
||||
$term->update($request->only(['term_name', 'description', 'date_create', 'status']));
|
||||
|
||||
if ($request->filled('type')) {
|
||||
TermFluctuationType::updateOrCreate(
|
||||
['term_fluctuation_id' => $term->id],
|
||||
['type' => $request->input('type')],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Cập nhật đợt khai báo thành công',
|
||||
'data' => DomainFluctuationTermResource::make($term->fresh('type')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$term = DomainFluctuationTerm::find($id);
|
||||
|
||||
if (! $term) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy đợt khai báo',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$term->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Xoá đợt khai báo thành công',
|
||||
]);
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Controllers\Api\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\IndexDomainFluctuationRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Resources\DomainFluctuationResource;
|
||||
use Modules\DomainFluctuation\App\Models\DomainFluctuation;
|
||||
|
||||
class DomainFluctuationController extends Controller
|
||||
{
|
||||
public function index(IndexDomainFluctuationRequest $request): JsonResponse
|
||||
{
|
||||
$filter = $request->toDTO();
|
||||
|
||||
$query = DomainFluctuation::query()
|
||||
->with('term')
|
||||
->where('status', 1);
|
||||
|
||||
if ($filter->termId) {
|
||||
$query->where('term_id', $filter->termId);
|
||||
}
|
||||
|
||||
if ($filter->keyword) {
|
||||
$kw = '%' . $filter->keyword . '%';
|
||||
$query->where(function ($q) use ($kw) {
|
||||
$q->where('domainName', 'like', $kw)
|
||||
->orWhere('ownerName', 'like', $kw);
|
||||
});
|
||||
}
|
||||
|
||||
$query->orderBy($filter->sortBy, $filter->sortDir);
|
||||
|
||||
$paginator = $query->paginate($filter->perPage, ['*'], 'page', $filter->page);
|
||||
|
||||
return DomainFluctuationResource::collection($paginator)->response();
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$domain = DomainFluctuation::with('term')->where('status', 1)->find($id);
|
||||
|
||||
if (! $domain) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy tên miền',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => DomainFluctuationResource::make($domain),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Modules\DomainFluctuation\App\DTOs\DomainFluctuationFilterDTO;
|
||||
|
||||
class IndexDomainFluctuationRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'term_id' => ['nullable', 'integer'],
|
||||
'keyword' => ['nullable', 'string', 'max:255'],
|
||||
'ownerType' => ['nullable', 'in:C,T'],
|
||||
'status' => ['nullable', 'integer', 'in:0,1'],
|
||||
'action' => ['nullable', 'string', 'max:100'],
|
||||
'from' => ['nullable', 'integer'],
|
||||
'to' => ['nullable', 'integer'],
|
||||
'per_page' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
'page' => ['nullable', 'integer', 'min:1'],
|
||||
'sort_by' => ['nullable', 'in:id,domainName,registeredDate,expiredDate,actionDate,created_at'],
|
||||
'sort_dir' => ['nullable', 'in:asc,desc'],
|
||||
];
|
||||
}
|
||||
|
||||
public function toDTO(): DomainFluctuationFilterDTO
|
||||
{
|
||||
return DomainFluctuationFilterDTO::fromArray($this->validated());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Modules\DomainFluctuation\App\DTOs\DomainFluctuationDTO;
|
||||
|
||||
class StoreDomainFluctuationRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'domainName' => ['required', 'string', 'max:255'],
|
||||
'term_id' => ['required', 'integer', 'exists:domain_fluctuation_terms,id'],
|
||||
'ownerName' => ['required', 'string', 'max:255'],
|
||||
'ownerType' => ['required', 'in:C,T'],
|
||||
'address' => ['required', 'string'],
|
||||
'countryCode' => ['required', 'string', 'max:10'],
|
||||
'adminName' => ['required', 'string', 'max:255'],
|
||||
'phone' => ['required', 'string', 'max:50'],
|
||||
'email' => ['required', 'email', 'max:255'],
|
||||
'registeredDate' => ['required'],
|
||||
'expiredDate' => ['required'],
|
||||
'cityName' => ['nullable', 'string', 'max:255'],
|
||||
'cityCode' => ['nullable', 'string', 'max:50'],
|
||||
'districtName' => ['nullable', 'string', 'max:255'],
|
||||
'wardName' => ['nullable', 'string', 'max:255'],
|
||||
'fax' => ['nullable', 'string', 'max:50'],
|
||||
'icannRegistrarName' => ['nullable', 'string', 'max:255'],
|
||||
'icannRegistrarTradeName' => ['nullable', 'string', 'max:255'],
|
||||
'businessCode' => ['nullable', 'string', 'max:100'],
|
||||
'eidCode' => ['nullable', 'string', 'max:100'],
|
||||
'personalId' => ['nullable', 'string', 'max:50'],
|
||||
'birthDate' => ['nullable', 'string', 'max:20'],
|
||||
'isAgentManager' => ['nullable', 'boolean'],
|
||||
'action' => ['nullable', 'string', 'max:100'],
|
||||
'actionReason' => ['nullable', 'string'],
|
||||
'actionSource' => ['nullable', 'string', 'max:100'],
|
||||
'actionDate' => ['nullable'],
|
||||
'note' => ['nullable', 'string'],
|
||||
'ianaNumber' => ['nullable', 'integer'],
|
||||
'status' => ['nullable', 'integer', 'in:0,1'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'domainName.required' => 'Tên miền là bắt buộc',
|
||||
'term_id.required' => 'Đợt khai báo là bắt buộc',
|
||||
'term_id.exists' => 'Đợt khai báo không tồn tại',
|
||||
'ownerName.required' => 'Tên chủ sở hữu là bắt buộc',
|
||||
'ownerType.required' => 'Loại chủ sở hữu là bắt buộc',
|
||||
'ownerType.in' => 'Loại chủ sở hữu phải là C (cá nhân) hoặc T (tổ chức)',
|
||||
'registeredDate.required' => 'Ngày đăng ký là bắt buộc',
|
||||
'expiredDate.required' => 'Ngày hết hạn là bắt buộc',
|
||||
'address.required' => 'Địa chỉ là bắt buộc',
|
||||
'countryCode.required' => 'Mã quốc gia là bắt buộc',
|
||||
'adminName.required' => 'Tên quản trị là bắt buộc',
|
||||
'phone.required' => 'Số điện thoại là bắt buộc',
|
||||
'email.required' => 'Email là bắt buộc',
|
||||
'email.email' => 'Email không hợp lệ',
|
||||
];
|
||||
}
|
||||
|
||||
public function toDTO(): DomainFluctuationDTO
|
||||
{
|
||||
return DomainFluctuationDTO::fromArray($this->validated());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Modules\DomainFluctuation\App\DTOs\DomainFluctuationTermDTO;
|
||||
|
||||
class StoreTermRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'term_name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'date_create' => ['nullable'],
|
||||
'status' => ['nullable', 'boolean'],
|
||||
'type' => ['nullable', 'in:vnnic_06,vnnic_07'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'term_name.required' => 'Tên đợt khai báo là bắt buộc',
|
||||
];
|
||||
}
|
||||
|
||||
public function toDTO(int $userId): DomainFluctuationTermDTO
|
||||
{
|
||||
return DomainFluctuationTermDTO::fromArray(array_merge(
|
||||
$this->validated(),
|
||||
['user_id' => $userId]
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Requests;
|
||||
|
||||
use Modules\DomainFluctuation\App\DTOs\DomainFluctuationDTO;
|
||||
|
||||
class UpdateDomainFluctuationRequest extends StoreDomainFluctuationRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return array_merge(parent::rules(), [
|
||||
'term_id' => ['sometimes', 'integer', 'exists:domain_fluctuation_terms,id'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function toDTO(): DomainFluctuationDTO
|
||||
{
|
||||
return DomainFluctuationDTO::fromArray($this->validated());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DomainFluctuationResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'domainName' => $this->domainName,
|
||||
'term_id' => $this->term_id,
|
||||
'term' => DomainFluctuationTermResource::make($this->whenLoaded('term')),
|
||||
'registeredDate' => $this->registeredDate,
|
||||
'expiredDate' => $this->expiredDate,
|
||||
'ownerName' => $this->ownerName,
|
||||
'ownerType' => $this->ownerType,
|
||||
'address' => $this->address,
|
||||
'wardName' => $this->wardName,
|
||||
'districtName' => $this->districtName,
|
||||
'cityName' => $this->cityName,
|
||||
'cityCode' => $this->cityCode,
|
||||
'countryCode' => $this->countryCode,
|
||||
'phone' => $this->phone,
|
||||
'email' => $this->email,
|
||||
'fax' => $this->fax,
|
||||
'adminName' => $this->adminName,
|
||||
'businessCode' => $this->businessCode,
|
||||
'eidCode' => $this->eidCode,
|
||||
'personalId' => $this->personalId,
|
||||
'birthDate' => $this->birthDate,
|
||||
'icannRegistrarName' => $this->icannRegistrarName,
|
||||
'icannRegistrarTradeName' => $this->icannRegistrarTradeName,
|
||||
'isAgentManager' => (bool) $this->isAgentManager,
|
||||
'action' => $this->action,
|
||||
'actionReason' => $this->actionReason,
|
||||
'actionSource' => $this->actionSource,
|
||||
'actionDate' => $this->actionDate,
|
||||
'note' => $this->note,
|
||||
'ianaNumber' => $this->ianaNumber,
|
||||
'status' => (int) $this->status,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DomainFluctuationTermResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'term_name' => $this->term_name,
|
||||
'description' => $this->description,
|
||||
'date_create' => $this->date_create,
|
||||
'user_id' => $this->user_id,
|
||||
'status' => (bool) $this->status,
|
||||
'type' => $this->whenLoaded('type', fn () => $this->type?->type),
|
||||
'fluctuations_count' => $this->when(
|
||||
isset($this->fluctuations_count),
|
||||
fn () => (int) $this->fluctuations_count
|
||||
),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class DomainFluctuation extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'domain_fluctuations';
|
||||
|
||||
protected $fillable = [
|
||||
'domainName',
|
||||
'term_id',
|
||||
'registeredDate',
|
||||
'expiredDate',
|
||||
'ownerName',
|
||||
'ownerType',
|
||||
'address',
|
||||
'wardName',
|
||||
'districtName',
|
||||
'cityName',
|
||||
'cityCode',
|
||||
'countryCode',
|
||||
'phone',
|
||||
'email',
|
||||
'fax',
|
||||
'adminName',
|
||||
'businessCode',
|
||||
'eidCode',
|
||||
'personalId',
|
||||
'birthDate',
|
||||
'icannRegistrarName',
|
||||
'icannRegistrarTradeName',
|
||||
'isAgentManager',
|
||||
'action',
|
||||
'actionReason',
|
||||
'actionSource',
|
||||
'actionDate',
|
||||
'note',
|
||||
'ianaNumber',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'isAgentManager' => 'boolean',
|
||||
'status' => 'integer',
|
||||
'registeredDate' => 'integer',
|
||||
'expiredDate' => 'integer',
|
||||
'actionDate' => 'integer',
|
||||
'ianaNumber' => 'integer',
|
||||
];
|
||||
|
||||
public function term(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DomainFluctuationTerm::class, 'term_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DomainFluctuationName extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'domain_fluctuation_names';
|
||||
|
||||
protected $fillable = ['domain_name'];
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class DomainFluctuationTerm extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'domain_fluctuation_terms';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'term_name',
|
||||
'description',
|
||||
'date_create',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => 'boolean',
|
||||
'date_create' => 'integer',
|
||||
];
|
||||
|
||||
public function fluctuations(): HasMany
|
||||
{
|
||||
return $this->hasMany(DomainFluctuation::class, 'term_id');
|
||||
}
|
||||
|
||||
public function type(): HasOne
|
||||
{
|
||||
return $this->hasOne(TermFluctuationType::class, 'term_fluctuation_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class TermFluctuationType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'term_fluctuation_type';
|
||||
|
||||
protected $fillable = [
|
||||
'term_fluctuation_id',
|
||||
'type',
|
||||
];
|
||||
|
||||
public function term(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DomainFluctuationTerm::class, 'term_fluctuation_id');
|
||||
}
|
||||
|
||||
public function getTypeLabelAttribute(): string
|
||||
{
|
||||
return $this->type === 'vnnic_06' ? 'VNNIC 06' : 'VNNIC 07';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class DomainFluctuationServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'DomainFluctuation';
|
||||
|
||||
protected string $moduleNameLower = 'domainfluctuation';
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerConfig();
|
||||
$this->registerMigrations();
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$this->mergeConfigFrom(
|
||||
module_path($this->moduleName, 'config/config.php'),
|
||||
$this->moduleNameLower
|
||||
);
|
||||
}
|
||||
|
||||
protected function registerMigrations(): void
|
||||
{
|
||||
$this->loadMigrationsFrom(module_path($this->moduleName, 'Database/migrations'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleNamespace = 'Modules\DomainFluctuation\App\Http\Controllers';
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
public function map(): void
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
}
|
||||
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->moduleNamespace)
|
||||
->group(module_path('DomainFluctuation', '/routes/api.php'));
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('domain_fluctuation_names', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('domain_name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('domain_fluctuation_names');
|
||||
}
|
||||
};
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('domain_fluctuation_terms', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->boolean('status')->default(false);
|
||||
$table->string('term_name');
|
||||
$table->string('description')->nullable();
|
||||
$table->integer('date_create');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('user_id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('domain_fluctuation_terms');
|
||||
}
|
||||
};
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('domain_fluctuations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('domainName');
|
||||
$table->unsignedBigInteger('term_id');
|
||||
$table->foreign('term_id')->references('id')->on('domain_fluctuation_terms');
|
||||
|
||||
$table->integer('registeredDate')->default(0)->index();
|
||||
$table->integer('expiredDate')->default(0)->index();
|
||||
$table->string('ownerName')->nullable();
|
||||
$table->string('ownerType')->nullable()->comment('C=ca nhan, T=to chuc');
|
||||
$table->string('address')->nullable();
|
||||
$table->string('wardName')->nullable();
|
||||
$table->string('districtName')->nullable();
|
||||
$table->string('cityName')->nullable();
|
||||
$table->string('cityCode')->nullable()->comment('Cot 7 - Ma tinh/thanh pho TT45');
|
||||
$table->string('countryCode')->nullable();
|
||||
$table->string('phone')->nullable();
|
||||
$table->string('email')->nullable();
|
||||
$table->string('fax')->nullable();
|
||||
$table->string('adminName')->nullable();
|
||||
$table->string('businessCode')->nullable()->comment('Cot 10 - Ma so DN/HKD/MST');
|
||||
$table->string('eidCode')->nullable()->comment('Cot 11 - Ma dinh danh dien tu to chuc');
|
||||
$table->string('personalId')->nullable()->comment('Cot 12 - So CCCD/ho chieu');
|
||||
$table->string('birthDate')->nullable()->comment('Cot 13 - Ngay sinh');
|
||||
$table->string('icannRegistrarName')->nullable();
|
||||
$table->string('icannRegistrarTradeName')->nullable();
|
||||
$table->boolean('isAgentManager')->nullable()->comment('true=dai ly, false=ndk');
|
||||
$table->string('action')->nullable();
|
||||
$table->string('actionReason')->nullable();
|
||||
$table->string('actionSource')->nullable();
|
||||
$table->integer('actionDate')->nullable()->default(0);
|
||||
$table->string('note')->nullable();
|
||||
$table->integer('ianaNumber')->default(1710);
|
||||
$table->tinyInteger('status')->default(0)->comment('0=Inactive, 1=Active');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('domainName');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('domain_fluctuations');
|
||||
}
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('term_fluctuation_type', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->bigInteger('term_fluctuation_id')->unsigned()->default(0)->index();
|
||||
$table->string('type', 50)->default('vnnic_06');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('term_fluctuation_type');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "nwidart/domainfluctuation",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Widart",
|
||||
"email": "n.widart@gmail.com"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [],
|
||||
"aliases": {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\DomainFluctuation\\": "",
|
||||
"Modules\\DomainFluctuation\\App\\": "App/",
|
||||
"Modules\\DomainFluctuation\\Database\\Factories\\": "Database/Factories/",
|
||||
"Modules\\DomainFluctuation\\Database\\Seeders\\": "Database/Seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Modules\\DomainFluctuation\\Tests\\": "tests/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'DomainFluctuation',
|
||||
];
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "DomainFluctuation",
|
||||
"alias": "domainfluctuation",
|
||||
"description": "Khai bao bien dong ten mien theo TT45/2025/TT-BKHCN",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"Modules\\DomainFluctuation\\App\\Providers\\DomainFluctuationServiceProvider"
|
||||
],
|
||||
"files": []
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\DomainFluctuation\App\Http\Controllers\Api\Admin\DomainFluctuationController as AdminDomainFluctuationController;
|
||||
use Modules\DomainFluctuation\App\Http\Controllers\Api\Admin\TermController as AdminTermController;
|
||||
use Modules\DomainFluctuation\App\Http\Controllers\Api\Client\DomainFluctuationController as ClientDomainFluctuationController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Domain Fluctuation API Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Khai báo biến động tên miền theo TT45/2025/TT-BKHCN
|
||||
| - admin: portal-admin (CRUD đầy đủ)
|
||||
| - client: portal-client (đọc danh sách + chi tiết active)
|
||||
|
|
||||
*/
|
||||
|
||||
Route::prefix('v1')
|
||||
->group(function () {
|
||||
// Admin
|
||||
Route::prefix('administrator')
|
||||
->middleware('api.auth:admin')
|
||||
->group(function () {
|
||||
Route::prefix('domain-fluctuations')
|
||||
->controller(AdminDomainFluctuationController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->middleware('perm:domain-fluctuation.view');
|
||||
Route::post('/', 'store')->middleware('perm:domain-fluctuation.create');
|
||||
Route::get('{id}', 'show')->middleware('perm:domain-fluctuation.view');
|
||||
Route::put('{id}', 'update')->middleware('perm:domain-fluctuation.edit');
|
||||
Route::delete('{id}', 'destroy')->middleware('perm:domain-fluctuation.destroy');
|
||||
});
|
||||
|
||||
Route::prefix('domain-fluctuation-terms')
|
||||
->controller(AdminTermController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->middleware('perm:domain-fluctuation.view');
|
||||
Route::post('/', 'store')->middleware('perm:domain-fluctuation.create');
|
||||
Route::get('{id}', 'show')->middleware('perm:domain-fluctuation.view');
|
||||
Route::put('{id}', 'update')->middleware('perm:domain-fluctuation.edit');
|
||||
Route::delete('{id}', 'destroy')->middleware('perm:domain-fluctuation.destroy');
|
||||
});
|
||||
});
|
||||
|
||||
// Client (portal-client)
|
||||
Route::prefix('client')
|
||||
->middleware('api.auth')
|
||||
->group(function () {
|
||||
Route::prefix('domain-fluctuations')
|
||||
->controller(ClientDomainFluctuationController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index');
|
||||
Route::get('{id}', 'show');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"DomainFluctuation": true
|
||||
}
|
||||
@@ -129,10 +129,13 @@ Route::prefix('v1')
|
||||
Route::delete('{uuid}/destroy', 'destroy')->middleware('perm:customer.destroy');
|
||||
Route::post('{uuid}/reset-password', 'resetPassword')->middleware('perm:customer.edit');
|
||||
Route::post('{uuid}/send-password', 'sendPasswordEmail')->middleware('perm:customer.edit');
|
||||
Route::post('{uuid}/login-as', 'loginAs')->middleware('perm:customer.edit');
|
||||
Route::post('{uuid}/add-credit', 'addCredit')->middleware('perm:customer.edit');
|
||||
Route::post('{uuid}/add-total', 'addTotal')->middleware('perm:customer.edit');
|
||||
Route::get('{uuid}/services', 'getServices')->middleware('perm:customer.view');
|
||||
Route::post('{uuid}/services', 'createService')->middleware('perm:customer.edit');
|
||||
Route::post('{uuid}/services/bulk-delete', 'bulkDeleteServices')->middleware('perm:customer.edit');
|
||||
Route::put('{uuid}/services/{serviceId}', 'updateService')->middleware('perm:customer.edit');
|
||||
Route::get('{uuid}/orders', 'getOrders')->middleware('perm:customer.view');
|
||||
Route::get('{uuid}/invoices', 'getInvoices')->middleware('perm:customer.view');
|
||||
Route::get('{uuid}/transactions', 'getTransactions')->middleware('perm:customer.view');
|
||||
|
||||
@@ -31,6 +31,7 @@ Route::prefix('v1')
|
||||
Route::post('register', 'register')->name('register');
|
||||
Route::post('refresh', 'refresh')->name('refresh');
|
||||
Route::post('forgot-password', 'forgotPassword')->name('forgot-password');
|
||||
Route::post('impersonate/exchange', 'impersonateExchange')->name('impersonate.exchange');
|
||||
|
||||
Route::group(['middleware' => ['api.auth']], function () {
|
||||
Route::get('me', 'me')->name('me');
|
||||
|
||||
Reference in New Issue
Block a user