diff --git a/catch/permissions/PermissionsMiddleware.php b/catch/permissions/PermissionsMiddleware.php index e2706e4..9364a36 100644 --- a/catch/permissions/PermissionsMiddleware.php +++ b/catch/permissions/PermissionsMiddleware.php @@ -1,7 +1,7 @@ department = $department; } - public function index() + /** + * 列表 + * + * @time 2020年01月09日 + * @param CatchRequest $request + * @return \think\response\Json + * @throws \think\db\exception\DbException + */ + public function index(CatchRequest $request): \think\response\Json { - + return CatchResponse::success(Tree::done($this->department->getList($request->param()))); } - public function save() + /** + * 保存 + * + * @time 2020年01月09日 + * @param CatchRequest $request + * @return \think\response\Json + */ + public function save(CatchRequest $request): \think\response\Json { - + return CatchResponse::success($this->department->storeBy($request->post())); } - public function update() + /** + * 更新 + * + * @time 2020年01月09日 + * @param $id + * @param CatchRequest $request + * @return \think\response\Json + */ + public function update($id, CatchRequest $request): \think\response\Json { - + return CatchResponse::success($this->department->updateBy($id, $request->post())); } - public function delete($id) + /** + * 删除 + * + * @time 2020年01月09日 + * @param $id + * @return \think\response\Json + */ + public function delete($id): \think\response\Json { - + return CatchResponse::success($this->department->deleteBy($id)); } } diff --git a/catch/permissions/controller/Job.php b/catch/permissions/controller/Job.php index ca0b6d3..b6b1334 100644 --- a/catch/permissions/controller/Job.php +++ b/catch/permissions/controller/Job.php @@ -1,9 +1,66 @@ job = $job; + } + + /** + * 列表 + * + * @time 2020年01月09日 + * @param CatchRequest $request + * @return \think\response\Json + */ + public function index(CatchRequest $request): \think\response\Json + { + return CatchResponse::paginate($this->job->getList($request->param())); + } + + /** + * 保存 + * + * @time 2020年01月09日 + * @param CatchRequest $request + * @return \think\response\Json + */ + public function save(CatchRequest $request): \think\response\Json + { + return CatchResponse::success($this->job->storeBy($request->post())); + } + + /** + * 更新 + * + * @time 2020年01月09日 + * @param $id + * @param CatchRequest $request + * @return \think\response\Json + */ + public function update($id, CatchRequest $request): \think\response\Json + { + return CatchResponse::success($this->job->updateBy($id, $request->post())); + } + + /** + * 删除 + * + * @time 2020年01月09日 + * @param $id + * @return \think\response\Json + */ + public function delete($id): \think\response\Json + { + return CatchResponse::success($this->job->deleteBy($id)); + } } diff --git a/catch/permissions/model/Department.php b/catch/permissions/model/Department.php index 1446c35..ee50f61 100644 --- a/catch/permissions/model/Department.php +++ b/catch/permissions/model/Department.php @@ -8,18 +8,35 @@ class Department extends CatchModel protected $name = 'department'; protected $field = [ - 'id', // - 'department_name', // 部门名称 - 'parent_id', // 父级ID - 'principal', // 负责人 - 'mobile', // 联系电话 - 'email', // 联系又想 - 'creator_id', // 创建人ID - 'status', // 1 正常 2 停用 - 'sort', // 排序字段 - 'created_at', // 创建时间 - 'updated_at', // 更新时间 - 'deleted_at', // 删除状态,null 未删除 timestamp 已删除 - - ]; -} \ No newline at end of file + 'id', // + 'department_name', // 部门名称 + 'parent_id', // 父级ID + 'principal', // 负责人 + 'mobile', // 联系电话 + 'email', // 联系又想 + 'creator_id', // 创建人ID + 'status', // 1 正常 2 停用 + 'sort', // 排序字段 + 'created_at', // 创建时间 + 'updated_at', // 更新时间 + 'deleted_at', // 删除状态,null 未删除 timestamp 已删除 + ]; + + /** + * 列表数据 + * + * @time 2020年01月09日 + * @param $params + * @throws \think\db\exception\DbException + */ + public function getList($params) + { + return $this->when($params['department_name'] ?? false, function ($query) use ($params){ + $query->whereLike('department_name', '%' . $params['department_name'] . '%'); + }) + ->when($params['status'] ?? false, function ($query) use ($params){ + $query->where('status', $params['status']); + }) + ->select()->toArray(); + } +} diff --git a/catch/permissions/model/Job.php b/catch/permissions/model/Job.php index 7a2dce4..d4642d4 100644 --- a/catch/permissions/model/Job.php +++ b/catch/permissions/model/Job.php @@ -8,16 +8,37 @@ class Job extends CatchModel protected $name = 'job'; protected $field = [ - 'id', // - 'job_name', // 岗位名称 - 'coding', // 编码 - 'creator_id', // 创建人ID - 'status', // 1 正常 2 停用 - 'sort', // 排序字段 - 'description', // 描述 - 'created_at', // 创建时间 - 'updated_at', // 更新时间 - 'deleted_at', // 删除状态,null 未删除 timestamp 已删除 - - ]; -} \ No newline at end of file + 'id', // + 'job_name', // 岗位名称 + 'coding', // 编码 + 'creator_id', // 创建人ID + 'status', // 1 正常 2 停用 + 'sort', // 排序字段 + 'description', // 描述 + 'created_at', // 创建时间 + 'updated_at', // 更新时间 + 'deleted_at', // 删除状态,null 未删除 timestamp 已删除 + ]; + + /** + * 列表 + * + * @time 2020年01月09日 + * @param $params + * @throws \think\db\exception\DbException + * @return \think\Paginator + */ + public function getList($params) + { + return $this->when($params['job_name'] ?? false, function ($query) use ($params){ + $query->whereLike('job_name', '%' . $params['job_name'] . '%'); + }) + ->when($params['status'] ?? false, function ($query) use ($params){ + $query->where('status', $params['status']); + }) + ->when($params['coding'] ?? false, function ($query) use ($params){ + $query->whereLike('coding', '%' . $params['coding'] . '%'); + }) + ->paginate($parmas['limit'] ?? $this->limit); + } +} diff --git a/catch/permissions/route.php b/catch/permissions/route.php index c60c646..437cb79 100644 --- a/catch/permissions/route.php +++ b/catch/permissions/route.php @@ -3,6 +3,9 @@ $router->resource('roles', '\catchAdmin\permissions\controller\Role'); // 角色列表 $router->get('/role/get/permissions', '\catchAdmin\permissions\controller\Role@getPermissions'); - // 权限 $router->resource('permissions', '\catchAdmin\permissions\controller\Permission'); +// 部门 +$router->resource('departments', '\catchAdmin\permissions\controller\Department'); +// 岗位 +$router->resource('jobs', '\catchAdmin\permissions\controller\Job');