UserApi::user_following PHP Method

user_following() public method

用户关注列表 --using
public user_following ( ) : array
return array 用户信息+关注状态
    public function user_following()
    {
        if (empty($this->user_id) && empty($this->data['uname'])) {
            $uid = $this->mid;
        } else {
            if ($this->user_id) {
                $uid = intval($this->user_id);
            } else {
                $uid = model('User')->where(array('uname' => $this->data['uname']))->getField('uid');
            }
        }
        $max_id = $this->max_id ? intval($this->max_id) : 0;
        $count = $this->count ? intval($this->count) : 20;
        if (t($this->data['key'])) {
            $map['f.`uid`'] = $uid;
            !empty($max_id) && ($map['follow_id'] = array('lt', $max_id));
            $_map['u.`uname`'] = array('LIKE', '%' . $this->data['key'] . '%');
            //通过备注名搜索
            $ruid_arr = D('UserRemark')->searchRemark($this->mid, t($this->data['key']));
            if ($ruid_arr) {
                $_map['u.`uid`'] = array('IN', $ruid_arr);
                $_map['_logic'] = 'OR';
            }
            $map['_complex'] = $_map;
            $following = D()->table('`' . C('DB_PREFIX') . 'user_follow` AS f LEFT JOIN `' . C('DB_PREFIX') . 'user` AS u ON f.`fid` = u.`uid`')->field('f.`follow_id` AS `follow_id`,f.`fid` AS `fid`')->where($map)->order('follow_id DESC')->limit($count)->findAll();
        } else {
            $where = 'uid = ' . $uid;
            !empty($max_id) && ($where .= " AND follow_id < {$max_id}");
            $following = model('Follow')->where($where)->order('follow_id DESC')->field('follow_id,fid')->limit($count)->findAll();
        }
        $follow_status = model('Follow')->getFollowStateByFids($this->mid, getSubByKey($following, 'fid'));
        $following_arr = array();
        foreach ($following as $k => $v) {
            $following_arr[$k]['follow_id'] = $v['follow_id'];
            $following_info = $this->get_user_info($v['fid']);
            $following_arr[$k]['user_group'] = $following_info['user_group'];
            $following_arr[$k]['uid'] = $v['fid'];
            $following_arr[$k]['uname'] = $following_info['uname'];
            $following_arr[$k]['remark'] = $following_info['remark'];
            $following_arr[$k]['intro'] = $following_info['intro'] ? formatEmoji(false, $following_info['intro']) : '';
            $following_arr[$k]['avatar'] = $following_info['avatar']['avatar_big'];
            $following_arr[$k]['follow_status'] = $follow_status[$v['fid']];
        }
        return $following_arr;
    }