ExamController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\ExamService;
  5. use App\Services\Exam\SubjectService;
  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 subjects()
  34. {
  35. try {
  36. $type = request()->post('type', 0);
  37. $sceneType = request()->post('scene_type', 0);
  38. $sc = request()->post('sc', 0);
  39. $datas = SubjectService::make()->getListByAttrType($type, $sceneType, $sc);
  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 history()
  51. {
  52. try {
  53. $params = request()->post();
  54. $pageSize = request()->post('pageSize', 10);
  55. $params['user_id'] = $this->userId;
  56. $datas = ExamService::make()->getHistoryList($params, $pageSize);
  57. return message(1010, true, $datas);
  58. } catch (\Exception $exception) {
  59. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  60. return message(1009, false, $error);
  61. }
  62. }
  63. /**
  64. * 错题记录
  65. * @return array
  66. */
  67. public function errors()
  68. {
  69. try {
  70. $params = request()->post();
  71. $pageSize = request()->post('pageSize', 10);
  72. $params['user_id'] = $this->userId;
  73. $datas = ExamService::make()->getErrorList($params, $pageSize);
  74. return message(1010, true, $datas);
  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 practice()
  85. {
  86. try {
  87. $params = request()->post();
  88. $pageSize = request()->post('pageSize', 10);
  89. $datas = ExamService::make()->getPracticeList($this->userId, $params, $pageSize);
  90. return message(1010, true, $datas);
  91. } catch (\Exception $exception) {
  92. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  93. return message(1009, false, $error);
  94. }
  95. }
  96. /**
  97. * 答题
  98. * @return array
  99. */
  100. public function answer()
  101. {
  102. try {
  103. $params = request()->all();
  104. if ($result = ExamService::make()->answer($this->userId, $params)) {
  105. return showJson(ExamService::make()->getError(), true, $result);
  106. } else {
  107. return showJson(ExamService::make()->getError(), false);
  108. }
  109. } catch (\Exception $exception) {
  110. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  111. return message(1003, false, $error);
  112. }
  113. }
  114. /**
  115. * 再次答题
  116. * @return array
  117. */
  118. public function reset()
  119. {
  120. try {
  121. $id = request()->post('id');
  122. if (ExamService::make()->reset($id, $this->userId)) {
  123. return showJson(1002, true);
  124. } else {
  125. return showJson(ExamService::make()->getError(), false);
  126. }
  127. } catch (\Exception $exception) {
  128. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  129. return message(1003, false, $error);
  130. }
  131. }
  132. /**
  133. * 详情
  134. */
  135. public function info()
  136. {
  137. try {
  138. $params = request()->all();
  139. $rid = isset($params['rid']) ? intval($params['rid']) : 0;
  140. if (empty($rid)) {
  141. return message(1036, false);
  142. }
  143. if ($info = ExamService::make()->getInfo($rid)) {
  144. return message(1010, true, $info);
  145. } else {
  146. return message(1009, false);
  147. }
  148. } catch (\Exception $exception) {
  149. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  150. return message(1009, false, $error);
  151. }
  152. }
  153. /**
  154. * 排行榜
  155. */
  156. public function ranks()
  157. {
  158. try {
  159. $params = request()->all();
  160. $type = isset($params['type']) ? intval($params['type']) : 0;
  161. if (empty($type)) {
  162. return message(1031, false);
  163. }
  164. $datas = ExamService::make()->getRankByType($type);
  165. return message(1010, true, $datas);
  166. } catch (\Exception $exception) {
  167. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  168. return message(1009, false, $error);
  169. }
  170. }
  171. /**
  172. * 答题卡数据
  173. */
  174. public function cards()
  175. {
  176. try {
  177. $params = request()->all();
  178. $rid = isset($params['rid']) ? intval($params['rid']) : 0;
  179. $paperId = isset($params['id']) ? intval($params['id']) : 0;
  180. if (empty($paperId)) {
  181. return message(1031, false);
  182. }
  183. $datas = ExamService::make()->getCardList($this->userId, $paperId, $rid);
  184. return message(1010, true, $datas);
  185. } catch (\Exception $exception) {
  186. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  187. return message(1009, false, $error);
  188. }
  189. }
  190. }