Index.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 = ['*'];
  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. ->where('index_status', 1)
  23. ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
  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. }
  30. $this->success('', $papers);
  31. }
  32. //在线考试
  33. //我的考试
  34. //可参加考试
  35. //我的试卷
  36. public function my_paper_list(){
  37. $now = time();
  38. $papers = Db::name('exam_paper')->field('id,title,start_time,end_time,total_score,limit_time')
  39. ->where('status', 'NORMAL')
  40. ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
  41. ->autopage()
  42. ->select();
  43. foreach($papers as $key => &$val){
  44. $val['limit_time'] = $val['limit_time']/60; //秒转换分种
  45. $val['is_start'] = 1;
  46. }
  47. $this->success('', $papers);
  48. }
  49. //历史考试
  50. public function my_grade_list(){
  51. $field = [
  52. 'grade.score','grade.is_pass','grade.total_score',
  53. 'grade.total_count','grade.right_count','grade.error_count',
  54. 'grade.grade_time','grade.start_time',
  55. 'paper.title'
  56. ];
  57. $list = Db::name('exam_grade')->alias('grade')
  58. ->join('exam_paper paper','grade.paper_id = paper.id','LEFT')
  59. ->field($field)
  60. ->where('grade.user_id',$this->auth->id)
  61. ->autopage()
  62. ->select();
  63. foreach($list as $key => &$val){
  64. $val['grade_time_text'] = Sec2Time($val['grade_time']);
  65. }
  66. $this->success('', $list);
  67. }
  68. }