Index.php 7.0 KB

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