Exemple #1
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $area = ['user_cover', 'user_nickname', 'user_gender', 'user_birthday', 'user_realname', 'user_district', 'user_money', 'user_money_virtual', 'user_mobile', 'persional_sign'];
     $fields = $this->getDataItem('fields');
     //字段
     $fields = explode(',', $fields);
     foreach ($fields as $f) {
         if (!in_array($f, $area)) {
             return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '字段名不存在.');
         }
     }
     $user = UserBase::find('user_id=' . $this->getUserAuth()->userId)->toArray();
     $user = $user[0];
     $fieldsArr = ['user_cover' => 'user_cover', 'user_nickname' => 'user_nickname', 'user_gender' => 'user_gender', 'user_birthday' => 'user_birthday', 'user_realname' => 'user_realname', 'user_district' => 'user_district', 'user_money' => 'user_money', 'user_money_virtual' => 'user_money_virtual', 'user_mobile' => 'user_account', 'persional_sign' => 'persional_sign'];
     $result = [];
     foreach ($fields as $field) {
         $key = $fieldsArr[$field];
         $value = $user[$key];
         if ($field == 'user_cover') {
             $value = PicUrl::UserCover($value, $this->getDi());
         }
         if ($field == 'persional_sign' && unserialize(base64_decode($value))) {
             $value = unserialize(base64_decode($value));
         }
         $result[$key] = $value;
     }
     $this->setResult($result);
 }
 /**
  * 问答详情
  * @date: 2016-1-16 
  * @author: futao
  */
 public function infoAction()
 {
     $this->setLeftNav("info");
     $req = $this->request;
     $questionId = intval($req->getQuery('id', null, 0));
     if ($questionId < 0) {
         echo "参数错误!";
         return;
     }
     $questionColumns = ['ub.user_id', 'ub.user_nickname', 'ub.user_cover', 'Apps\\Common\\Models\\Question.user_id', 'Apps\\Common\\Models\\Question.question_content', 'Apps\\Common\\Models\\Question.question_pics', 'Apps\\Common\\Models\\Question.question_addtime', 'Apps\\Common\\Models\\Question.question_browsers', 'Apps\\Common\\Models\\Question.question_id'];
     $info = Question::query()->columns($questionColumns)->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\Question.user_id', 'ub')->where("Apps\\Common\\Models\\Question.question_id = {$questionId} and Apps\\Common\\Models\\Question.question_state = 1")->execute()->getFirst();
     if (!$info) {
         echo "问题不存在!";
         exit;
     }
     $info->user_cover = PicUrl::UserCover($info->user_cover, $this->di);
     if (unserialize(base64_decode($info->question_content))) {
         $info->question_content = unserialize(base64_decode($info->question_content));
     }
     if (json_decode($info->question_pics)) {
         $info->question_pics = json_decode($info->question_pics);
     }
     $answerColumns = ['ub.user_nickname', 'ub.user_cover', 'Apps\\Common\\Models\\QuestionAnswer.answer_content', 'Apps\\Common\\Models\\QuestionAnswer.answer_addtime', 'Apps\\Common\\Models\\QuestionAnswer.answer_id', 'Apps\\Common\\Models\\QuestionAnswer.original_content', 'Apps\\Common\\Models\\QuestionAnswer.answer_pics', 'Apps\\Common\\Models\\QuestionAnswer.type', 'Apps\\Common\\Models\\QuestionAnswer.user_id'];
     $answerList = QuestionAnswer::query()->columns($answerColumns)->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\QuestionAnswer.user_id', 'ub')->where("Apps\\Common\\Models\\QuestionAnswer.question_id = {$questionId} and Apps\\Common\\Models\\QuestionAnswer.answer_state = 1")->orderBy("Apps\\Common\\Models\\QuestionAnswer.answer_floor asc")->execute()->toArray();
     foreach ($answerList as $k => $val) {
         if (unserialize(base64_decode($answerList[$k]['answer_content']))) {
             $answerList[$k]['answer_content'] = unserialize(base64_decode($answerList[$k]['answer_content']));
         }
         if (unserialize(base64_decode($answerList[$k]['original_content']))) {
             $answerList[$k]['original_content'] = unserialize(base64_decode($answerList[$k]['original_content']));
         }
         if (json_decode($answerList[$k]['answer_pics'])) {
             $answerList[$k]['answer_pics'] = json_decode($answerList[$k]['answer_pics']);
         }
         if ($answerList[$k]['type'] == 1) {
             $answerList[$k]['reply'] = QuestionAnswerComments::query()->columns(['ub.user_nickname', 'ub.user_cover', 'ub.user_id', 'content', 'add_time', 'id'])->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\QuestionAnswerComments.user_id', 'ub')->where("question_id = {$questionId} and answer_id = " . $answerList[$k]['answer_id'] . " and to_user_id = " . $answerList[$k]['user_id'])->orderBy("id desc")->execute()->toArray();
         }
         $answerList[$k]['user_cover'] = PicUrl::UserCover($answerList[$k]['user_cover'], $this->di);
     }
     $userList = UserBase::find("is_manage = 1");
     $seeList = QuestionViewsUser::query()->columns(['distinct ub.user_id', 'ub.user_cover'])->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\QuestionViewsUser.user_id', 'ub')->where("question_id = {$questionId}")->orderBy("id desc")->limit(7)->execute();
     $this->view->setVar('seelist', $seeList);
     $this->view->setVar('comment_count', QuestionAnswer::count('answer_state = 1 and question_id = ' . $questionId));
     $this->view->setVar('question_id', $questionId);
     $this->view->setVar('userlist', $userList);
     $this->view->setVar('questioninfo', $info);
     $this->view->setVar('answerlist', $answerList);
     $this->view->pick('question/info');
 }
 /**
  * 添加问题
  * @date: 2016-1-15 
  * @author: futao
  */
 public function addquestionAction()
 {
     $this->setLeftNav('addquestion');
     $req = $this->request;
     if (!$req->isPost()) {
         $userList = UserBase::find("is_manage = 1");
         $tag = BeautyParlorTagInfo::find("parent_id != 0 and tag_state = 1");
         $this->view->setVar('city_list', $this->openCityList());
         $this->view->setVar('userlist', $userList);
         $this->view->setVar('tag', $tag);
         $this->view->pick("question/add");
         return;
     }
     $this->view->disable();
     $echo = function ($msg, $state = false) {
         echo '<script type="text/javascript">';
         echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')';
         echo '</script>';
     };
     $questionContent = $req->getPost('question_content', null, '');
     $questionTag = $req->getPost('question_tag', null, '');
     $questionBrowsers = intval($req->getPost('question_browsers', null, 0));
     $userId = intval($req->getPost('user_id', null, 0));
     $cityCode = intval($req->getPost('city_id', null, 0));
     if ($userId < 0 || $questionBrowsers < 0) {
         $echo("添加失败!");
         return;
     }
     if (is_array($questionTag)) {
         foreach ($questionTag as $val) {
             $tagArr = explode(',', $val);
             $tagName = $tagArr[1];
             $tagNameArr[] = $tagName;
         }
     } else {
         $echo("标签必选!");
         return;
     }
     $questionModel = new Question();
     //保存图片
     if ($_FILES['q_photos']['name'][0] != '') {
         $uploadFile = new UploadPic();
         $uploadFile->request = $req;
         $questionPics = $uploadFile->questionPic();
         $questionModel->question_pics = json_encode($questionPics);
     } else {
         $questionModel->question_pics = json_encode([]);
     }
     $questionModel->question_content = $questionContent;
     $questionModel->city_code = $cityCode;
     $questionModel->question_browsers = $questionBrowsers;
     $questionModel->question_tag = json_encode($tagNameArr);
     $questionModel->user_id = $userId;
     if (!$questionModel->save()) {
         $echo("添加失败!");
         return;
     }
     if ($questionTag != '' && is_array($questionTag)) {
         unset($tagNameArr);
         unset($tagName);
         unset($tagArr);
         foreach ($questionTag as $val) {
             unset($tagId);
             unset($tagName);
             $tagArr = explode(',', $val);
             $tagId = $tagArr[0];
             $tagName = $tagArr[1];
             $tagNameArr[] = $tagName;
             $questionTagModel = new QuestionTag();
             $questionTagModel->question_id = $questionModel->question_id;
             $questionTagModel->tag_id = $tagId;
             $questionTagModel->tag_name = $tagName;
             if ($questionTagModel->save()) {
                 $echo("添加成功!", true);
             }
         }
     } else {
         $echo("添加失败!");
         return;
     }
 }