Index.php 6.1 KB

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