db() ->where($where) ->page($page, config('paginate.list_rows')) ->select(); } /** * 获取分页信息 * @param array $where 查询条件 */ public function getPage($where = array()){ $query = getPaginatiorQuery(); $total = $this->db()->where($where)->count(); // 查询条件 $config = ['query'=>$query]; $paginate = $this->db()->where($where)->paginate(config('paginate.list_rows'), $total, $config); return $paginate->render(); } /** * 根据id找到角色 * @param int $id */ public function getRoleById($id){ return $this->db()->where(['id'=>$id])->find(); } /** * 获取所有角色 * @return array */ public function getAllRole(){ return $this->db()->where(['status'=>1])->select(); } /** * 添加和更新的方法 */ public function addAndSave(){ $data = request()->post(); return $this->allowField(true)->isUpdate($data['id']?true:false)->save($data); } public function remove(){ $request = Request::instance(); if($request->isPost()) $this->data = $request->post(); if($request->isGet()) $this->data = $request->get(); return $this->delete(); } }