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

更新用户RPC服务方法

parent eb59e625
......@@ -27,24 +27,24 @@ class BaseService
protected function find($id)
{
$model = $this->model->find($id);
// if (!$model) {
// return Helper::fail('', '数据不存在', 404);
// }
return $model;
}
public function all(array $columns = ['*'], array $relations = []): array
{
return $this->model->with($relations)->get($columns)->toArray();
}
/**
* 获取一条数据
* @param $id
* @return array
* @param int $id
* @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);
if (!$model) {
return Helper::fail('', '数据不存在', 404);
}
return Helper::success($model);
return $this->model->with($relations)->find($id, $columns);
}
/**
......
......@@ -13,10 +13,20 @@ interface UserServiceInterface
/**
* 获取单个数据
* @param $id
* @param int $id
* @param array $columns
* @param array $relations
* @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列表获取用户数组
......
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