123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace User\Model;
- use Think\Model;
- /**
- * 管理员模型
- * @author Superbee
- *
- */
- class AdminModel extends Model{
-
- protected $fields = array('id', 'name', 'password', 'realname', 'last_login' , 'last_ip',
- '_pk' => '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);
- }
-
-
- }
|