Exemplo n.º 1
0
 public static function handleCode($code)
 {
     $openid = ImWx::getRequestUserId();
     $userInfo = D('User')->getUserFromOpenId($openid);
     if ($userInfo['verified'] == 1) {
         ImWx::fetchTextResult('您已经完成验证,无需再次输入邀请码。请进入' . self::generateEntryUrl() . '。');
     }
     $exist = D('InviteCode')->where(array('code' => $code))->find();
     if (!$exist) {
         ImWx::fetchTextResult('您输入的邀请码有误,请核实后再试。');
     }
     if ($exist['to_uid'] || $exist['use_time']) {
         ImWx::fetchTextResult('您输入的邀请码已被使用过,您可以请求推荐人为您申请新的邀请码。');
     }
     D('InviteCode')->where(array('code' => $code))->save(array('to_uid' => $userInfo['uid'], 'use_time' => time()));
     $degree = Degree::getDegreeByUid($userInfo['uid']);
     D('User')->where(array('uid' => $userInfo['uid']))->save(array('verified' => 1, 'allow_invite_count' => $degree == 1 ? 12 : 0));
     ImWx::fetchTextResult('验证成功。首次进入填写的资料包括您的【微信号】,请先记好哦~进入' . self::generateEntryUrl() . '。');
 }
 private function others_profile($uid)
 {
     /*
     $myUser = D('User')->find($this->uid);
     //非验证用户无法访问
     if($myUser['verified'] != 1)
         $this->responseError(new CommonException('200101'));
     $myUserInfo = D('UserInfo')->find($this->uid);
     //未选择身份无法访问
     if($myUserInfo['is_single'] == -1)
         $this->responseError(new CommonException('200101'));
     //介绍人身份
     if($myUserInfo['is_single'] == 0){
         //只能访问自己邀请的人的信息
         $myInvites = D('InviteCode')->where(array('from_uid'=>$this->uid))->select();
         $myInviteUids = array();
         foreach ($myInvites as $value)
             if($value['to_uid'])
                 $myInviteUids[] = $value['to_uid'];
         if(!in_array($uid, $myInviteUids))
             $this->responseError(new CommonException('200101'));
     }
     
     $result = D('User')->where(array('verified'=>1))->find($uid);
     //不允许访问错误的uid,或者未认证的uid
     if(!$result) $this->responseError(new CommonException('200101'));
     unset($result['openid']);
     $result['user_info'] = D('UserInfo')->where(array('uid'=>$uid))->find();
     if(!$result['user_info']){
         D('User')->createUserInfoItem($uid);
         $result['user_info'] = D('UserInfo')->where(array('uid'=>$uid))->find();
     }
     //不允许访问介绍人或未选身份人的信息
     if($result['user_info']['is_single'] != 1){
         $this->responseError(new CommonException('200101'));
     }
     */
     $userInfos = Privilege::canIntereact($this->uid, $uid);
     if (!$userInfos) {
         $this->responseError(new CommonException('200101'));
     }
     $fromUserInfo = $userInfos[0];
     $toUserInfo = $userInfos[1];
     //不允许单身访问同性的信息
     if ($fromUserInfo['is_single'] == 1 && $toUserInfo['user_info']['gender'] == $fromUserInfo['user_info']['gender']) {
         $this->responseError(new CommonException('200101'));
     }
     unset($toUserInfo['openid']);
     $toUserInfo['relation_text'] = Degree::getRelationText($this->uid, $uid);
     $toUserInfo['photo'] = D('Photo')->where(array('uid' => $uid, 'status' => 1))->select();
     $toUserInfo['photo'] = $toUserInfo['photo'] ? $toUserInfo['photo'] : array();
     D('ViewLog')->add(array('from_uid' => $this->uid, 'to_uid' => $uid, 'view_time' => time()));
     $this->responseSuccess($toUserInfo);
 }