Files
portal-api/app/Repositories/Api/ServiceClient/ServiceClientRepository.php
T

59 lines
1.5 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 danh sách sản phẩm đang hoạt động
*/
public function getActiveServices(int $limit = 10)
{
return $this->model
->with(['orderItem' => fn($q) => $q->with('product')])
->where('status', 'active')
->orderBy('started_at', 'asc')
->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)
{
return $this->model
->with([
'orderItem.os.osGroup',
'orderItem.product',
'orderItem.order.vmWare.ipAddress',
])
->where('uuid', $uuid)
->first();
}
}