Update source into github

This commit is contained in:
pbao9
2025-07-24 16:18:27 +07:00
parent 41419358dd
commit 69851ac7bc
2642 changed files with 284095 additions and 0 deletions
@@ -0,0 +1,52 @@
<?php
namespace App\Repositories\Group;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class GroupCachedRepository extends BaseCachedRepository implements GroupRepositoryInterface
{
public function __construct(
public GroupRepository $groupRepository
)
{
parent::__construct();
}
public function getModel()
{
return $this->groupRepository->getModel();
}
public function getProduct(int $group_id = 0, int $type_id = 0)
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'type_id' => $type_id,
'group_id' => $group_id
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($type_id, $group_id) {
return $this->groupRepository->getProduct($group_id, $type_id);
});
}
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->groupRepository->filter($data, $relationships, $withCount, $select);
});
}
public function findBySlugWithProduct(string $slug)
{
return $this->model->where('slug', $slug)->with(['hostings', 'vps'])->first();
}
}
@@ -0,0 +1,87 @@
<?php
namespace App\Repositories\Group;
use App\Models\Group;
use App\Repositories\Addon\AddonRepositoryInterface;
use App\Repositories\BaseRepository;
use App\Repositories\Domain\DomainRepositoryInterface;
use App\Repositories\Hosting\HostingRepositoryInterface;
use App\Repositories\VPS\VPSRepositoryInterface;
class GroupRepository extends BaseRepository implements GroupRepositoryInterface
{
public function __construct(
public VPSRepositoryInterface $vPSRepository,
public HostingRepositoryInterface $hostingRepository,
public AddonRepositoryInterface $addonRepository,
public DomainRepositoryInterface $domainRepository
)
{
parent::__construct();
}
public function getModel()
{
return Group::class;
}
public function getProduct(int $group_id = 0, int $type_id = 0)
{
return match ($type_id) {
3 => $this->hostingRepository->filter(['group_id' => $group_id]),
4 => $this->vPSRepository->filter(['group_id' => $group_id]),
default => null
};
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
{
$model = $this->model->with($relationships)->select($select);
if (isset($data['status'])) {
$model = $model->where("status", $data['status']);
}
if (isset($data['relations'])) {
foreach ($data['relations'] as $key => $value) {
$model = $model->whereHas($key, function ($query) use ($value) {
if (isset($value['condition'])) {
switch (strtoupper($value['condition'])) {
case "IN":
$query->whereIn($value['key'], $value['value']);
break;
case "NotIn":
$query->whereNotIn($value['key'], $value['value']);
break;
default:
$query->where($value['key'], $value['condition'], $value['value']);
break;
}
} else {
$query->where($value['key'], $value['value']);
}
});
}
}
if (count($withCount) > 0) {
$model = $model->withCount($withCount);
}
if (isset($data['page'])) {
return $model->paginate(15);
}
return $model->get();
}
public function findBySlugWithProduct(string $slug)
{
return $this->model->where('slug', $slug)
->where('status', 1) // Only active groups
->with(['hostings' => function ($query) {
$query->where('status', 1); // Only active hostings
}, 'vps' => function ($query) {
$query->where('status', 1); // Only active VPS
}])
->first();
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Repositories\Group;
use App\Repositories\BaseRepositoryInterface;
interface GroupRepositoryInterface extends BaseRepositoryInterface
{
public function getProduct(int $group_id = 0, int $type_id = 0);
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*']);
public function findBySlugWithProduct(string $slug);
}