PaperController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\PaperService;
  5. /**
  6. * 试卷管理
  7. * @package App\Http\Controllers\Api
  8. */
  9. class PaperController extends webApp
  10. {
  11. /**
  12. * 试题列表
  13. * @return array
  14. */
  15. public function index()
  16. {
  17. $params =request()->post();
  18. $params['user_id'] = $this->userId;
  19. $pageSize = request()->post('pageSize', 15);
  20. $datas = PaperService::make()->getDataList($params, $pageSize);
  21. return message(1010, true, $datas);
  22. }
  23. /**
  24. * 详情
  25. */
  26. public function info()
  27. {
  28. try {
  29. $params = request()->all();
  30. $id = isset($params['id'])? intval($params['id']) : 0;
  31. if(empty($id)){
  32. return message(1036, false);
  33. }
  34. if($info = PaperService::make()->getInfo($this->userId, $id, $params)){
  35. return message(1010, true, $info);
  36. }else{
  37. return message(1009, false);
  38. }
  39. }catch (\Exception $exception){
  40. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  41. return message(1009, false, $error);
  42. }
  43. }
  44. /**
  45. * 试题纠错
  46. * @return array
  47. */
  48. public function error()
  49. {
  50. try {
  51. $params = request()->all();
  52. if ($result = PaperService::make()->submitError($this->userId, $params)) {
  53. return showJson(PaperService::make()->getError(), true, $result);
  54. } else {
  55. return showJson(PaperService::make()->getError(), false);
  56. }
  57. } catch (\Exception $exception) {
  58. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  59. return message(1003, false, $error);
  60. }
  61. }
  62. }