ExamController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\ArticleService;
  5. use App\Services\Api\ExamService;
  6. /**
  7. * 考试管理
  8. * @package App\Http\Controllers\Api
  9. */
  10. class ExamController extends webApp
  11. {
  12. /**
  13. * 答题记录
  14. * @return array
  15. */
  16. public function index()
  17. {
  18. try {
  19. $params = request()->post();
  20. $pageSize = request()->post('pageSize', 10);
  21. $params['user_id'] = $this->userId;
  22. $datas = ExamService::make()->getDataList($params, $pageSize);
  23. return message(1010, true, $datas);
  24. } catch (\Exception $exception) {
  25. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  26. return message(1009, false, $error);
  27. }
  28. }
  29. /**
  30. * 答题历史
  31. * @return array
  32. */
  33. public function history()
  34. {
  35. try {
  36. $params = request()->post();
  37. $pageSize = request()->post('pageSize', 10);
  38. $params['user_id'] = $this->userId;
  39. $datas = ExamService::make()->getHistoryList($params, $pageSize);
  40. return message(1010, true, $datas);
  41. } catch (\Exception $exception) {
  42. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  43. return message(1009, false, $error);
  44. }
  45. }
  46. /**
  47. * 每日一练
  48. * @return array
  49. */
  50. public function practice()
  51. {
  52. try {
  53. $params = request()->post();
  54. $pageSize = request()->post('pageSize', 10);
  55. $datas = ExamService::make()->getPracticeList($this->userId, $params, $pageSize);
  56. return message(1010, true, $datas);
  57. } catch (\Exception $exception) {
  58. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  59. return message(1009, false, $error);
  60. }
  61. }
  62. /**
  63. * 答题
  64. * @return array
  65. */
  66. public function answer()
  67. {
  68. try {
  69. $params = request()->all();
  70. if($result = ExamService::make()->answer($this->userId, $params)){
  71. return showJson(ExamService::make()->getError(), true, $result);
  72. }else{
  73. return showJson(ExamService::make()->getError(), false);
  74. }
  75. } catch (\Exception $exception) {
  76. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  77. return message(1009, false, $error);
  78. }
  79. }
  80. /**
  81. * 再次答题
  82. * @return array
  83. */
  84. public function reset()
  85. {
  86. try {
  87. $id = request()->post('id');
  88. if(ExamService::make()->reset($id, $this->userId)){
  89. return showJson(1002, true);
  90. }else{
  91. return showJson(ExamService::make()->getError(), false);
  92. }
  93. } catch (\Exception $exception) {
  94. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  95. return message(1009, false, $error);
  96. }
  97. }
  98. /**
  99. * 详情
  100. */
  101. public function info()
  102. {
  103. $params = request()->all();
  104. $rid = isset($params['rid']) ? intval($params['rid']) : 0;
  105. if (empty($rid)) {
  106. return message(1036, false);
  107. }
  108. if ($info = ExamService::make()->getInfo($rid)) {
  109. return message(1010, true, $info);
  110. } else {
  111. return message(1009, false);
  112. }
  113. }
  114. /**
  115. * 排行榜
  116. */
  117. public function ranks()
  118. {
  119. $params = request()->all();
  120. $type = isset($params['type']) ? intval($params['type']) : 0;
  121. if (empty($type)) {
  122. return message(1031, false);
  123. }
  124. $datas = ExamService::make()->getRankByType($type);
  125. return message(1010, true, $datas);
  126. }
  127. /**
  128. * 答题卡数据
  129. */
  130. public function cards()
  131. {
  132. $params = request()->all();
  133. $rid = isset($params['rid']) ? intval($params['rid']) : 0;
  134. $paperId = isset($params['id']) ? intval($params['id']) : 0;
  135. if (empty($paperId)) {
  136. return message(1031, false);
  137. }
  138. $datas = ExamService::make()->getCardList($this->userId, $paperId, $rid);
  139. return message(1010, true, $datas);
  140. }
  141. }