123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 首页接口
- */
- class Index extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- //热门试卷列表
- $now = time();
- $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time')
- ->where('status', 'NORMAL')
- ->where('index_status', 1)
- ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
- ->limit(3)
- ->select();
- foreach($papers as $key => &$val){
- $val['image'] = localpath_to_netpath($val['image']);
- $val['limit_time'] = $val['limit_time']/60; //秒转换分种
- $val['is_start'] = 1;
- }
- $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')
- ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
- ->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);
- }
- }
|