This commit is contained in:
baodev0
2026-07-01 10:51:05 +07:00
parent 914e96138a
commit 3bb59feba3
43 changed files with 1680 additions and 28 deletions
@@ -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,
];
}
}
@@ -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',
]);
}
}
@@ -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'));
}
}
@@ -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');
}
};
@@ -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');
}
};
@@ -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');
}
};
@@ -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');
}
};
+31
View File
@@ -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',
];
+11
View File
@@ -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": []
}
+57
View File
@@ -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');
});
});
});