104 lines
2.9 KiB
PHP
104 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\BaseApp\BaseService;
|
|
use App\Enum\ProjectStatusEnum;
|
|
use App\Enum\StatusEnum;
|
|
use App\Models\CollectionModel;
|
|
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', 'is_sold', 'description', 'module_image', 'flowchart', 'content', '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 projectList(): array
|
|
{
|
|
$this->queryField = [
|
|
'title' => 'like'
|
|
];
|
|
$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'
|
|
];
|
|
$result = $this->getDetail($id);
|
|
if (!empty($this->userId)) {
|
|
$result['is_collection'] = CollectionModel::where('project_id', $id)->where('user_id', $this->userId)->exists();
|
|
} else {
|
|
$result['is_collection'] = false;
|
|
}
|
|
return $result;
|
|
}
|
|
}
|