Exemple #1
0
 public function run()
 {
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $user_id = intval($this->getDataItem('user_id', 0));
     $to_user_id = intval($this->getDataItem('to_user_id', 0));
     $type = intval($this->getDataItem('type', 0));
     if ($user_id == 0 || $to_user_id == 0 || $type == 0) {
         $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, 'URL参数不全');
         return false;
     }
     if (!in_array($type, ['1', '2'])) {
         $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, 'type类型错误!');
         return false;
     }
     $UserFollow = new UserFollow();
     if ($UserFollow->is_follow($user_id, $to_user_id, $type)) {
         $this->setResult(['success' => 3, 'message' => '已经关注过了']);
     } else {
         // 未关注
         if ($UserFollow->follow($user_id, $to_user_id, $type)) {
             if ($type == 2) {
                 // 增加专家的粉丝数
                 (new \Apps\Common\Models\UserBase())->setExpertFollowCount($to_user_id, 1, true);
             }
             $this->setResult(['success' => 1, 'message' => '关注成功']);
         } else {
             $this->setResult(['success' => 2, 'message' => '关注失败']);
         }
     }
 }
Exemple #2
0
 public function run()
 {
     $to_user_id = $this->getDataItem('user_id');
     if (!(is_numeric($to_user_id) && $to_user_id > 0)) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '用户id不能为空.');
     }
     /**
      * 验证用户权限
      */
     /*if(!empty($this->parameters->userToken) && $this->verifyUserAuth() && $this->getUserAuth()->userId == $userid){
           return $this->errorLog(111, '请跳转我的问答.');
       }*/
     $field = ['user_cover', 'user_nickname', 'user_gender', 'user_birthday', 'user_realname', 'user_district', 'user_money', 'user_money_virtual', 'bind_phone user_mobile', 'persional_sign', 'user_expert'];
     $info = UserBase::query()->columns($field)->where('user_id=' . $to_user_id)->execute()->getFirst()->toArray();
     // 获取城市信息
     $SysAreaZipDistrictPhonecode = new SysAreaZipDistrictPhonecode();
     $city = $SysAreaZipDistrictPhonecode->getOne($info['user_district']);
     $info['user_district'] = $city['FULL_NAME'] ?: '';
     // 加入关注数和粉丝数
     $UserFollow = new UserFollow();
     $info['follow_count'] = $UserFollow->getFollowCount($to_user_id, 1);
     $info['fans_count'] = $UserFollow->getToFollowCount($to_user_id, 1);
     $info['user_cover'] = $info['user_cover'] ? PicUrl::UserCover($info['user_cover'], $this->getDi()) : '';
     $info['persional_sign'] = $info['persional_sign'] ? unserialize(base64_decode($info['persional_sign'])) : '';
     $this->verifyUserAuth(false);
     if ($user_id = $this->getUserAuth()->userId) {
         $info['is_follow'] = $UserFollow->is_follow($user_id, $to_user_id, 1) ? '1' : '0';
     } else {
         $info['is_follow'] = '0';
     }
     $this->setResult($info);
 }