ExamController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. $params = request()->post();
  19. $pageSize = request()->post('pageSize', 15);
  20. $datas = ExamService::make()->getDataList($params, $pageSize);
  21. return message(1010, true, $datas);
  22. }
  23. /**
  24. * 答题历史
  25. * @return array
  26. */
  27. public function history()
  28. {
  29. try {
  30. $params = request()->post();
  31. $pageSize = request()->post('pageSize', 15);
  32. $datas = ExamService::make()->getHistoryList($params, $pageSize);
  33. return message(1010, true, $datas);
  34. } catch (\Exception $exception) {
  35. return message(1009, false);
  36. }
  37. }
  38. /**
  39. * 详情
  40. */
  41. public function info()
  42. {
  43. $params = request()->all();
  44. $id = isset($params['id']) ? intval($params['id']) : 0;
  45. if (empty($id)) {
  46. return message(1036, false);
  47. }
  48. if ($info = ArticleService::make()->getInfo($id)) {
  49. return message(1010, true, $info);
  50. } else {
  51. return message(1009, false);
  52. }
  53. }
  54. /**
  55. * 排行榜
  56. */
  57. public function ranks()
  58. {
  59. $params = request()->all();
  60. $type = isset($params['type']) ? intval($params['type']) : 0;
  61. if (empty($type)) {
  62. return message(1031, false);
  63. }
  64. $datas = ExamService::make()->getRankByType($type);
  65. return message(1010, true, $datas);
  66. }
  67. }