Esempio n. 1
0
 public function run()
 {
     $question_id = intval($this->getDataItem('question_id', 0));
     if ($question_id < 1) {
         return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '参数错误!');
     }
     $QuestionTag = new QuestionTag();
     if ($tagList = $QuestionTag->query()->where('question_id = ' . $question_id)->execute()->toArray()) {
         $tag_id = '';
         foreach ($tagList as $val) {
             $tag_id .= $val['tag_id'] . ',';
         }
         $tag_id = '(' . trim($tag_id, ',') . ')';
         $question_id_list = $QuestionTag->query()->groupBy('question_id')->where("tag_id in{$tag_id} and question_id != {$question_id}")->orderBy('id DESC')->limit(50)->execute()->toArray();
         if ($question_id_list) {
             /*$where_question_id = '';
               foreach ($question_id_list as $val) {
                   $where_question_id .= $val['question_id'] . ',';
               }
               $where_question_id = '(' . trim($where_question_id, ',') . ')';*/
             // 随机取相关问答的id
             $count = count($question_id_list);
             if ($count >= 3) {
                 $start = mt_rand(0, $count - 3);
                 $where_question_id = '(' . $question_id_list[$start]['question_id'] . ',' . $question_id_list[$start + 1]['question_id'] . ',' . $question_id_list[$start + 2]['question_id'] . ')';
             } else {
                 $where_question_id = '';
                 foreach ($question_id_list as $val) {
                     $where_question_id .= $val['question_id'] . ',';
                 }
                 $where_question_id = '(' . trim($where_question_id, ',') . ')';
             }
             $list = Question::query()->columns(['question_id', 'question_content', 'question_pics', 'question_tag', 'answer_num', 'question_browsers', 'question_addtime', 'u.user_id', 'u.user_nickname', 'u.user_expert', 'u.user_cover', 'u.user_gender'])->leftJoin('\\Apps\\Common\\Models\\UserBase', 'u.user_id = \\Apps\\Common\\Models\\Question.user_id', 'u')->where("question_id in{$where_question_id} and question_state = 1")->execute()->toArray();
             foreach ($list as $k => $val) {
                 $list[$k]['question_tag'] = $val['question_tag'] ? json_decode($val['question_tag'], true) : [];
                 $list[$k]['user_cover'] = PicUrl::UserCover($val['user_cover'], $this->getDi());
                 $list[$k]['question_content'] = unserialize(base64_decode($val['question_content'])) ?: $val['question_content'];
                 if ($val['question_pics']) {
                     $question_pics = [];
                     foreach (json_decode($val['question_pics'], true) as $key => $value) {
                         $question_pics[] = PicUrl::Question($value, $this->getDi());
                     }
                     $list[$k]['question_pics'] = $question_pics;
                 }
             }
             $this->setResult($list);
         }
     }
 }
Esempio n. 2
0
 /**
  * 问题列表
  */
 public function listAction()
 {
     $this->setLeftNav('list');
     $req = $this->request;
     $page = intval($req->getQuery('page', null, 1));
     $page = $page > 0 ? $page : 1;
     $limit = $this->pageNavLimit;
     $offset = $limit * ($page - 1);
     $filterTag = intval($req->getQuery('filterTag', null, -10000));
     $filterOrder = intval($req->getQuery('filterOrder', null, 0));
     $columns = ['question_id', 'ub.user_id', 'user_nickname', 'user_cover', 'question_tag', 'tag_title', 'question_content', 'question_pics', 'answer_num', 'question_follows', 'question_browsers', 'question_state', 'question_addtime'];
     $where = [];
     $bind = [];
     if ($filterTag > 0) {
         $where[] = 'Apps\\Common\\Models\\Question.question_tag = :tag:';
         $bind['tag'] = $filterTag;
     }
     // 只查询正常的内容
     $where[] = 'Apps\\Common\\Models\\Question.question_state > 0';
     $whereStr = implode(' AND ', $where);
     $query = Question::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\Question.user_id', 'ub')->leftJoin('Apps\\Common\\Models\\QuestionTag', 'tag.tag_id = question_tag', 'tag');
     if (count($where) > 0) {
         $query = $query->where($whereStr)->bind($bind);
     }
     $data = $query->orderBy($filterOrder == 1 ? 'answer_num ASC, question_id DESC' : 'question_id DESC')->limit($limit, $offset)->execute();
     $total = Question::count(['conditions' => $whereStr, 'bind' => $bind]);
     $this->view->setVar('data', $data);
     $this->view->setVar('page', $page);
     $this->view->setVar('limit', $limit);
     $this->view->setVar('total', $total);
     $this->view->setVar('tagList', QuestionTag::query()->columns('*')->orderBy('tag_order DESC, tag_id ASC')->execute());
     $this->view->setVar('filterTag', $filterTag);
     $this->view->setVar('filterOrder', $filterOrder);
 }
