Index.php 5.4 KB

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