| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Services\Api\ExamService;
- /**
- * 考试管理
- * @package App\Http\Controllers\Api
- */
- class ExamController extends webApp
- {
- /**
- * 答题记录
- * @return array
- */
- public function index()
- {
- try {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 10);
- $params['user_id'] = $this->userId;
- $datas = ExamService::make()->getDataList($params, $pageSize);
- return message(1010, true, $datas);
- } catch (\Exception $exception) {
- $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
- return message(1009, false, $error);
- }
- }
- /**
- * 答题历史
- * @return array
- */
- public function history()
- {
- try {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 10);
- $params['user_id'] = $this->userId;
- $datas = ExamService::make()->getHistoryList($params, $pageSize);
- return message(1010, true, $datas);
- } catch (\Exception $exception) {
- $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
- return message(1009, false, $error);
- }
- }
- /**
- * 每日一练
- * @return array
- */
- public function practice()
- {
- try {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 10);
- $datas = ExamService::make()->getPracticeList($this->userId, $params, $pageSize);
- return message(1010, true, $datas);
- } catch (\Exception $exception) {
- $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
- return message(1009, false, $error);
- }
- }
- /**
- * 答题
- * @return array
- */
- public function answer()
- {
- try {
- $params = request()->all();
- if ($result = ExamService::make()->answer($this->userId, $params)) {
- return showJson(ExamService::make()->getError(), true, $result);
- } else {
- return showJson(ExamService::make()->getError(), false);
- }
- } catch (\Exception $exception) {
- $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
- return message(1003, false, $error);
- }
- }
- /**
- * 再次答题
- * @return array
- */
- public function reset()
- {
- try {
- $id = request()->post('id');
- if (ExamService::make()->reset($id, $this->userId)) {
- return showJson(1002, true);
- } else {
- return showJson(ExamService::make()->getError(), false);
- }
- } catch (\Exception $exception) {
- $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
- return message(1003, false, $error);
- }
- }
- /**
- * 详情
- */
- public function info()
- {
- try {
- $params = request()->all();
- $rid = isset($params['rid']) ? intval($params['rid']) : 0;
- if (empty($rid)) {
- return message(1036, false);
- }
- if ($info = ExamService::make()->getInfo($rid)) {
- return message(1010, true, $info);
- } else {
- return message(1009, false);
- }
- } catch (\Exception $exception) {
- $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
- return message(1009, false, $error);
- }
- }
- /**
- * 排行榜
- */
- public function ranks()
- {
- try {
- $params = request()->all();
- $type = isset($params['type']) ? intval($params['type']) : 0;
- if (empty($type)) {
- return message(1031, false);
- }
- $datas = ExamService::make()->getRankByType($type);
- return message(1010, true, $datas);
- } catch (\Exception $exception) {
- $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
- return message(1009, false, $error);
- }
- }
- /**
- * 答题卡数据
- */
- public function cards()
- {
- try {
- $params = request()->all();
- $rid = isset($params['rid']) ? intval($params['rid']) : 0;
- $paperId = isset($params['id']) ? intval($params['id']) : 0;
- if (empty($paperId)) {
- return message(1031, false);
- }
- $datas = ExamService::make()->getCardList($this->userId, $paperId, $rid);
- return message(1010, true, $datas);
- } catch (\Exception $exception) {
- $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
- return message(1009, false, $error);
- }
- }
- }
|