| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- /**
- *
- * @author meitu
- *
- */
- class userDao extends Dao
- {
- public $table_name = 'user';
- private $fields = "uid,user_name,email,pass,passwd,t,u,d,plan,transfer_enable,port,switch,enable,type,last_get_gift_time,last_check_in_time,last_rest_pass_time,reg_date,invite_num,money,code,vaild_time,last_login_time";
- /**
- * 新增用户
- *
- * @param
- * $user
- */
- public function createUser($info)
- {
- $info = $this->dao->db->build_key($info, $this->fields);
- return $this->dao->db->insert($info, $this->table_name);
- }
- /**
- * 删除一个用户
- *
- * @param unknown $uid
- * @return boolean
- */
- public function delUser($uid)
- {
- $data = array(
- 'switch' => 0
- )
- // 'enable' => 0
- ;
- return $this->dao->db->update_by_field($data, array(
- 'uid' => $uid
- ), $this->table_name);
- }
- /**
- * 根据用户id获取用户
- *
- * @return Ambigous <multitype:, boolean>
- */
- public function getUserById($id, $force = FALSE)
- {
- $result = $this->dao->db->get_one($id, $this->table_name, 'uid');
- return $result;
- }
- /**
- * 获取最后一个用户的端口号
- */
- public function getLastPort()
- {
- $sql = "SELECT port FROM `$this->table_name` ORDER BY UID DESC";
- $result = $this->dao->db->get_one_sql($sql);
- return $result['port'];
- }
- /**
- * 获取所有用户的总流量
- */
- public function getAllTran()
- {
- $sql = "SELECT SUM(u) as up,SUM(d) as down FROM `user`";
- $result = $this->dao->db->get_one_sql($sql);
- return $result['up'] + $result['down'];
- }
- /**
- * 根据用户名获取用户
- *
- * @return Ambigous <multitype:, boolean>
- */
- public function getUserByName($name)
- {
- $result = $this->dao->db->get_one_by_field(array(
- 'user_name' => $name
- ), $this->table_name);
- return $result;
- }
- /**
- * 根据邮箱获取用户
- *
- * @return Ambigous <multitype:, boolean>
- */
- public function getUserByEmail($email)
- {
- $result = $this->dao->db->get_one_by_field(array(
- 'email' => $email
- ), $this->table_name);
- return $result;
- }
- /**
- * 获取用户
- *
- * @return Ambigous <multitype:, boolean>
- */
- public function getUserByField($field)
- {
- $result = $this->dao->db->get_one_by_field($field, $this->table_name);
- return $result;
- }
- /**
- * 检测用户是否可以注册
- *
- * @param unknown $userinfo
- * @return boolean
- */
- public function checkUser($userinfo)
- {
- $result = $this->dao->db->get_one_by_field(array(
- 'user_name' => $userinfo['username']
- ), $this->table_name);
- if ($result) {
- return false;
- }
- $result = $this->dao->db->get_one_by_field(array(
- 'email' => $userinfo['email']
- ), $this->table_name);
- if ($result) {
- return false;
- }
- return true;
- }
- public function getUsers($num = NULL, $offset = 0)
- {
- $return = $this->dao->db->get_all($this->table_name, $num, $offset, array(), "d", 'desc');
- return $return[0];
- }
- public function getCount()
- {
- return $this->dao->db->get_count($this->table_name);
- }
- /**
- * 更新用户信息
- *
- * @param unknown $data
- * @param unknown $field
- * @return boolean
- */
- public function updateUser($id, $data)
- {
- $data = $this->dao->db->build_key($data, $this->fields);
- $result = $this->dao->db->update_by_field($data, array(
- "uid" => $id
- ), $this->table_name);
- return $result;
- }
- public function resetTran()
- {
- $sql = "UPDATE `user` SET `u` = '0', `d` = '0',`transfer_enable`='32212254720'";
- return $this->dao->db->query($sql);
- }
- }
|