name = $params["name"]; $this->description = $params["description"]; $this->status = "normal"; if ($this->name == "") { return "empty role name"; } $this->save(); return "success"; } /** * 修改用户的角色信息 * * @param array $params * @return string */ public function ModifyRole(array $params) { $update = []; $id = $params["id"]; if ($id == "") { return "empty role id"; } if ($params["name"] != "") { $update["name"] = $params["name"]; } if ($params["description"] != "") { $update["description"] = $params["description"]; } if (count($update) == 0) { return "nothing to update"; } $this->where("id", $id) ->where("is_del", false) ->update($update); return "success"; } /** * 删除一个用户角色 * * @param array $params * @return string */ public function DeleteRole(array $params) { $id = $params["id"]; if ($id == "") { return "empty role id"; } $this->where("id", $id) ->where("is_del", false) ->update(["is_del" => true]); return "success"; } /** * 列出用户角色列表 * * @param array $params * @return mixed */ public function ListRole(array $params) { $page = $params["page"]; $pageCount = $params["pageCount"]; $data = $this->where("is_del", false) ->orderBy("created_at", "asc") ->paginate($pageCount, ["*"], "page", $page) ->get(); return $data; } }