55 lines
1.4 KiB
PHP
55 lines
1.4 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.host.datacenter.vCenter'])
|
|
->where('uuid', $uuid)
|
|
->first();
|
|
}
|
|
}
|