Index.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['index'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 首页
  14. *
  15. */
  16. public function index()
  17. {
  18. //热门试卷列表
  19. $now = time();
  20. $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time')
  21. ->where('status', 'NORMAL')
  22. ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
  23. // ->where('find_in_set(:user_ids,user_ids)', ['user_ids' => $this->auth->id])
  24. ->limit(3)
  25. ->select();
  26. foreach($papers as $key => &$val){
  27. $val['image'] = localpath_to_netpath($val['image']);
  28. $val['limit_time'] = $val['limit_time']/60; //秒转换分种
  29. $val['is_start'] = 1;
  30. }
  31. $this->success('', $papers);
  32. }
  33. //在线考试
  34. //我的考试
  35. //可参加考试
  36. //我的试卷
  37. public function my_paper_list(){
  38. $now = time();
  39. $papers = Db::name('exam_paper')->field('id,title,start_time,end_time,total_score,limit_time')
  40. ->where('status', 'NORMAL')
  41. ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
  42. ->where('find_in_set(:user_ids,user_ids)', ['user_ids' => $this->auth->id])
  43. ->autopage()
  44. ->select();
  45. foreach($papers as $key => &$val){
  46. $val['limit_time'] = $val['limit_time']/60; //秒转换分种
  47. $val['is_start'] = 1;
  48. }
  49. $this->success('', $papers);
  50. }
  51. //历史考试
  52. public function my_grade_list(){
  53. $field = [
  54. 'grade.score','grade.is_pass','grade.total_score',
  55. 'grade.total_count','grade.right_count','grade.error_count',
  56. 'grade.grade_time','grade.start_time',
  57. 'paper.title'
  58. ];
  59. $list = Db::name('exam_grade')->alias('grade')
  60. ->join('exam_paper paper','grade.paper_id = paper.id','LEFT')
  61. ->field($field)
  62. ->where('grade.user_id',$this->auth->id)
  63. ->autopage()
  64. ->select();
  65. foreach($list as $key => &$val){
  66. $val['grade_time_text'] = Sec2Time($val['grade_time']);
  67. }
  68. $this->success('', $list);
  69. }
  70. }