53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Api\Service;
|
|
|
|
use App\Support\ProductBillingCycles;
|
|
use App\Models\Product;
|
|
use App\Repositories\Api\BaseApiRepository;
|
|
|
|
class ServiceRepository extends BaseApiRepository implements ServiceRepositoryInterface
|
|
{
|
|
public function getModel()
|
|
{
|
|
return Product::class;
|
|
}
|
|
|
|
/**
|
|
* Lấy danh sách sản phẩm đang hoạt động
|
|
*/
|
|
public function getActiveServices(int $limit = 10)
|
|
{
|
|
return $this->model
|
|
->with(['osVersions.osGroup', 'category', 'pricings' => fn($q) => $q->where('is_active', 1)])
|
|
->where('is_active', 1)
|
|
->orderBy('sort_order', '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)
|
|
{
|
|
$product = $this->model->find($productId);
|
|
|
|
if (!ProductBillingCycles::allows($product->product_type, $billingCycle)) {
|
|
return null;
|
|
}
|
|
|
|
$pricing = $product->pricings()
|
|
->where('billing_cycle', $billingCycle)
|
|
->where('is_active', 1)
|
|
->first();
|
|
|
|
return $pricing ? $pricing->price : null;
|
|
}
|
|
}
|