Files
portal-api/app/Repositories/InvoiceItem/InvoiceItemCachedRepository.php
T
2025-07-24 16:18:27 +07:00

90 lines
3.3 KiB
PHP

<?php
namespace App\Repositories\InvoiceItem;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class InvoiceItemCachedRepository extends BaseCachedRepository implements InvoiceItemRepositoryInterface
{
public function __construct(
public InvoiceItemRepository $invoiceItemRepository
) {
parent::__construct();
}
public function getModel()
{
return $this->invoiceItemRepository->getModel();
}
public function getItemBy(array $type_in = [], int $invoice_type_id = 0)
{
$cacheKey = $this->getCacheKey(md5(json_encode(
[
'getItemBy' => [
'type_in' => $type_in,
'invoice_type_id' => $invoice_type_id
]
]
)));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($type_in, $invoice_type_id) {
return $this->invoiceItemRepository->getItemBy($type_in, $invoice_type_id);
});
}
public function findBy(int $userId = 0, array $data = [], array $relationships = [])
{
$cacheKey = $this->getCacheKey(md5(json_encode(
[
'findBy' => [
'userId' => $userId,
'data' => $data,
'relationships' => $relationships
]
]
)));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($userId, $data, $relationships) {
return $this->invoiceItemRepository->findBy($userId, $data, $relationships);
});
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'filterItem' => [
'data' => $data,
'relationships' => $relationships,
'select' => $select,
'withCount' => $withCount
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
return $this->invoiceItemRepository->filter($data, $relationships, $withCount, $select);
});
}
public function findServiceStatus(int $relid = 0, int $type_id = 0)
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'findServiceStatus' => [
'relid' => $relid,
'type_id' => $type_id,
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($relid, $type_id) {
return $this->invoiceItemRepository->findServiceStatus($relid, $type_id);
});
}
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = [])
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'findWithRelationships' => [
'id' => $id,
'relationships' => $relationships,
'withCount' => $withCount,
'withSum' => $withSum
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships,$withCount,$withSum) {
return $this->invoiceItemRepository->findWithRelationships($id, $relationships,$withCount,$withSum);
});
}
}