'id', '_autoinc' => true); protected $rule = array( array('username', 'require', '用户名不能为空!', 1), // 正则验证密码 [需包含字母数字以及@*#中的一种,长度为6-22位] array('password', '/^([a-zA-Z0-9@*#]{6,22})$/', '密码格式不正确,请重新输入!', 1), array('verify','require','验证码必须!'), // 都有时间都验证 array('verify','checkVerify','验证码错误',0, 'function'), ); protected $_auto = array( array('password','md5',3,'function') , // 对password字段在新增和编辑的时候使md5函数处理 ); public function __construct(){ $this->dbName = 'admin'; // 表名 $this->db = M($this->dbName); } public function getAdminList(){ return $this->db->alias('a')->join('jj_admintype as b on(a.type_id=b.type_id)')->select(); } /** * 获取页码当前标签 * @param array $where * @param int $page * @return \Think\mixed */ public function getInfo($page=0, $where=array()){ return $this->db->where($where)->page(0, PAGE_ROW)->select(); } /** * 获取分页信息 * @param array $where 查询条件 * @return string */ public function getPages($where=array()){ $p = getPages($this->db, $where, PAGE_ROW); return $p->show(); } /** * 根据id找到人员 * @param int $id * @return mixed|boolean|NULL|string|unknown|object */ public function getAdminById($id){ return $this->db->where(array('id'=>$id))->find(); } /** * 登录判断 */ public function onLogin(){ $name = I('name'); $password = I('password'); $where = array('username'=>$name, 'password'=>md5($password)); $res = $this->db->where($where)->find(); if($res){ $this->db->save(array('last_login'=>getCurrentTime())); } return $res; } /** * 修改密码 * @param int $id 管理员id * @param string $pwd 新密码 */ public function modifyPwd($id, $pwd){ return $this->db->where(array('id'=>$id))->save(array('password'=>md5($pwd))); } public function update(){ $data = $this->db->create(); return $this->db->save($data); } public function add(){ $data = $this->db->create(); $data['password']=md5($data['password']); return $this->db->add($data); } }