角色相关(列表和下拉框)、用户查询、项目部分API
This commit is contained in:
93
app/Service/ProjectService.php
Normal file
93
app/Service/ProjectService.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BaseApp\BaseService;
|
||||
use App\Models\ProjectModel;
|
||||
use App\Models\UserModel;
|
||||
use Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class ProjectService extends BaseService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->selectField = [ 'id', 'user_id', 'title', 'cover', '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->with = [
|
||||
'frameworks:id,name',
|
||||
'labels:id,name',
|
||||
// 'features:id,project_id,name'
|
||||
];
|
||||
return $this->getPageList();
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$this->with = [
|
||||
'frameworks:id,name',
|
||||
'labels:id,name',
|
||||
'features:id,project_id,name'
|
||||
];
|
||||
return $this->getDetail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目下拉列表
|
||||
* @return mixed
|
||||
*/
|
||||
public function option()
|
||||
{
|
||||
$this->optionField = ['id', 'title'];
|
||||
return $this->getOption();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建项目
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create($params): mixed
|
||||
{
|
||||
$params['user_id'] = $this->userId;
|
||||
$params['author_id'] = $params['author_id']?? $this->userId;
|
||||
return $this->insert($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑项目
|
||||
* @param $id
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update($id, $params): mixed
|
||||
{
|
||||
return $this->save($id, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除项目
|
||||
* @param $ids
|
||||
* @return mixed|true
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete($ids): mixed
|
||||
{
|
||||
return $this->del($ids);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user