You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

4 years ago
  1. <?php
  2. namespace Home\Model;
  3. use Home\Model\BaseModel;
  4. class UserModel extends BaseModel {
  5. /**
  6. * 用户名是否已经存在
  7. *
  8. */
  9. public function isExist($username){
  10. return $this->where("username = '%s'",array($username))->find();
  11. }
  12. /**
  13. * 注册新用户
  14. *
  15. */
  16. public function register($username,$password){
  17. $password = md5(base64_encode(md5($password)).'576hbgh6');
  18. return $this->add(array('username'=>$username ,'password'=>$password , 'reg_time'=>time()));
  19. }
  20. //修改用户密码
  21. public function updatePwd($uid, $password){
  22. $password = md5(base64_encode(md5($password)).'576hbgh6');
  23. return $this->where("uid ='%d' ",array($uid))->save(array('password'=>$password));
  24. }
  25. /**
  26. * 返回用户信息
  27. * @return
  28. */
  29. public function userInfo($uid){
  30. return $this->where("uid = '%d'",array($uid))->find();
  31. }
  32. /**
  33. *@param username:登录名
  34. *@param password 登录密码
  35. */
  36. public function checkLogin($username,$password){
  37. $password = md5(base64_encode(md5($password)).'576hbgh6');
  38. $where=array($username,$password);
  39. return $this->where("username='%s' and password='%s'",$where)->find();
  40. }
  41. //设置最后登录时间
  42. public function setLastTime($uid){
  43. return $this->where("uid='%s'",array($uid))->save(array("last_login_time"=>time()));
  44. }
  45. }