member_interface.class.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * 会员接口
  4. *
  5. */
  6. class member_interface {
  7. //数据库连接
  8. private $db;
  9. public function __construct() {
  10. $this->db = pc_base::load_model('member_model');
  11. }
  12. /**
  13. * 获取用户信息
  14. * @param $username 用户名
  15. * @param $type {1:用户id;2:用户名;3:email}
  16. * @return $mix {-1:用户不存在;userinfo:用户信息}
  17. */
  18. public function get_member_info($mix, $type=1) {
  19. $mix = safe_replace($mix);
  20. if($type==1) {
  21. $userinfo = $this->db->get_one(array('userid'=>$mix));
  22. } elseif($type==2) {
  23. $userinfo = $this->db->get_one(array('username'=>$mix));
  24. } elseif($type==3) {
  25. if(!$this->_is_email($mix)) {
  26. return -4;
  27. }
  28. $userinfo = $this->db->get_one(array('email'=>$mix));
  29. }
  30. if($userinfo) {
  31. return $userinfo;
  32. } else {
  33. return -1;
  34. }
  35. }
  36. /**
  37. * 将文章加入收藏夹
  38. * @param int $cid 文章id
  39. * @param int $userid 会员id
  40. * @param string $title 文章标题
  41. * @param $mix {-1:加入失败;$id:加入成功,返回收藏id}
  42. */
  43. public function add_favorite($cid, $userid, $title) {
  44. $cid = intval($cid);
  45. $userid = intval($userid);
  46. $title = safe_replace($title);
  47. $this->favorite_db = pc_base::load_model('favorite_model');
  48. $id = $this->favorite_db->insert(array('title'=>$title,'userid'=>$userid, 'cid'=>$cid, 'adddate'=>SYS_TIME), 1);
  49. if($id) {
  50. return $id;
  51. } else {
  52. return -1;
  53. }
  54. }
  55. /**
  56. * 根据uid增加用户积分
  57. * @param int $userid 用户id
  58. * @param int $point 点数
  59. * @return boolean
  60. */
  61. public function add_point($userid, $point) {
  62. $point = intval($point);
  63. return $this->db->update(array('point'=>"+=$point"), array('userid'=>$userid));
  64. }
  65. }