|
@@ -12,122 +12,6 @@ class Index extends Api
|
|
|
protected $noNeedLogin = ['index'];
|
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
- /**
|
|
|
- * 首页
|
|
|
- * 热门试卷3个
|
|
|
- * 未开始的 + 进行中的
|
|
|
- * 我能参与的
|
|
|
- */
|
|
|
- public function index()
|
|
|
- {
|
|
|
- $now = time();
|
|
|
-
|
|
|
-
|
|
|
- $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time,user_ids')
|
|
|
- ->where('status', 'NORMAL')
|
|
|
- ->where('deletetime', NULL)
|
|
|
- ->whereRaw("((end_time = 0) or (end_time > {$now}))")
|
|
|
-
|
|
|
- ->limit(2)
|
|
|
- ->order('start_time desc')
|
|
|
- ->select();
|
|
|
-
|
|
|
- if(empty($papers)){
|
|
|
- $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time,user_ids')
|
|
|
- ->where('status', 'NORMAL')
|
|
|
- ->where('deletetime', NULL)
|
|
|
- ->limit(2)
|
|
|
- ->order('start_time desc')
|
|
|
- ->select();
|
|
|
- }
|
|
|
-
|
|
|
- foreach($papers as $key => &$val){
|
|
|
- $val['image'] = localpath_to_netpath($val['image']);
|
|
|
- $val['limit_time'] = $val['limit_time']/60; //秒转换分种
|
|
|
- $val['is_start'] = 0;
|
|
|
-
|
|
|
- if($val['start_time'] < $now && $now < $val['end_time'] && in_array($this->auth->id,explode(',',$val['user_ids'])) ){
|
|
|
- $val['is_start'] = 1;
|
|
|
- }
|
|
|
-
|
|
|
- unset($val['user_ids']);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- $this->success('', $papers);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //考试,更多,所有考试列表
|
|
|
- public function all_paper_list(){
|
|
|
-
|
|
|
- //非实名,只能看一部分
|
|
|
- $where_auth = "";
|
|
|
- if($this->auth->idcard_status != 1){
|
|
|
- $where_auth = "(find_in_set('".$this->auth->id."',user_ids) )";
|
|
|
- }
|
|
|
-
|
|
|
- $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time')
|
|
|
- ->where('status', 'NORMAL')
|
|
|
- ->where('deletetime', NULL)
|
|
|
- ->where($where_auth)
|
|
|
- ->autopage()
|
|
|
- ->order('start_time desc')
|
|
|
- ->select();
|
|
|
-
|
|
|
- foreach($papers as $key => &$val){
|
|
|
- $val['image'] = localpath_to_netpath($val['image']);
|
|
|
- $val['limit_time'] = $val['limit_time']/60; //秒转换分种
|
|
|
- }
|
|
|
-
|
|
|
- $this->success('', $papers);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //在线考试
|
|
|
- //我的考试
|
|
|
- //可参加考试
|
|
|
- //我的试卷
|
|
|
- public function my_paper_list(){
|
|
|
- $now = time();
|
|
|
- $papers = Db::name('exam_paper')->field('id,title,start_time,end_time,total_score,limit_time')
|
|
|
- ->where('status', 'NORMAL')
|
|
|
- ->where('deletetime', NULL)
|
|
|
- ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
|
|
|
- ->where('find_in_set(:user_ids,user_ids)', ['user_ids' => $this->auth->id])
|
|
|
- ->order('start_time desc')
|
|
|
- ->autopage()
|
|
|
- ->select();
|
|
|
-
|
|
|
- foreach($papers as $key => &$val){
|
|
|
- $val['limit_time'] = $val['limit_time']/60; //秒转换分种
|
|
|
- $val['is_start'] = 1;
|
|
|
- }
|
|
|
-
|
|
|
- $this->success('', $papers);
|
|
|
- }
|
|
|
-
|
|
|
- //历史考试
|
|
|
- public function my_grade_list(){
|
|
|
- $field = [
|
|
|
- 'grade.score','grade.is_pass','grade.total_score',
|
|
|
- 'grade.total_count','grade.right_count','grade.error_count',
|
|
|
- 'grade.grade_time','grade.start_time',
|
|
|
- 'paper.title'
|
|
|
- ];
|
|
|
- $list = Db::name('exam_grade')->alias('grade')
|
|
|
- ->join('exam_paper paper','grade.paper_id = paper.id','LEFT')
|
|
|
- ->field($field)
|
|
|
- ->where('grade.user_id',$this->auth->id)
|
|
|
- ->order('grade.id desc')
|
|
|
- ->autopage()
|
|
|
- ->select();
|
|
|
- foreach($list as $key => &$val){
|
|
|
- $val['grade_time_text'] = Sec2Time($val['grade_time']);
|
|
|
- }
|
|
|
-
|
|
|
- $this->success('', $list);
|
|
|
- }
|
|
|
|
|
|
|
|
|
}
|