alias('u') ->field('u.id,u.username,u.password,u.status,u.rule') ->where('u.username', $userName) ->find(); } /** * 根据搜索条件获取用户列表信息 * @param $where * @param $offset * @param $limit */ public function getUsersByWhere($where, $offset, $limit) { return $this->where($where)->limit($offset, $limit)->order('id desc')->field('id,username,create_timestamp,last_login_ip,last_login_time,status,update_timestamp,rule')->select(); } /** * 根据搜索条件获取所有的用户数量 * @param $where */ public function getAllUsers($where) { return $this->where($where)->count(); } /** * 管理员登录信息同步错误 * @param array $param */ public function updateStatus($param = [], $uid) { try{ $this->where('id', $uid)->update($param); return msg(1, '', 'ok'); }catch (\Exception $e){ return msg(-1, '', $e->getMessage()); } } /** * 插入管理员信息 * @param $param */ public function insertUser($param) { try{ $param['create_timestamp'] = $param['update_timestamp'] = date('Y-m-d H:i:s'); $result = $this->save($param); if(false === $result){ // 验证失败 输出错误信息 return msg(-1, '', $this->getError()); }else{ return msg(1, '', '添加用户成功'); } }catch(PDOException $e){ return msg(-2, '', $e->getMessage()); } } /** * 删除管理员 * @param $id */ public function delUser($id) { try{ $this->where('id', $id)->delete(); return msg(1, '', '删除管理员成功'); }catch( PDOException $e){ return msg(-1, '', $e->getMessage()); } } }