Index.php 2.5 KB

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