UserApi::show PHP Method

show() public method

用户个人主页 --using
public show ( ) : array
return array 状态+提示 或 用户信息
    public function show()
    {
        $num = $_REQUEST['num'];
        $num = intval($num);
        $num or $num = 10;
        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');
            }
        }
        if ($this->mid != $uid) {
            $privacy = model('UserPrivacy')->getPrivacy($this->mid, $uid);
            if ($privacy['space'] == 1) {
                return array('status' => 0, 'msg' => '您没有权限进入TA的个人主页');
            }
        }
        $userInfo = $this->get_user_info($uid);
        if (!$userInfo['uname']) {
            return array('status' => 0, 'msg' => '该用户不存在或已被删除');
        }
        // $userInfo['can_'] = CheckPermission('core_normal','feed_del');
        $user_info['is_admin'] = CheckPermission('core_admin', 'feed_del') ? '1' : '0';
        $user_info['uid'] = $userInfo['uid'];
        $user_info['uname'] = $userInfo['uname'];
        $user_info['remark'] = $userInfo['remark'];
        $user_info['sex'] = $userInfo['sex'] == 1 ? '男' : '女';
        $user_info['intro'] = $userInfo['intro'] ? formatEmoji(false, $userInfo['intro']) : '';
        $user_info['location'] = $userInfo['location'] ? $userInfo['location'] : '';
        $user_info['avatar'] = $userInfo['avatar']['avatar_big'];
        $user_info['experience'] = t($userInfo['user_credit']['credit']['experience']['value']);
        $user_info['charm'] = t($userInfo['user_credit']['credit']['charm']['value']);
        $user_info['weibo_count'] = t(intval($userInfo['user_data']['weibo_count']));
        $user_info['follower_count'] = t(intval($userInfo['user_data']['follower_count']));
        $user_info['following_count'] = t(intval($userInfo['user_data']['following_count']));
        $follower = model('Follow')->where('fid=' . $user_info['uid'])->order('follow_id DESC')->field('uid')->limit($num)->findAll();
        $following = model('Follow')->where('uid=' . $user_info['uid'])->order('follow_id DESC')->field('fid')->limit($num)->findAll();
        $follower_arr = $following_arr = array();
        foreach ($follower as $k => $v) {
            $follower_info = $this->get_user_info($v['uid']);
            $follower_arr[$k]['uid'] = $follower_info['uid'];
            $follower_arr[$k]['uname'] = $follower_info['uname'];
            $follower_arr[$k]['remark'] = $follower_info['remark'];
            $follower_arr[$k]['avatar'] = $follower_info['avatar']['avatar_big'];
        }
        foreach ($following as $k1 => $v1) {
            $following_info = $this->get_user_info($v1['fid']);
            $following_arr[$k1]['uid'] = $following_info['uid'];
            $following_arr[$k1]['uname'] = $following_info['uname'];
            $following_arr[$k1]['remark'] = $following_info['remark'];
            $following_arr[$k1]['avatar'] = $following_info['avatar']['avatar_big'];
        }
        $user_info['follower'] = $follower_arr;
        $user_info['following'] = $following_arr;
        $user_info['follow_status'] = model('Follow')->getFollowState($this->mid, $uid);
        $user_info['is_in_blacklist'] = t(D('user_blacklist')->where('uid=' . $this->mid . ' and fid=' . $uid)->count());
        $user_info['photo_count'] = model('Attach')->where(array('is_del' => 0, 'attach_type' => 'feed_image', 'uid' => $uid))->count();
        $user_info['photo'] = $this->user_photo($uid);
        $map['uid'] = $uid;
        $map['type'] = 'postvideo';
        $map['is_del'] = 0;
        $user_info['video_count'] = M('feed')->where($map)->count();
        $user_info['video'] = $this->user_video($uid);
        $user_info['level_src'] = $userInfo['user_credit']['level']['src'];
        // 用户认证图标
        $groupIcon = array();
        $userGroup = model('UserGroupLink')->getUserGroupData($uid);
        foreach ($userGroup[$uid] as $g) {
            $g['is_authenticate'] == 1 && ($groupArr[] = $g['user_group_name']);
        }
        $user_info['authenticate'] = empty($groupArr) ? '无' : implode(' , ', $groupArr);
        /* # 获取用户认证理由 */
        $user_info['certInfo'] = D('user_verified')->where('verified=1 AND uid=' . $uid)->field('info')->getField('info');
        /* # 获取用户封面 */
        $user_info['cover'] = D('user_data')->where('`key` LIKE "application_user_cover" AND `uid` = ' . $uid)->field('value')->getField('value');
        $user_info['cover'] = getImageUrlByAttachId($user_info['cover']);
        // 用户组
        $user_group = model('UserGroupLink')->where('uid=' . $uid)->field('user_group_id')->findAll();
        foreach ($user_group as $v) {
            $user_group_icon = D('user_group')->where('user_group_id=' . $v['user_group_id'])->getField('user_group_icon');
            if ($user_group_icon != -1) {
                $user_info['user_group'][] = THEME_PUBLIC_URL . '/image/usergroup/' . $user_group_icon;
            }
        }
        // 勋章
        $list = M()->query('select b.small_src from ' . C('DB_PREFIX') . 'medal_user a inner join ' . C('DB_PREFIX') . 'medal b on a.medal_id=b.id where a.uid=' . $uid . ' order by a.ctime desc limit 10');
        foreach ($list as $v) {
            $smallsrc = explode('|', $v['small_src']);
            $user_info['medals'][] = $smallsrc[1];
        }
        $user_info['gift_count'] = M('gift_user')->where($map)->count();
        $user_info['gift_list'] = $gift_list;
        $user_info['user_credit'] = $userInfo['user_credit'];
        $user_info['tags'] = (array) model('Tag')->setAppName('public')->setAppTable('user')->getAppTags($uid, true);
        // 没登陆过智播没有usid的 直接生成一个
        $live_user_mod = M('live_user_info');
        if (!($usid = $live_user_mod->where(array('uid' => $userInfo['uid']))->getField('usid'))) {
            $live_user_info = file_get_contents(SITE_URL . '/api.php?api_version=live&mod=LiveUser&act=postUser&uid=' . $userInfo['uid']);
            $live_user_info = json_decode($live_user_info, true);
            $live_user_info['status'] == 1 && ($user_info['usid'] = $live_user_info['data']['usid']);
        } else {
            $user_info['usid'] = $usid;
        }
        //可查看自己的绑定账户
        if ($uid == $this->mid) {
            $userAccountinfo = D('user_account')->where(array('uid' => $this->mid))->find();
            if (!$userAccountinfo) {
                $user_info['account'] = '';
                $user_info['account_type'] = 0;
            } else {
                $length = strlen($userAccountinfo['account']);
                $user_info['account'] = substr_replace($userAccountinfo['account'], '****', 3, $length - 3);
                $user_info['account_type'] = $userAccountinfo['type'];
            }
        }
        return $user_info;
    }