id = (string)$userID; $this->set = new ARedisSet($this->id); $this->f_set = new ARedisSet($this->id.'_follow_by'); } //关注某个用户 public function follow($user_id) { $user = (string)$user_id; if($user != $this->id){ $this->set->add($user); $user_follow_by_set = new ARedisSet($user.'_follow_by'); //被关注用户粉丝列表 $user_follow_by_set->add($this->id); $c_user = RUser::get(new MongoId($this->id)); $z_message = new ZMessage(); $from_user = Yii::app()->params['sys_user']; $m_data = array( 'from_user' => $from_user, 'to_user' => $user, 'content' => ''.$c_user->user_name.' 关注了你' , 'pics' => array(), 'voice' => array(), 'video'=> array() ); $z_message->addMessage($m_data); } } //取消关注 public function unfollow($user) { $user = (string)$user; if ($this->is_following($user)) { $this->set->remove($user); $user_follow_by_set = new ARedisSet($user.'_follow_by'); //被关注用户粉丝列表 $user_follow_by_set->remove($this->id); } } //获取关注列表 public function following() { return $this->set->getData(); } //获取粉丝列表 public function followed_by() { return $this->f_set->getData(); } //判断是否互相关注 public function is_mutual($user){ $user = (string)$user; return in_array($user,$this->mutual_set); } //判断是否关注某用户 public function is_following($user) { $user = (string)$user; return $this->set->contains($user); } //判断是否被某用户关注 public function is_followed_by($user) { $user = (string)$user; return $this->f_set->contains($user); } //获取互相关注列表 public function mutual_follow() { return $this->set->inter($this->f_set); } //获取用户关注数 public function follow_count() { return $this->set->getCount(); } //获取粉丝数 public function follower_count() { return $this->f_set->getCount(); } //判断用户关系 public function relation($user){ $user = (string)$user; if ($this->is_following($user)) {//关注 if($this->is_followed_by($user)){ return 3; }else{ return 1; } }elseif ($this->is_followed_by($user)) {//被关注 return 2; }else{ return 0; } } }