LearnQuestion.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php namespace App\Http\Controllers\Api\Video;
  2. use App\Http\Controllers\Api\Api;
  3. use App\Models\Video\Answer as VideoAnswer;
  4. use App\Models\Video\Question as VideoQuestion;
  5. use App\Models\Video\LearnQuestion as Model;
  6. /**
  7. * 课程
  8. *
  9. * @author 刘相欣
  10. *
  11. */
  12. class LearnQuestion extends Api{
  13. /**
  14. * 获取习题列表 /api/video_learn_question/get_list
  15. *
  16. */
  17. public function get_list(Model $Model,VideoQuestion $VideoQuestion,VideoAnswer $VideoAnswer){
  18. // 用户登录
  19. $uid = $this->checkLogin();
  20. // 接收参数
  21. $courseId = request('course_id',0);
  22. // 查询课程数据
  23. $questionList = $Model->query()->where([['course_id','=',$courseId],['status','=',0]])->orderBy('play_time')->select(['question_id','play_time'])->get()->toArray();
  24. // 获取数据
  25. foreach ($questionList as $key => $value) {
  26. # 获取习题数据
  27. $value['question_title']= $VideoQuestion->getOne($value['question_id'],'title');
  28. $value['answer_list'] = $VideoAnswer->getListByQuestion($value['question_id']);
  29. $value['answer_list'] = array_values($value['answer_list']);
  30. // 如果没有题目选项,删除
  31. if( !$value['answer_list'] ){
  32. // 如果没有题目选项,删除
  33. unset($questionList[$key]);
  34. continue;
  35. }
  36. // 重组
  37. $questionList[$key] = $value;
  38. }
  39. // 习题列表
  40. $questionList = array_values($questionList);
  41. // 返回结果
  42. return json_send(['code'=>'success','msg'=>'暂无','data'=>$questionList]);
  43. }
  44. }