Index.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. * 热门试卷3个
  15. * 未开始的 + 进行中的
  16. */
  17. public function index()
  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. ->whereRaw("((end_time = 0) or (end_time > {$now}))")
  25. // ->where('find_in_set(:user_ids,user_ids)', ['user_ids' => $this->auth->id])
  26. ->limit(3)
  27. ->select();
  28. foreach($papers as $key => &$val){
  29. $val['image'] = localpath_to_netpath($val['image']);
  30. $val['limit_time'] = $val['limit_time']/60; //秒转换分种
  31. $val['is_start'] = 1;
  32. }
  33. $this->success('', $papers);
  34. }
  35. /**
  36. * 首页
  37. * 全部培训3个
  38. * 未开始的 + 进行中的
  39. */
  40. public function index_trainactive(){
  41. $now = time();
  42. $lists = Db::name('train_active')->field('id,title,logo_image,starttime,endtime')
  43. ->where('status', 1)
  44. ->where('deletetime', NULL)
  45. ->whereRaw("((endtime = 0) or (endtime > {$now}))")
  46. //->where("(userauth_status = 1) or (find_in_set('".$this->auth->id."',user_ids) )")
  47. ->limit(3)
  48. ->select();
  49. foreach($lists as $key => &$val){
  50. $val['image'] = localpath_to_netpath($val['logo_image']);
  51. if($now < $val['starttime']){
  52. $val['show_status'] = 1;
  53. $val['show_status_text'] = '待开始';
  54. }
  55. if($val['starttime'] < $now && $now < $val['endtime']){
  56. $val['show_status'] = 2;
  57. $val['show_status_text'] = '进行中';
  58. }
  59. if($val['endtime'] < $now){
  60. $val['show_status'] = 3;
  61. $val['show_status_text'] = '已结束';
  62. }
  63. }
  64. $this->success('', $lists);
  65. }
  66. //考试,更多,所有考试列表
  67. public function all_paper_list(){
  68. $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time')
  69. ->where('status', 'NORMAL')
  70. ->where('deletetime', NULL)
  71. ->autopage()
  72. ->select();
  73. foreach($papers as $key => &$val){
  74. $val['image'] = localpath_to_netpath($val['image']);
  75. $val['limit_time'] = $val['limit_time']/60; //秒转换分种
  76. $val['is_start'] = 1;
  77. }
  78. $this->success('', $papers);
  79. }
  80. //在线考试
  81. //我的考试
  82. //可参加考试
  83. //我的试卷
  84. public function my_paper_list(){
  85. $now = time();
  86. $papers = Db::name('exam_paper')->field('id,title,start_time,end_time,total_score,limit_time')
  87. ->where('status', 'NORMAL')
  88. ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
  89. ->where('find_in_set(:user_ids,user_ids)', ['user_ids' => $this->auth->id])
  90. ->where('deletetime', NULL)
  91. ->autopage()
  92. ->select();
  93. foreach($papers as $key => &$val){
  94. $val['limit_time'] = $val['limit_time']/60; //秒转换分种
  95. $val['is_start'] = 1;
  96. }
  97. $this->success('', $papers);
  98. }
  99. //历史考试
  100. public function my_grade_list(){
  101. $field = [
  102. 'grade.score','grade.is_pass','grade.total_score',
  103. 'grade.total_count','grade.right_count','grade.error_count',
  104. 'grade.grade_time','grade.start_time',
  105. 'paper.title'
  106. ];
  107. $list = Db::name('exam_grade')->alias('grade')
  108. ->join('exam_paper paper','grade.paper_id = paper.id','LEFT')
  109. ->field($field)
  110. ->where('grade.user_id',$this->auth->id)
  111. ->autopage()
  112. ->select();
  113. foreach($list as $key => &$val){
  114. $val['grade_time_text'] = Sec2Time($val['grade_time']);
  115. }
  116. $this->success('', $list);
  117. }
  118. }