Example #1
0
 public function run()
 {
     $user_id = intval($this->getDataItem('user_id', 0));
     $expert_id = intval($this->getDataItem('expert_id', 0));
     //		$expert_id = 289;
     if ($expert_id < 1) {
         return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '缺少必传参数!');
     }
     $columns = ['user_id', 'user_nickname', 'user_cover', 'expert_follow_count', 'persional_sign'];
     if ($UserBase = UserBase::query()->columns($columns)->where('user_expert = 1 and user_id = ' . $expert_id)->execute()->getFirst()) {
         $info = $UserBase->toArray();
         $info['user_cover'] = PicUrl::ActivityCover($info['user_cover'], $this->getDi());
         if ($userAttribute = UserAttribute::findFirst('attr_type = 103 and attr_state = 1 and user_id = ' . $expert_id)) {
             $attr_value_json = $userAttribute->attr_value_json;
         } else {
             $attr_value_json = [];
         }
         $info['persional_sign'] = $info['persional_sign'] ? unserialize(base64_decode($info['persional_sign'])) : '';
         $attr_value_json = $attr_value_json ? json_decode($attr_value_json) : [];
         $info['experience'] = $attr_value_json->experience ?: '';
         // 从业经验
         $info['experttitle'] = $attr_value_json->experttitle ?: '';
         // 擅长领域
         $info['field'] = $attr_value_json->field ?: [];
         // 专家头衔(array)
         if ($user_id > 0) {
             $info['is_follow'] = (new UserFollow())->is_follow($user_id, $expert_id, 2) ? '1' : '0';
         } else {
             $info['is_follow'] = '0';
         }
         // 回答问题数
         $result = (new UserBase())->getReadConnection()->query("SELECT count(*) c FROM\r\n(SELECT count(*) FROM question_answer WHERE answer_state = 1 AND user_id = {$expert_id} GROUP BY question_id) a;");
         $count = $result->fetch();
         $info['question_count'] = $count['c'];
     } else {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '用户不存在或不是专家');
     }
     $this->setResult($info);
 }
Example #2
0
 public function run()
 {
     $user_id = intval($this->getDataItem('user_id', 0));
     $page = intval($this->getDataItem('page', 1));
     $limit = $this->getConfig()->limit;
     $offset = ($page - 1) * $limit;
     //		$user_id = 12;
     $where = 'user_expert = 1 and user_state = 1';
     if ($user_id > 0) {
         // 用户关注的专家列表
         $followExpert = UserFollow::query()->where("user_id = {$user_id} and type = 2")->execute()->toArray();
         $expert = '';
         foreach ($followExpert as $val) {
             $expert .= $val['to_user_id'] . ',';
         }
         if ($expert && ($expert = trim($expert, ','))) {
             $where = "user_expert = 1 and user_state = 1 and user_id not in({$expert})";
         }
     }
     $list = UserBase::query()->columns(['user_id', 'user_nickname', 'user_cover', 'expert_follow_count'])->where($where)->orderBy('expert_follow_count DESC')->limit($limit, $offset)->execute()->toArray();
     foreach ($list as $k => $val) {
         $list[$k]['user_cover'] = PicUrl::ActivityCover($val['user_cover'], $this->getDi());
         // 获取专家的扩展信息
         if ($userAttribute = UserAttribute::findFirst('attr_type = 103 and attr_state = 1 and user_id = ' . $val['user_id'])) {
             $attr_value_json = $userAttribute->attr_value_json;
         } else {
             $attr_value_json = [];
         }
         $info = $attr_value_json ? json_decode($attr_value_json) : [];
         $list[$k]['experience'] = $info->experience ?: '0';
         // 从业经验
         $list[$k]['experttitle'] = $info->experttitle ?: '';
         // 擅长领域
         $list[$k]['field'] = $info->field ?: '';
         // 专家头衔(array)
     }
     $this->setResult($list);
 }
