Question.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\mainapp\controller;
  3. use think\facade\Session;
  4. use app\mainapp\BaseController;
  5. use app\common\model\Question as QuestionModel;
  6. use app\common\model\QuestionCate as QuestionCateModel;
  7. class Question extends BaseController
  8. {
  9. // 详情
  10. public function getQuestion()
  11. {
  12. $questionid = input('questionid/d', 0);
  13. $question = QuestionModel::with('questionCate')->append(['createtime_text'])->findOrEmpty($questionid);
  14. if ($question->isEmpty()){
  15. page_result(1, "通知公告信息不存在");
  16. }
  17. $question->volume += 1;
  18. $question->save();
  19. page_result(0, "", array(
  20. 'question' => $question
  21. ));
  22. }
  23. // 列表
  24. public function listQuestion()
  25. {
  26. $ppage = input('ppage/d', 1);
  27. $psize = input('psize/d', 20);
  28. $map[] = ['status','=',1];
  29. $cateid = input('cateid/d');
  30. if ($cateid!=0){
  31. $map[] = ['cateid', '=', $cateid];
  32. }
  33. $plist = QuestionModel::with('questionCate')->where($map)->order(['priority'=>'desc','id'=>'desc'])->page($ppage)->limit($psize)->append(['createtime_text'])->select();
  34. page_result(0, "", array(
  35. 'plist' => $plist,
  36. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more'
  37. ));
  38. }
  39. // 全部分类
  40. public function allCate()
  41. {
  42. $allcate = QuestionCateModel::where('status',1)->order(['priority'=>'desc','id'=>'desc'])->select()->toArray();
  43. array_unshift( $allcate, array('id'=>0,'title'=>'全部') );
  44. page_result(0, "", array('allcate'=>$allcate));
  45. }
  46. }