feat: Add DNS management resources and importer
- Implemented DomainCollection, DomainDetailResource, DomainNSCollection, DomainNSResource, and DomainResource for handling DNS domain and record data. - Created VpsServiceCollection and VpsServiceResource for VPS service management. - Added DnsManagerNS and DnsManagerUser models to represent DNS records and user associations. - Developed AdminZoneDnsSqlImporter for importing DNS data from SQL dumps, including customer and DNS domain records. - Added migration scripts to update the customers table with new fields and sync foreign key references for DNS tables. - Created a migration preview document outlining the mapping and schema changes for the admin zone DNS import.
This commit is contained in:
@@ -15,13 +15,21 @@ class ServiceClientRepository extends BaseApiRepository implements ServiceClient
|
||||
/**
|
||||
* Lấy toàn bộ dịch vụ của customer (mọi trạng thái)
|
||||
*/
|
||||
public function getActiveServices(int $limit = 10)
|
||||
public function getActiveServices(int $customerId, ?string $productType = null, int $limit = 10)
|
||||
{
|
||||
return $this->model
|
||||
$query = $this->model
|
||||
->with(['orderItem' => fn($q) => $q->with(['product', 'os.osGroup'])])
|
||||
->where('customer_id', $customerId)
|
||||
->orderByRaw("FIELD(status, 'active', 'pending', 'suspended', 'expired', 'cancelled', 'terminated')")
|
||||
->orderBy('started_at', 'desc')
|
||||
->paginate($limit);
|
||||
->orderBy('started_at', 'desc');
|
||||
|
||||
if ($productType) {
|
||||
$query->whereHas('orderItem.product', function ($builder) use ($productType) {
|
||||
$builder->where('product_type', $productType);
|
||||
});
|
||||
}
|
||||
|
||||
return $query->paginate($limit);
|
||||
}
|
||||
|
||||
public function findActiveBySlug(string $slug)
|
||||
@@ -44,7 +52,7 @@ class ServiceClientRepository extends BaseApiRepository implements ServiceClient
|
||||
return $pricing ? $pricing->price : null;
|
||||
}
|
||||
|
||||
public function getDetailService(string $uuid)
|
||||
public function getDetailService(string $uuid, int $customerId)
|
||||
{
|
||||
return $this->model
|
||||
->with([
|
||||
@@ -54,6 +62,7 @@ class ServiceClientRepository extends BaseApiRepository implements ServiceClient
|
||||
'vmware.ipAddress',
|
||||
])
|
||||
->where('uuid', $uuid)
|
||||
->where('customer_id', $customerId)
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ interface ServiceClientRepositoryInterface extends BaseRepositoryInterface
|
||||
/**
|
||||
* Lấy danh sách sản phẩm đang hoạt động
|
||||
*/
|
||||
public function getActiveServices(int $limit = 10);
|
||||
public function getActiveServices(int $customerId, ?string $productType = null, int $limit = 10);
|
||||
|
||||
public function findActiveBySlug(string $slug);
|
||||
|
||||
public function getPricing(int $productId, string $billingCycle);
|
||||
|
||||
public function getDetailService(string $uuid);
|
||||
public function getDetailService(string $uuid, int $customerId);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,16 @@ use App\Repositories\BaseRepository;
|
||||
|
||||
class CustomerRepository extends BaseRepository implements CustomerRepositoryInterface
|
||||
{
|
||||
private const STATUS_MAP = [
|
||||
'active' => 1,
|
||||
'inactive' => 2,
|
||||
'de_active' => 2,
|
||||
'pending' => 0,
|
||||
'closed' => 2,
|
||||
'suspended' => 3,
|
||||
'banned' => 3,
|
||||
];
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
return Customer::class;
|
||||
@@ -19,6 +29,16 @@ class CustomerRepository extends BaseRepository implements CustomerRepositoryInt
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
if (isset($data['filter']) && ! empty($data['filter'])) {
|
||||
$model = $model->where(function ($query) use ($data) {
|
||||
$filter = trim($data['filter']);
|
||||
$query->where('fullname', 'LIKE', "%{$filter}%")
|
||||
->orWhere('username', 'LIKE', "%{$filter}%")
|
||||
->orWhere('company', 'LIKE', "%{$filter}%")
|
||||
->orWhere('email', 'LIKE', "%{$filter}%")
|
||||
->orWhere('phone', 'LIKE', "%{$filter}%");
|
||||
});
|
||||
}
|
||||
if (isset($data['name']) && ! empty($data['name'])) {
|
||||
$model = $model->where(function ($query) use ($data) {
|
||||
$name = trim($data['name']);
|
||||
@@ -33,11 +53,14 @@ class CustomerRepository extends BaseRepository implements CustomerRepositoryInt
|
||||
$model = $model->where("phone", "LIKE", "%" . $data['phone'] . "%");
|
||||
}
|
||||
if (isset($data['status']) && ! empty($data['status']) && $data['status'] != 'full') {
|
||||
$model = $model->where("status", match ($data['status']) {
|
||||
'active' => 1,
|
||||
'de_active' => 0,
|
||||
'closed' => 2,
|
||||
});
|
||||
$status = (string) $data['status'];
|
||||
$statusValue = is_numeric($status)
|
||||
? (int) $status
|
||||
: (self::STATUS_MAP[$status] ?? null);
|
||||
|
||||
if ($statusValue !== null) {
|
||||
$model = $model->where('status', $statusValue);
|
||||
}
|
||||
}
|
||||
if (isset($data['relations'])) {
|
||||
foreach ($data['relations'] as $key => $value) {
|
||||
|
||||
@@ -35,7 +35,7 @@ class DnsDomainRepository extends BaseRepository implements DnsDomainRepositoryI
|
||||
|
||||
if (isset($data['user_id']) && $data['user_id']) {
|
||||
$model = $model->whereHas('users', function ($query) use ($data) {
|
||||
$query->where('users.id', $data['user_id']);
|
||||
$query->where('customers.id', $data['user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user