91 lines
2.0 KiB
PHP
91 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\BaseApp\BaseService;
|
|
use App\Models\CollectionModel;
|
|
use App\Models\FileModel;
|
|
use App\Models\ProjectModel;
|
|
use App\Models\RoleModel;
|
|
use App\Models\UserModel;
|
|
use Exception;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
class CollectionService extends BaseService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->selectField = ['id', 'user_id', 'project_id', 'created_at', 'updated_at', 'deleted_at'];
|
|
$this->model = CollectionModel::class;
|
|
$this->where[] = ['user_id', '=', $this->userId];
|
|
}
|
|
|
|
/**
|
|
* 获取用户收藏列表
|
|
* @return array
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function list(): array
|
|
{
|
|
$this->with = [
|
|
'project:id,title,cover,category_id,description,price,preferential_price,front,service,deploy,status,created_at,updated_at',
|
|
'project.category:id,name',
|
|
'project.labels:id,name',
|
|
];
|
|
return $this->getPageList();
|
|
}
|
|
|
|
public function detail($id)
|
|
{
|
|
return $this->getDetail($id);
|
|
}
|
|
|
|
/**
|
|
* 用户收藏下拉列表
|
|
* @return mixed
|
|
*/
|
|
public function option()
|
|
{
|
|
$this->optionField = ['id', 'url'];
|
|
return $this->getOption();
|
|
}
|
|
|
|
/**
|
|
* 创建用户收藏
|
|
* @param $params
|
|
* @return mixed
|
|
* @throws Exception
|
|
*/
|
|
public function create($params): mixed
|
|
{
|
|
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);
|
|
}
|
|
|
|
}
|