field('id,image,title,start_time,end_time,total_score,limit_time,user_ids') ->where('status', 'NORMAL') ->where('deletetime', NULL) // ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))") ->whereRaw("((end_time = 0) or (end_time > {$now}))") // ->where('find_in_set(:user_ids,user_ids)', ['user_ids' => $this->auth->id]) ->limit(3) ->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); } /** * 首页 * 全部培训3个 * 未开始的 + 进行中的 */ public function index_trainactive(){ $now = time(); $lists = Db::name('train_active')->field('id,title,logo_image,starttime,endtime,pingjia_time,pingjia_uid') ->where('status', 1) ->where('deletetime', NULL) ->whereRaw("((endtime = 0) or (endtime > {$now}))") //->where("(userauth_status = 1) or (find_in_set('".$this->auth->id."',user_ids) )") ->limit(3) ->order('starttime desc') ->select(); foreach($lists as $key => &$val){ $val['logo_image'] = localpath_to_netpath($val['logo_image']); if($now < $val['starttime']){ $val['show_status'] = 1; $val['show_status_text'] = '待开始'; } if($val['starttime'] < $now && $now < $val['endtime']){ $val['show_status'] = 2; $val['show_status_text'] = '进行中'; } if(/*$val['endtime'] < $now || */$val['pingjia_uid'] != 0){ //时间或评价,都行 $val['show_status'] = 3; $val['show_status_text'] = '已结束'; } } $this->success('', $lists); } //考试,更多,所有考试列表 public function all_paper_list(){ $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time') ->where('status', 'NORMAL') ->where('deletetime', NULL) ->autopage() ->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 all_trainactive_list(){ $type = input('type',1); $now = time(); $where = []; if($type == 1){ $where['starttime'] = ['gt',$now]; } if($type == 2){ $where['starttime'] = ['lt',$now]; $where['endtime'] = ['gt',$now]; } if($type == 3){ // $where = 'endtime < '.$now.' or pingjia_time > 0'; $where['pingjia_uid'] = ['NEQ',0]; } $papers = Db::name('train_active')->field('id,title,logo_image,starttime,endtime,pingjia_time,pingjia_uid') ->where('status', 1) ->where('deletetime', NULL) ->where($where) ->autopage() ->order('starttime desc') ->select(); foreach($papers as $key => &$val){ $val['logo_image'] = localpath_to_netpath($val['logo_image']); if($now < $val['starttime']){ $val['show_status'] = 1; $val['show_status_text'] = '待开始'; } if($val['starttime'] < $now && $now < $val['endtime']){ $val['show_status'] = 2; $val['show_status_text'] = '进行中'; } if(/*$val['endtime'] < $now || */$val['pingjia_uid'] != 0){ //时间或评价,都行 $val['show_status'] = 3; $val['show_status_text'] = '已结束'; } } $this->success(1, $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]) ->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) ->autopage() ->select(); foreach($list as $key => &$val){ $val['grade_time_text'] = Sec2Time($val['grade_time']); } $this->success('', $list); } }