Esempio n. 3
0
 public function run()
 {
     $limit = $this->getConfig()->limit;
     //统计问答标签出现的次数 倒序获取次数最多即热门标签
     $list = QuestionTag::query()->columns('b.tag_id id,tag_name name')->join('Apps\\Common\\Models\\BeautyParlorTagInfo', 'Apps\\Common\\Models\\QuestionTag.tag_id = b.tag_id', 'b')->where('tag_state = 1 AND b.parent_id IN (SELECT s.tag_id FROM Apps\\Common\\Models\\BeautyParlorTagInfo as s WHERE tag_state>0 AND parent_id=0 ) GROUP BY Apps\\Common\\Models\\QuestionTag.tag_id')->orderBy('COUNT(Apps\\Common\\Models\\QuestionTag.tag_id) desc')->limit($limit, 0)->execute()->toArray();
     //如果热门标签不足 获取 最新标签补足
     if (count($list) < $limit) {
         $limit -= count($list);
         $temp = BeautyParlorTagInfo::query()->columns(['tag_id id', 'tag_title name'])->where('tag_state = 1 AND  parent_id IN (SELECT tag_id FROM Apps\\Common\\Models\\BeautyParlorTagInfo WHERE tag_state>0 AND parent_id=0 )')->orderBy('tag_id DESC')->limit($limit, 0)->execute()->toArray();
         //合并数据
         $list = array_merge($list, $temp);
     }
     $this->setResult($list);
 }
Esempio n. 4
0
 /**
  * 问题列表
  * @date: 2016年1月19日 
  * @author: futao
  */
 public function listAction()
 {
     $this->setLeftNav('list');
     $req = $this->request;
     $page = intval($req->getQuery('page', null, 1));
     $page = $page > 0 ? $page : 1;
     $limit = $this->pageNavLimit;
     $offset = $limit * ($page - 1);
     $filterUser = intval($req->getQuery('filterUser', null, -10000));
     $filterState = intval($req->getQuery('filterState', null, -10000));
     $filtertime = $req->getQuery('inputtime', null, '');
     $filtercontent = $req->getQuery('qcontent', null, '');
     $filtertag = $req->getQuery('qtag', null, '');
     $filtercity = $req->getQuery('cityCode', null, 0);
     $filterNew = $req->getQuery('new', null, -1);
     $columns = ['Apps\\Common\\Models\\Question.question_id', 'ub.user_id', 'ub.user_nickname', 'ub.user_cover', 'Apps\\Common\\Models\\Question.question_tag', 'Apps\\Common\\Models\\Question.question_content', 'Apps\\Common\\Models\\Question.question_pics', 'Apps\\Common\\Models\\Question.answer_num', 'Apps\\Common\\Models\\Question.question_follows', 'Apps\\Common\\Models\\Question.question_browsers', 'Apps\\Common\\Models\\Question.question_state', 'Apps\\Common\\Models\\Question.question_addtime', 'Apps\\Common\\Models\\Question.city_code'];
     $where = [];
     $bind = [];
     //筛选数据
     if ($filtercity == -1) {
         $where[] = 'city_code <> 0 ';
         $this->setLeftNav('citylist');
     }
     if ($filterNew > -1) {
         $where[] = 'Apps\\Common\\Models\\Question.is_manager_reply = :new:';
         $bind['new'] = $filterNew;
     }
     if ($filtertag != '') {
         $questionIds = QuestionTag::query()->columns("question_id")->where('tag_name like "%' . $filtertag . '%"')->execute()->toArray();
         if ($questionIds != '') {
             foreach ($questionIds as $val) {
                 $ids[] = $val['question_id'];
             }
             $ids = implode(",", $ids);
             $where[] = 'Apps\\Common\\Models\\Question.question_id in (' . $ids . ')';
         }
     }
     if ($filtertime != '') {
         if (explode("至", $filtertime)) {
             $timearr[] = explode("至", $filtertime);
             $start_time = $timearr[0][0];
             $end_time = $timearr[0][1];
             if ($start_time != '' && $end_time != '') {
                 $where[] = 'Apps\\Common\\Models\\Question.question_addtime >= :start_time: and Apps\\Common\\Models\\Question.question_addtime <= :end_time:';
                 $bind['start_time'] = $start_time;
                 $bind['end_time'] = $end_time;
             }
         }
     }
     if ($filtercontent != '') {
         $where[] = 'Apps\\Common\\Models\\Question.question_content like :content:';
         $bind['content'] = '%' . $filtercontent . '%';
     }
     if ($filterUser > 0) {
         $where[] = 'Apps\\Common\\Models\\Question.user_id = :uid:';
         $bind['uid'] = $filterUser;
     }
     if ($filterState > -10000) {
         $where[] = 'Apps\\Common\\Models\\Question.question_state = :state:';
         $bind['state'] = $filterState;
     }
     $whereStr = implode(' AND ', $where);
     $query = Question::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\Question.user_id', 'ub');
     if (count($where) > 0) {
         $query = $query->where($whereStr)->bind($bind);
     }
     $data = $query->orderBy('Apps\\Common\\Models\\Question.question_id DESC')->limit($limit, $offset)->execute()->toArray();
     $total = Question::count(['conditions' => $whereStr, 'bind' => $bind]);
     foreach ($data as $k => $v) {
         //问题内容解码
         if (unserialize(base64_decode($v['question_content']))) {
             $data[$k]['question_content'] = unserialize(base64_decode($v['question_content']));
         }
         if (json_decode($data[$k]['question_tag'])) {
             $data[$k]['question_tag'] = json_decode($data[$k]['question_tag']);
         }
     }
     $this->view->setVar('data', $data);
     $this->view->setVar('page', $page);
     $this->view->setVar('limit', $limit);
     $this->view->setVar('total', $total);
     $this->view->setVar('openCity', $this->openCityList());
     $this->view->setVar('filterNew', $filterNew);
     $this->view->setVar('cityCode', $filtercity);
     $this->view->setVar('inputtime', $filtertime);
     $this->view->setVar('filterUser', $filterUser);
     $this->view->setVar('filtertag', $filtertag);
     $this->view->setVar('filterState', $filterState);
     $this->view->setVar('qcontent', $filtercontent);
 }
