user.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. class user_m extends Model
  3. {
  4. var $psize = 20;
  5. function __construct()
  6. {
  7. parent::Model();
  8. $this->psize = defined("SYS_PSIZE") ? SYS_PSIZE : 20;
  9. }
  10. function user_m()
  11. {
  12. $this->__construct();
  13. }
  14. function get_one($id)
  15. {
  16. if(!$id)
  17. {
  18. return false;
  19. }
  20. $sql = "SELECT u.*,f.thumb picture FROM ".$this->db->prefix."user u LEFT JOIN ".$this->db->prefix."upfiles f ON(u.thumb_id=f.id) WHERE u.id='".$id."'";
  21. $rs = $this->db->get_one($sql);
  22. if(!$rs) return false;
  23. //取得扩展内容
  24. //取得扩展字段信息
  25. $sql = "SELECT field,val FROM ".$this->db->prefix."user_ext WHERE id='".$id."'";
  26. $tmp_rs = $this->db->get_all($sql);
  27. if($tmp_rs && is_array($tmp_rs) && count($tmp_rs)>0)
  28. {
  29. foreach($tmp_rs AS $key=>$value)
  30. {
  31. $rs[$value["field"]] = $value["val"];
  32. }
  33. }
  34. return $rs;
  35. }
  36. //获取推荐人
  37. function get_parent_one($Recommend)
  38. {
  39. if(!$Recommend)
  40. {
  41. return false;
  42. }
  43. $sql = "SELECT * FROM ".$this->db->prefix."user WHERE id='".$Recommend."'";
  44. $rs = $this->db->get_one($sql);
  45. if(!$rs) return false;
  46. return $rs;
  47. }
  48. //读取会员列表数据
  49. function get_list($offset=0,$condition="")
  50. {
  51. //$sql = "SELECT *,(SELECT username from ".$this->db->prefix."user where id=u.Recommend) as RecommendName FROM ".$this->db->prefix."user u ";
  52. $sql = "SELECT * FROM ".$this->db->prefix."user ";
  53. if($condition)
  54. {
  55. $sql .= " WHERE ".$condition;
  56. }
  57. $sql .= " ORDER BY id DESC LIMIT ".$offset.",".$this->psize;
  58. return $this->db->get_all($sql);
  59. }
  60. //取得总数量
  61. function get_count($condition="")
  62. {
  63. $sql = "SELECT count(id) FROM ".$this->db->prefix."user ";
  64. if($condition)
  65. {
  66. $sql .= " WHERE ".$condition;
  67. }
  68. return $this->db->count($sql);
  69. }
  70. //存储会员数据
  71. function save($data,$id=0)
  72. {
  73. if($id)
  74. {
  75. $this->db->update_array($data,"user",array("id"=>$id));
  76. return $id;
  77. }
  78. else
  79. {
  80. $insert_id = $this->db->insert_array($data,"user");
  81. return $insert_id;
  82. }
  83. }
  84. function set_status($id,$status=0)
  85. {
  86. $sql = "UPDATE ".$this->db->prefix."user SET status='".$status."' WHERE id='".$id."'";
  87. return $this->db->query($sql);
  88. }
  89. function status($id,$status=0)
  90. {
  91. $sql = "UPDATE ".$this->db->prefix."user SET status='".$status."' WHERE id IN(".$id.")";
  92. return $this->db->query($sql);
  93. }
  94. function del($id)
  95. {
  96. $sql = "DELETE FROM ".$this->db->prefix."user WHERE id='".$id."'";
  97. return $this->db->query($sql);
  98. }
  99. function pl_del($id)
  100. {
  101. $sql = "DELETE FROM ".$this->db->prefix."user WHERE id IN(".$id.")";
  102. return $this->db->query($sql);
  103. }
  104. //检测电话是否冲突
  105. function chk_phone($phone,$id=0)
  106. {
  107. $sql = "SELECT id FROM ".$this->db->prefix."user WHERE phone='".$phone."' ";
  108. if($id)
  109. {
  110. $sql.= " AND id!='".$id."' ";
  111. }
  112. return $this->db->get_one($sql);
  113. }
  114. //检测身份证号是否冲突
  115. function chk_usercard($usercard,$id=0)
  116. {
  117. $sql = "SELECT id FROM ".$this->db->prefix."user WHERE usercard='".$usercard."' ";
  118. if($id)
  119. {
  120. $sql.= " AND id!='".$id."' ";
  121. }
  122. return $this->db->get_one($sql);
  123. }
  124. }
  125. ?>