Commit 7c2f9315 authored by 王源's avatar 王源 🎧

更新用户RPC服务方法

parent eb59e625
...@@ -27,24 +27,24 @@ class BaseService ...@@ -27,24 +27,24 @@ class BaseService
protected function find($id) protected function find($id)
{ {
$model = $this->model->find($id); $model = $this->model->find($id);
// if (!$model) {
// return Helper::fail('', '数据不存在', 404);
// }
return $model; return $model;
} }
public function all(array $columns = ['*'], array $relations = []): array
{
return $this->model->with($relations)->get($columns)->toArray();
}
/** /**
* 获取一条数据 * 获取一条数据
* @param $id * @param int $id
* @return array * @param array $columns
* @param array $relations
* @return mixed
*/ */
public function get($id) public function get(int $id, array $columns = ['*'], array $relations = [])
{ {
$model = $this->find($id); return $this->model->with($relations)->find($id, $columns);
if (!$model) {
return Helper::fail('', '数据不存在', 404);
}
return Helper::success($model);
} }
/** /**
......
...@@ -13,10 +13,20 @@ interface UserServiceInterface ...@@ -13,10 +13,20 @@ interface UserServiceInterface
/** /**
* 获取单个数据 * 获取单个数据
* @param $id * @param int $id
* @param array $columns
* @param array $relations
* @return mixed * @return mixed
*/ */
public function get($id); public function get(int $id, array $columns = ['*'], array $relations = []);
/**
* 获取全部数据
* @param array $columns
* @param array $relations
* @return array
*/
public function all(array $columns = ['*'], array $relations = []): array;
/** /**
* 通过id列表获取用户数组 * 通过id列表获取用户数组
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment