Cate.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace addons\exam\controller;
  3. use addons\exam\enum\CateKind;
  4. use app\admin\model\exam\CateModel;
  5. /**
  6. * 分类接口
  7. */
  8. class Cate extends Base
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 按种类查询分类
  14. */
  15. public function index()
  16. {
  17. if (!$kind = input('kind/s')) {
  18. fail('缺少分类种类参数');
  19. }
  20. $model = new CateModel();
  21. $data['level1'] = $model->where('status', '1')->where('kind', $kind)->where('level', 1)->order('sort desc')->select();
  22. $data['level2'] = $model->where('status', '1')->where('kind', $kind)->where('level', 2)->order('sort desc')->select();
  23. $data['level3'] = $model->where('status', '1')->where('kind', $kind)->where('level', 3)->order('sort desc')->select();
  24. $this->success('', $data);
  25. }
  26. /**
  27. * 3级分类筛选
  28. */
  29. public function filter()
  30. {
  31. $kind = input('kind/s');
  32. if (!$kind || !in_array($kind, [CateKind::PAPER, CateKind::QUESTION, CateKind::ROOM])) {
  33. fail('筛选参数错误');
  34. }
  35. $submenu = [];
  36. switch ($kind) {
  37. case CateKind::QUESTION:
  38. case CateKind::PAPER:
  39. $submenu = [
  40. [
  41. 'name' => '默认排序',
  42. 'value' => '',
  43. ],
  44. [
  45. 'name' => '按参与人数从低到高',
  46. 'value' => "join_count|asc",
  47. ],
  48. [
  49. 'name' => '按参与人数从高到低',
  50. 'value' => "join_count|desc",
  51. ],
  52. ];
  53. break;
  54. case CateKind::ROOM:
  55. $submenu = [
  56. [
  57. 'name' => '默认排序',
  58. 'value' => '',
  59. ],
  60. [
  61. 'name' => '按报考人数从低到高',
  62. 'value' => "signup_count|asc",
  63. ],
  64. [
  65. 'name' => '按报考人数从高到低',
  66. 'value' => "signup_count|desc",
  67. ],
  68. [
  69. 'name' => '按考试人数从低到高',
  70. 'value' => "grade_count|asc",
  71. ],
  72. [
  73. 'name' => '按考试人数从高到低',
  74. 'value' => "grade_count|desc",
  75. ],
  76. [
  77. 'name' => '按及格人数从低到高',
  78. 'value' => "pass_count|asc",
  79. ],
  80. [
  81. 'name' => '按及格人数从高到低',
  82. 'value' => "pass_count|desc",
  83. ],
  84. ];
  85. break;
  86. }
  87. $filter = [
  88. [
  89. 'name' => '筛选分类',
  90. 'type' => 'hierarchy',
  91. 'submenu' => CateModel::threeLevel($kind)
  92. ],
  93. [
  94. 'name' => '排序',
  95. 'type' => 'hierarchy',
  96. 'submenu' => $submenu
  97. ]
  98. ];
  99. $this->success('', $filter);
  100. }
  101. /**
  102. * 3级分类获取
  103. */
  104. public function getThree()
  105. {
  106. $kind = input('kind/s');
  107. if (!$kind || !in_array($kind, [CateKind::PAPER, CateKind::QUESTION, CateKind::ROOM])) {
  108. fail('筛选参数错误');
  109. }
  110. $cates = CateModel::threeLevel2($kind);
  111. $this->success('', $cates);
  112. }
  113. }