Index.php 6.8 KB

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