Esempio n. 5
0
 public function run()
 {
     $this->tags = QuestionTag::query()->columns(['tag_id id', 'tag_title title'])->where('tag_state = 1')->orderBy('tag_order DESC, tag_id ASC')->execute()->toArray();
     $this->tags = $this->tags ? $this->tags : [];
     $this->setResult($this->tags);
 }
Esempio n. 6
0
 public function updateAction()
 {
     $req = $this->request;
     if (!$req->isPost()) {
         $id = intval($req->getQuery('id', null, 0));
         $tagTitle = '';
         $tagOrder = 0;
         if ($id > 0) {
             $info = QuestionTag::findFirst('tag_id=' . $id);
             if ($info) {
                 $tagTitle = $info->tag_title;
                 $tagOrder = $info->tag_order;
             }
         }
         $this->view->setVar('id', $id);
         $this->view->setVar('tagTitle', $tagTitle);
         $this->view->setVar('tagOrder', $tagOrder);
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $id = intval($req->getPost('tag_id', null, 0));
     $title = $req->getPost('tag_title');
     $order = intval($req->getPost('tag_order', null, '-10000'));
     // 通过名称查找,是否存在
     $exist = function ($title, $id) {
         $existInfo = QuestionTag::query()->columns('*')->where('tag_title = :title:', ['title' => $title])->limit(1)->execute()->getFirst();
         if ($existInfo && $existInfo->tag_id != $id) {
             return true;
         }
         return false;
     };
     if ($id > 0) {
         // 修改
         $info = QuestionTag::findFirst('tag_id=' . $id);
         if (!$info) {
             $response->sendError(ResponseResultStatus::ERROR, '分类不存在!');
             return $response;
         }
         if ($exist($title, $id)) {
             $response->sendError(ResponseResultStatus::ERROR, '名称已经存在了!');
             return $response;
         }
         $data = [];
         if ($info->tag_title != $title) {
             $data['tag_title'] = $title;
         }
         if ($order > -1) {
             $data['tag_order'] = $order;
         }
         if (count($data) > 0) {
             $info->update($data);
         }
     } else {
         // 添加
         if ($exist($title, $id)) {
             $response->sendError(ResponseResultStatus::ERROR, '名称已经存在了!');
             return $response;
         }
         $tag = new QuestionTag();
         $tag->tag_title = $title;
         $tag->tag_order = $order;
         if (!$tag->save()) {
             $this->databaseErrorLog($tag);
             $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常!');
             return $response;
         }
     }
     $response->sendResult('ok');
     return $response;
 }