VideoExamAnswer.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Models\Custom;
  3. use App\Models\Video\ExamAnswer as Model;
  4. use App\Models\Video\Course as VideoCourse;
  5. use App\Models\Video\Answer as VideoAnswer;
  6. use App\Models\Video\Question as VideoQuestion;
  7. /**
  8. * 学习记录
  9. *
  10. * @author 刘相欣
  11. *
  12. */
  13. class VideoExamAnswer extends Auth{
  14. protected function _initialize(){
  15. parent::_initialize();
  16. $this->assign('breadcrumb1','课后评测');
  17. $this->assign('breadcrumb2','答题记录');
  18. }
  19. /**
  20. * 列表页
  21. *
  22. * */
  23. public function index(Model $Model,VideoCourse $VideoCourse,Custom $Custom,VideoQuestion $VideoQuestion,VideoAnswer $VideoAnswer){
  24. // 接收参数
  25. $recordId = request('record_id',0);
  26. $courseId = request('course_id',0);
  27. $customCode = request('custom_code','');
  28. $customName = request('custom_name','');
  29. // 转码
  30. $customCode = $Custom->codeToId($customCode);
  31. // 查询条件
  32. $map = [];
  33. // 组合条件
  34. if( $courseId ) $map[] = ['video_course.id','=',$courseId];
  35. if( $recordId ) $map[] = ['video_exam_answer.record_id','=',$recordId];
  36. if( $customCode ) $map[] = ['custom.uid','=',$customCode];
  37. if( $customName ) $map[] = ['custom.username','LIKE','%'.$customName.'%'];
  38. // 查询数据
  39. $list = $Model->query()
  40. ->join('video_course','video_course.id','=','video_exam_answer.course_id')
  41. ->join('custom','custom.uid','=','video_exam_answer.custom_uid')
  42. ->where($map)->select(['video_exam_answer.*','video_course.name as course_name','custom.username as custom_name'])
  43. ->orderByDesc('id')->paginate(config('page_num',10));
  44. // 循环处理数据
  45. foreach ($list as $key => $value) {
  46. // 时间
  47. $value['custom_code'] = $Custom->idToCode($value['custom_uid']);
  48. $value['question_title']= $VideoQuestion->getOne($value['question_id'],'title');
  49. $value['answer_list'] = $VideoAnswer->getListByQuestion($value['question_id']);
  50. $value['answer_list'] = array_values($value['answer_list']);
  51. // 重组
  52. $list[$key] = $value;
  53. }
  54. // 查询数据
  55. $courseList = $VideoCourse->query()->orderByDesc('id')->get(['id','name']);
  56. // 分配数据
  57. $this->assign('list',$list);
  58. $this->assign('courseList',$courseList);
  59. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  60. // 加载模板
  61. return $this->fetch();
  62. }
  63. }