db = $db; } //获取用户的组ID public function getGroup($uid=0){ if(!empty($uid) && is_numeric($uid)) { $sql = "SELECT gid FROM ".$this->tbl_userToGroup." WHERE uid=$uid"; $rs = $this->db->query($sql); $row = $rs->fetch(); return $row['gid']; }else{ $select = $this->db->select(); return $select ->from($this->tbl_group) ->order('groups.id desc'); } } //获取组名 public function getGroupName($gid){ if(!is_numeric($gid)) { return false; } $sql = "SELECT * FROM ".$this->tbl_group." WHERE id=$gid"; $rs = $this->db->query($sql); $row = $rs->fetch(); return $row['name']; } //创建用户组 public function CreateGroup($name){ $groupTable = $this->tbl_group; if(empty($name)) { return false; } $data = array( "name" => $name ); return $this->db->insert($groupTable,$data); } //把用户移动到组 public function AddTo($uid,$gid){ if(!is_numeric($uid) || !is_numeric($gid)) { return false; } $sql = "SELECT * FROM ".$this->tbl_userToGroup." WHERE uid=? AND gid=?"; $sth = $this->db->prepare($sql); $sth->execute(array($uid,$gid)); $row = $sth->fetch(); if(!empty($row['ts_created'])) { $data = array( "uid"=>$uid, "gid"=>$gid ); $whereSql = " uid=$uid AND gid=$gid "; return $this->db->update($this->tbl_userToGroup,$data,$whereSql); }else{ $data = array( "uid"=>$uid, "gid"=>$gid ); return $this->db->insert($this->tbl_userToGroup,$data); } } }