ExamController.php 5.0 KB

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