auth->id; } //如果不是我,并且开了隐私,直接返回空 if($user_id != $this->auth->id){ $yinsi = $this->user_power($user_id,'yinsi'); if($yinsi == 1){ $this->success(1,[]); } } //列表 $list = Db::name('user_follow') ->alias('follow') ->join('user','follow.follow_uid = user.id','LEFT') ->join('user_wallet uw','user.id = uw.user_id','LEFT') ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime') ->where('follow.uid',$user_id)->order('follow.id desc')->group('follow.follow_uid')->autopage()->select(); $list = list_domain_image($list,['avatar']); $list = list_birthday_age($list); //我的关注uids $my_follow_uids = $this->my_follow_uids(); if(!empty($list)){ foreach($list as $key => &$val){ //用户vip $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0; unset($val['vip_endtime']); //是否关注 $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0; } } $this->success('success',$list); } //我的粉丝列表 public function my_fans_list(){ $user_id = input('user_id',0); if(empty($user_id)){ $user_id = $this->auth->id; } //如果不是我,并且开了隐私,直接返回空 if($user_id != $this->auth->id){ $yinsi = $this->user_power($user_id,'yinsi'); if($yinsi == 1){ $this->success(1,[]); } } //列表 $list = Db::name('user_follow') ->alias('follow') ->join('user','follow.uid = user.id','LEFT') ->join('user_wallet uw','user.id = uw.user_id','LEFT') ->join('user_power power','user.id = power.user_id','LEFT') ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime') ->where('follow.follow_uid',$user_id) ->where('power.yinsi',0) ->group('follow.uid') ->order('follow.id desc')->autopage()->select(); $list = list_domain_image($list,['avatar']); $list = list_birthday_age($list); //我的关注uids $my_follow_uids = $this->my_follow_uids(); if(!empty($list)){ foreach($list as $key => &$val){ //用户vip $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0; unset($val['vip_endtime']); //是否关注 $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0; } } $this->success('success',$list); } //我的好友,拿粉丝列表改的 public function my_friend_list(){ $list = Db::name('user_follow') ->alias('follow') ->join('user','follow.uid = user.id','LEFT') ->join('user_wallet uw','user.id = uw.user_id','LEFT') ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime') ->where('follow.follow_uid',$this->auth->id) ->group('follow.uid') ->order('follow.id desc')->autopage()->select(); $list = list_domain_image($list,['avatar']); $list = list_birthday_age($list); //我的关注uids $my_follow_uids = $this->my_follow_uids(); $new_rs = []; //另起 if(!empty($list)){ foreach($list as $key => &$val){ //用户vip $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0; unset($val['vip_endtime']); //是否关注 $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0; //我的粉丝,且是我的关注的,另起 if($val['is_follow'] == 1){ $new_rs[] = $val; } } } $this->success('success',$new_rs); } //好友审核列表。粉丝列表改的。关注了我,我还没关注他的 //接口废弃,使用 newfriend_list public function my_fans_unfollow_list(){ //我的关注uids $my_follow_uids = $this->my_follow_uids(); $list = Db::name('user_follow') ->alias('follow') ->join('user','follow.uid = user.id','LEFT') ->join('user_wallet uw','user.id = uw.user_id','LEFT') ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime') ->where('follow.follow_uid',$this->auth->id)->where('user.id','NOT IN',$my_follow_uids)->order('follow.id desc')->autopage()->select(); $list = list_domain_image($list,['avatar']); $list = list_birthday_age($list); if(!empty($list)){ foreach($list as $key => &$val){ //用户vip $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0; unset($val['vip_endtime']); //是否关注 $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0; } } $this->success('success',$list); } //好友待审核列表。 public function newfriend_list(){ //我的关注uids $my_follow_uids = $this->my_follow_uids(); // dump($my_follow_uids); $list = Db::name('message')->alias('msg') ->join('user user','user.id = msg.infotype_id','LEFT') ->join('user_wallet uw','user.id = uw.user_id','LEFT') ->field('msg.id as msg_id,user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime') ->where(['msg.infotype'=>'newfriend','msg.user_id'=>$this->auth->id,'msg.audit_status'=>0]) ->where('msg.infotype_id','NOT IN',$my_follow_uids) ->order('msg.id desc')->autopage()->select(); $list = list_domain_image($list,['avatar']); $list = list_birthday_age($list); if(!empty($list)){ foreach($list as $key => &$val){ //用户vip $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0; unset($val['vip_endtime']); //是否关注 $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0; } } $this->success('success',$list); } //拒绝好友请求 public function refuse_newfriend(){ $id = input('msg_id',0); $msg_info = Db::name('message')->where('id',$id)->find(); Db::name('message')->where('id',$id)->update(['audit_status'=>1]); //拒绝给个消息 if($msg_info['infotype'] == 'newfriend' && !empty($msg_info['infotype_id'])){ $msg_id = \app\common\model\Message::addMessage($msg_info['infotype_id'],'好友申请被拒绝',$this->auth->nickname.'拒绝了您的好友请求'); } $this->success('已拒绝'); } //关注某人 public function follow_one(){ $follow_uid = input('follow_uid',0); $msg_id = input('msg_id',0); if(!$follow_uid){ $this->error(__('Invalid parameters')); } $checkuser = Db::name('user')->find($follow_uid); if(empty($checkuser)){ $this->error('此用户不存在'); } if($follow_uid == $this->auth->id){ $this->error('不能关注自己'); } $map = [ 'uid' => $this->auth->id, 'follow_uid' => $follow_uid, ]; $check = Db::name('user_follow')->where($map)->find(); if($check){ //取关 $rs = Db::name('user_follow')->where($map)->delete(); $this->success('操作成功'); } Db::startTrans(); $id = Db::name('user_follow')->insertGetId($map); if(!$id){ Db::rollback(); $this->error('关注失败'); } //被关注人如果没有关注我,发一条消息,让他加好友,也就是让他回关 $map2 = [ 'uid' => $follow_uid, 'follow_uid' => $this->auth->id, ]; $check = Db::name('user_follow')->where($map2)->find(); if(empty($check) && $this->user_power($this->auth->id,'yinsi') != 1){ //防止重复刷关注,先删掉以前的,再加新的 Db::name('message') ->where('user_id',$follow_uid) ->where('infotype','newfriend') ->where('infotype_id',$this->auth->id) ->delete(); $message = [ 'user_id' => $follow_uid, 'title' => '好友请求', 'content' => '有人关注了你,回关TA成为好友', 'createtime' => time(), 'status' => 0, 'infotype' => 'newfriend',//关注,请求好友 'infotype_id' => $this->auth->id, ]; Db::name('message')->insertGetId($message); } //我从好友审核列表过来的,我又回关了 if(!empty($msg_id)){ Db::name('message')->where('id',$id)->update(['audit_status'=>1]); $msg_id = \app\common\model\Message::addMessage($follow_uid,'好友申请已通过',$this->auth->nickname.'同意了您的好友请求'); } Db::commit(); $this->success('操作成功',$id); } //取关某人 public function un_follow_one(){ $follow_uid = input('follow_uid',0); if(!$follow_uid){ $this->error(__('Invalid parameters')); } $checkuser = Db::name('user')->find($follow_uid); if(empty($checkuser)){ $this->error('此用户不存在'); } $map = [ 'uid' => $this->auth->id, 'follow_uid' => $follow_uid, ]; //不检查,全删 $rs = Db::name('user_follow')->where($map)->delete(); $this->success('操作成功'); } //我的关注uids private function my_follow_uids(){ $list = Db::name('user_follow')->where('uid',$this->auth->id)->column('follow_uid'); $list = array_flip($list); $list = array_flip($list); return $list; } //我的粉丝uids private function my_fans_uids(){ $list = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid'); $list = array_flip($list); $list = array_flip($list); return $list; } }