Files
portal-api/app/Repositories/Api/ServiceClient/ServiceClientRepository.php
T
baodev0 fccb0c353a 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.
2026-05-26 13:54:33 +07:00

69 lines
2.0 KiB
PHP

<?php
namespace App\Repositories\Api\ServiceClient;
use App\Models\Service;
use App\Repositories\Api\BaseApiRepository;
class ServiceClientRepository extends BaseApiRepository implements ServiceClientRepositoryInterface
{
public function getModel()
{
return Service::class;
}
/**
* Lấy toàn bộ dịch vụ của customer (mọi trạng thái)
*/
public function getActiveServices(int $customerId, ?string $productType = null, int $limit = 10)
{
$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');
if ($productType) {
$query->whereHas('orderItem.product', function ($builder) use ($productType) {
$builder->where('product_type', $productType);
});
}
return $query->paginate($limit);
}
public function findActiveBySlug(string $slug)
{
return $this->model
->with(['osVersions.osGroup', 'category', 'pricings' => fn ($q) => $q->where('is_active', 1)])
->where('slug', $slug)
->where('is_active', 1)
->first();
}
public function getPricing(int $productId, string $billingCycle)
{
$pricing = $this->model->find($productId)
->pricings()
->where('billing_cycle', $billingCycle)
->where('is_active', 1)
->first();
return $pricing ? $pricing->price : null;
}
public function getDetailService(string $uuid, int $customerId)
{
return $this->model
->with([
'orderItem.os.osGroup',
'orderItem.product',
'orderItem.order',
'vmware.ipAddress',
])
->where('uuid', $uuid)
->where('customer_id', $customerId)
->first();
}
}