Files
spa-api/app/Service/HomeService.php
2025-05-07 14:48:34 +08:00

77 lines
2.1 KiB
PHP

<?php
namespace App\Service;
use App\BaseApp\BaseService;
use App\Enum\ProjectStatusEnum;
use App\Enum\StatusEnum;
use App\Models\FeatureModel;
use App\Models\ProjectLabelRelationModel;
use App\Models\ProjectModel;
use App\Models\ScreenshotModel;
use App\Models\UserModel;
use Exception;
use Illuminate\Support\Facades\DB;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class HomeService extends BaseService
{
public function __construct()
{
$this->isAuth = false;
parent::__construct();
$this->selectField = [ 'id', 'user_id', 'title', 'cover', 'category_id', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status', 'created_at', 'updated_at', 'deleted_at', ];
$this->model = ProjectModel::class;
}
/**
* 获取项目列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
$this->where[] = [ 'is_selected', '=', 1 ];
$this->where[] = [ 'status', '=', 1 ];
$this->with = [
'frameworks:id,name',
'labels:id,name',
'category:id,name',
];
return $this->getPageList();
}
/**
* 获取项目列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function carousel(): array
{
$this->where[] = [ 'is_carousel', '=', 1 ];
$this->where[] = [ 'status', '=', 1 ];
$this->with = [
'frameworks:id,name',
'labels:id,name',
'category:id,name',
];
return $this->getPageList();
}
public function detail($id)
{
$this->with = [
'frameworks:id,name',
'labels:id,name',
'category:id,name',
'screenshots:id,url,project_id',
'features:id,project_id,name',
'author:id,nick_name,avatar,email'
];
return $this->getDetail($id);
}
}