コード例 #1
0
ファイル: ExpertInfo.php プロジェクト: fu-tao/meelier_c2.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);
 }
コード例 #2
0
ファイル: ExpertList.php プロジェクト: fu-tao/meelier_c2.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);
 }
コード例 #3
0
 /**
  * 更新用户信息
  * @date: 2016-1-5 
  * @author: futao
  */
 public function editsaveAction()
 {
     $req = $this->request;
     $district = $req->getPost('district', null, '');
     $nickname = $req->getPost('nickname', null, '');
     $realname = $req->getPost('realname', null, '');
     $phone = $req->getPost('phone', null, '');
     $persional_sign = $req->getPost('persional_sign', null, '');
     $birthday = $req->getPost('birthday', null, '');
     $userId = intval($req->getPost('user_id', null, 0));
     $gender = $req->getPost('sex', null, 2);
     $experience = $req->getPost("experience", null, '');
     //从业经验
     $field = $req->getPost("field", null, '');
     //擅长领域
     $experttitle = $req->getPost("experttitle", null, '');
     //专家头衔
     $echo = function ($msg, $state = false) {
         echo '<script type="text/javascript">';
         echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')';
         echo '</script>';
     };
     $usermodel = UserBase::findFirst("user_id = {$userId} and is_manage = 1");
     if (!$usermodel) {
         $echo("用户不存在!");
         return;
     }
     if ($field == "" || !is_array($field)) {
         $echo("擅长领域必填!");
         return;
     }
     $data = ['experience' => $experience, 'experttitle' => $experttitle, 'field' => $field];
     $datajson = json_encode($data);
     $info = UserAttribute::findFirst("user_id = {$userId} and attr_type = 103");
     $info->attr_value_json = $datajson;
     $info->save();
     //用户头像
     if ($_FILES['avatar']['name'] != '') {
         $uploadFile = new UploadPic();
         $uploadFile->request = $req;
         $cover = $uploadFile->userCover();
         if ($cover == false) {
             if ($_FILES['avatar']['error'] == 1) {
                 $echo('封面大小超过了2M!');
             } else {
                 $echo('封面必须上传!');
             }
             return;
         }
         $usermodel->user_cover = $cover;
     }
     $usermodel->user_district = $district;
     $usermodel->user_nickname = $nickname;
     $usermodel->user_realname = $realname;
     $usermodel->bind_phone = $phone;
     //个性签名编码
     if ($persional_sign != '') {
         $usermodel->persional_sign = base64_encode(serialize($persional_sign));
     }
     //$usermodel->persional_sign=$persional_sign;
     $usermodel->user_birthday = $birthday;
     $usermodel->user_gender = $gender;
     if ($usermodel->save()) {
         $echo('ok', true);
     } else {
         $echo("添加失败!");
     }
 }