ExamAnswer.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php namespace App\Http\Controllers\Api\Video;
  2. use App\Http\Controllers\Api\Api;
  3. use App\Models\Video\ExamAnswer as Model;
  4. use App\Models\Video\Answer as VideoAnswer;
  5. use App\Models\Video\Question as VideoQuestion;
  6. /**
  7. * 课程
  8. *
  9. * @author 刘相欣
  10. *
  11. */
  12. class ExamAnswer extends Api{
  13. /**
  14. * 获取答题记录 /api/video_learn_answer/get_list
  15. *
  16. */
  17. public function get_list(Model $Model,VideoQuestion $VideoQuestion,VideoAnswer $VideoAnswer){
  18. // 用户登录
  19. $uid = $this->checkLogin();
  20. // 接收参数
  21. $recordId = request('record_id',0);
  22. // 如果不是课中习题
  23. if( !$recordId ) return json_send(['code'=>'error','msg'=>'请选择评测记录']);
  24. // 查询答题记录
  25. $answerList = $Model->query()
  26. ->where([['custom_uid','=',$uid],['record_id','=',$recordId]])
  27. ->select(['id','record_id','course_id','question_id','answer_id','is_answer','get_score'])
  28. ->get()->toArray();
  29. // 循环答题
  30. foreach ($answerList as $key => $value) {
  31. // 题目标题
  32. $value['question_title']= $VideoQuestion->getOne($value['question_id'],'title');
  33. $value['answer_list'] = $VideoAnswer->getListByQuestion($value['question_id']);
  34. $value['answer_list'] = array_values($value['answer_list']);
  35. // 重组
  36. $answerList[$key] = $value;
  37. }
  38. // 返回结果
  39. return json_send(['code'=>'success','msg'=>'获取成功','data'=>$answerList]);
  40. }
  41. }