Example #3
0
 private function register($type, $attrType, $openId, $nickname, $cover, $otherData)
 {
     // 添加基础信息
     $base = new UserBase();
     $base->user_account = '';
     $base->user_password = '';
     $base->user_nickname = $nickname;
     /* if($cover!=''){
       	$base->user_cover = $this->getConfig()->defaultCover; //'default.png';
        } */
     //$config=$this->Config()->aliyun->oss;
     $img = file_get_contents($cover);
     file_put_contents('img/1.jpg', $img);
     $oss = new OSS('dUBfr1wNHjgMnJsd', '1U6ZSbOKhGBffxsopuMIKN6xCpSzUe', 'oss-cn-beijing.aliyuncs.com');
     $options = array();
     $object_name = time() . rand(10000, 99999);
     $file_path = "user-cover/" . date("Y/m/d") . "/" . $object_name . ".jpg";
     $response = $oss->upload_file_by_file('meelier', $file_path, 'img/1.jpg');
     unlink('img/1.jpg');
     $url = $response->header['_info']['url'];
     $url = str_replace("http://oss-cn-beijing.aliyuncs.com/meelier/", "", $url);
     if ($attrType == 101) {
         $base->user_cover = json_decode($otherData)->headimgurl ?: $url;
     } else {
         $base->user_cover = $url;
     }
     // $base->user_cover=$this->getConfig()->defaultCover;
     if (!$base->save()) {
         $this->databaseErrorLog($base);
         return false;
     }
     $userId = $base->user_id;
     // 保存第三方登录信息
     $attr = new UserAttribute();
     $attr->user_id = $userId;
     $attr->attr_type = 100;
     $attr->attr_key = $type;
     $attr->attr_value_json = $openId;
     if (!$attr->save()) {
         $this->databaseErrorLog($attr);
         return false;
     }
     $attr2 = new UserAttribute();
     $attr2->user_id = $userId;
     $attr2->attr_type = $attrType;
     $attr2->attr_key = $openId;
     $attr2->attr_value_json = $otherData;
     if (!$attr2->save()) {
         $this->databaseErrorLog($attr2);
         return false;
     }
     return $userId;
 }
Example #4
0
 /**
  * 设置成专家信息
  * @date: 2016-1-6 
  * @author: futao
  */
 public function setExpertinfoAction()
 {
     $req = $this->request;
     if (!$req->isPost()) {
         $userId = $req->getQuery('userid', null, 0);
         if (!$userId) {
             echo "用户不存在";
             return;
         }
         $tagList = BeautyParlorTagInfo::find("tag_state = 1 and parent_id !=0");
         $this->view->setVar("userId", $userId);
         $this->view->setVar("tagList", $tagList);
         $this->view->pick('user/setexpertinfo');
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     //$response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数问题!');
     /* $response->sendResult(1);
       	return $response; */
     $experience = $req->getPost("experience", null, '');
     //从业经验
     $userId = $req->getPost("userId", null, '');
     $field = $req->getPost("field", null, '');
     //擅长领域
     $experttitle = $req->getPost("experttitle", null, '');
     //专家头衔
     //验证数据
     if ($field == "" || !is_array($field)) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '擅长领域必填!');
         return $response;
     }
     if ($userId == "") {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数错误!');
         return $response;
     }
     $userInfo = UserBase::findFirst($userId);
     if (!$userInfo) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数错误!');
         return $response;
     }
     $data = ['experience' => $experience, 'experttitle' => $experttitle, 'field' => $field];
     $datajson = json_encode($data);
     $userAttr = new UserAttribute();
     $userAttr->attr_value_json = $datajson;
     $userAttr->user_id = $userId;
     $userAttr->attr_type = 103;
     $userAttr->attr_state = 1;
     $userAttr->attr_key = time();
     $userAttrId = $userAttr->save();
     if (!$userAttrId) {
         $response->sendError(ResponseResultStatus::ERROR, '设置失败!');
         return $response;
     }
     $userInfo->user_expert = 1;
     if ($userInfo->save()) {
         $response->sendResult(1);
     } else {
         $response->sendError(ResponseResultStatus::ERROR, '设置失败!');
     }
     return $response;
 }