Qw.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace app\controller;
  3. use app\model\qw\QwCategory;
  4. use app\model\qw\QwDepartment;
  5. use app\model\qw\QwSub;
  6. use think\facade\Request;
  7. use think\response\Json;
  8. /**
  9. * 科室知识问题
  10. */
  11. class Qw extends CommonTwoController
  12. {
  13. /**
  14. * 科室列表
  15. */
  16. public function categoryList()
  17. {
  18. return $this->_json_succ(
  19. QwDepartment::withSearch('status')->select()->toArray()
  20. );
  21. }
  22. /**
  23. * 科室下分类列表
  24. */
  25. public function departmentList()
  26. {
  27. $departmentId = Request::param('department_id') ?? '';
  28. $where = [];
  29. if( $departmentId) {
  30. $where = [
  31. 'department_id' => $departmentId
  32. ];
  33. }
  34. $categoryList = QwCategory::where($where)->withSearch('status')->select()->toArray();
  35. return $this->_json_succ(
  36. $categoryList
  37. );
  38. }
  39. /**
  40. * 分类下问题
  41. */
  42. public function questionList()
  43. {
  44. $categoryId = Request::param('category_id') ?? '';
  45. if( ! $categoryId) {
  46. return $this->_json_error('未获取到分类Id');
  47. }
  48. $questionList = \app\model\qw\Qw::where('category_id' , $categoryId)
  49. ->withSearch('status' , 1)
  50. ->select()->toArray() ?? [];
  51. return $this->_json_succ(
  52. $questionList
  53. );
  54. }
  55. /**
  56. * 热门问题
  57. */
  58. public function hotQuestionList()
  59. {
  60. $questionList = \app\model\qw\Qw::withSearch('status')->select()->toArray() ?? [];
  61. return $this->_json_succ(
  62. [
  63. 'show_title' => '热门问题',
  64. 'question_list' => $questionList
  65. ]
  66. );
  67. }
  68. /**
  69. * 问题对应答案
  70. */
  71. public function getAnswerByQuestion()
  72. {
  73. $params = Request::only(
  74. [
  75. 'question_id' , 'search' , 'is_sub_question' , 'category_id'
  76. ]
  77. );
  78. $search = $params['search'] ?? '';
  79. $questionId = $params['question_id'] ?? '';
  80. $isSubQuestion = $params['is_sub_question'] ?? '';
  81. /**
  82. * 输入的情况
  83. */
  84. if($search) {
  85. /**
  86. * 检测问题 问题主表 / 问题子表
  87. */
  88. $question = \app\model\qw\Qw::where("question" , "like" , "%$search%")->select()->toArray() ?? [];
  89. if( ! empty($question)) {
  90. return $this->_json_succ($question);
  91. }
  92. $subQuestion = QwSub::where('sub_question', 'like' , "%$search%")->select()->toArray() ?? [];
  93. if( ! empty($subQuestion)) {
  94. return $this->_json_succ($question);
  95. }
  96. if( empty($question) && empty($subQuestion)) {
  97. return 121212;
  98. /**
  99. * 检索不到返分类
  100. */
  101. $qwCategory = \app\model\qw\QwCategory::select();
  102. return $this->_json_succ($qwCategory);
  103. }
  104. $categoryId = $params['category_id'] ?? '';
  105. if($categoryId) {
  106. $qwSubCategory = QwCategory::where('category_id', $categoryId)->select()->toArray();
  107. return $this->_json_succ($qwSubCategory);
  108. }
  109. }
  110. /**
  111. * 点选的情况
  112. */
  113. if( ! $search) {
  114. /**
  115. * 子问题
  116. */
  117. if($isSubQuestion) {
  118. $result = QwSub::field('id as sub_question_id , sub_question as question, sub_answer as answer')->where('id', $questionId)->select()->toArray();
  119. } else {
  120. $result = \app\model\qw\Qw::find($questionId);
  121. if( 1 == $result->is_have_question_select) {
  122. /**
  123. * 多级问题回答
  124. */
  125. $result = QwSub::field('id as sub_question_id, question_id , sub_question , is_sub_question')->where('question_id' , $questionId)->select()->toArray();
  126. } else {
  127. /**
  128. * 一级问题回答
  129. */
  130. $result = \app\model\qw\Qw::field('id as question_id , question , answer')->where('id' , $questionId)->select()->toArray();
  131. }
  132. }
  133. }
  134. return $this->_json_succ(
  135. $result
  136. );
  137. }
  138. }