...
|
...
|
@@ -132,6 +132,7 @@ class Exam extends Api |
|
|
$third_exam = Db::name('third_exam')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$study_id)
|
|
|
->whereTime('createtime','month')
|
|
|
->order('exam_num desc')
|
|
|
->find();
|
|
|
if(empty($third_exam)){
|
...
|
...
|
@@ -144,7 +145,8 @@ class Exam extends Api |
|
|
$info['third_exam_id'] = Db::name('third_exam')->insertGetId($exam);
|
|
|
}else{
|
|
|
if($third_exam['exam_num'] == 3){
|
|
|
$this->error('您已经考过三次了');
|
|
|
// $this->error('您已经考过三次了');
|
|
|
$this->error('您本月已经考过三次了');
|
|
|
}
|
|
|
$study = Db::name('study')->where('id',$study_id)->find();
|
|
|
$where_exam = [
|
...
|
...
|
@@ -152,8 +154,12 @@ class Exam extends Api |
|
|
'study_id' => $study_id,
|
|
|
'score' => ['egt',$study['pass_mark']]
|
|
|
];
|
|
|
$third_exam_pass = Db::name('third_exam')->where($where_exam)->find();
|
|
|
if($third_exam_pass) $this->error('已通过该考试');
|
|
|
$third_exam_pass = Db::name('third_exam')
|
|
|
->where($where_exam)
|
|
|
->whereTime('createtime','year')
|
|
|
->find();
|
|
|
// if($third_exam_pass) $this->error('已通过该考试');
|
|
|
if($third_exam_pass) $this->error('今年已通过该考试');
|
|
|
$exam['user_id'] = $user_id;
|
|
|
$exam['study_id'] = $study_id;
|
|
|
$exam['exam_num'] = $third_exam['exam_num'] + 1;
|
...
|
...
|
@@ -169,7 +175,12 @@ class Exam extends Api |
|
|
->find();
|
|
|
|
|
|
//判断第几次考试
|
|
|
$is_have = Db::name('answer_detail')->where('user_id',$user_id)->where('study_id',$study_id)->order('id desc')->find();
|
|
|
$is_have = Db::name('answer_detail')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$study_id)
|
|
|
->whereTime('createtime','month')
|
|
|
->order('id desc')
|
|
|
->find();
|
|
|
|
|
|
//添加用户考试记录详情表中
|
|
|
$answer['user_id'] = $user_id;
|
...
|
...
|
@@ -292,11 +303,12 @@ class Exam extends Api |
|
|
$third_exam = Db::name('third_exam')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$study_id)
|
|
|
->whereTime('createtime','month')
|
|
|
->order('exam_num desc')
|
|
|
->find();
|
|
|
if($third_exam['exam_num'] == 3){
|
|
|
$this->error('您已经考过三次了');
|
|
|
// $this->success('success');
|
|
|
// $this->error('您已经考过三次了');
|
|
|
$this->error('您本月已经考过三次了');
|
|
|
}else{
|
|
|
$this->success('success');
|
|
|
}
|
...
|
...
|
@@ -331,6 +343,7 @@ class Exam extends Api |
|
|
*
|
|
|
* @ApiHeaders (name="token", type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="study_id", type="int", required=true, description="学习系统id")
|
|
|
* @ApiParams (name="month", type="string", required=false, description="月份")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
...
|
...
|
@@ -354,10 +367,23 @@ class Exam extends Api |
|
|
{
|
|
|
$user_id = $this->auth->id;
|
|
|
$study_id = $this->request->param('study_id');
|
|
|
$month = $this->request->param('month');
|
|
|
if(empty($study_id)){
|
|
|
$this->error('缺少必要参数');
|
|
|
}
|
|
|
|
|
|
if(empty($month)){
|
|
|
$starttime = strtotime(date('Y-m'));
|
|
|
$time = [
|
|
|
$starttime,
|
|
|
strtotime('+1 month',$starttime)
|
|
|
];
|
|
|
}else{
|
|
|
$starttime = strtotime($month);
|
|
|
$time = [
|
|
|
strtotime($month),
|
|
|
strtotime('+1 month',$starttime)
|
|
|
];
|
|
|
}
|
|
|
$study = Db::name('study')
|
|
|
->where('id',$study_id)
|
|
|
->field('id,examname,pass_mark')
|
...
|
...
|
@@ -367,6 +393,7 @@ class Exam extends Api |
|
|
$data['record'] = Db::name('third_exam')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$study_id)
|
|
|
->where('createtime','between',$time)
|
|
|
->order('exam_num')
|
|
|
->field('id,exam_num,score,createtime')
|
|
|
->select();
|
...
|
...
|
@@ -441,6 +468,7 @@ class Exam extends Api |
|
|
->where('type',1)
|
|
|
->where('question_id',$question_id)
|
|
|
->where('study_exam_num',$study_exam_num)
|
|
|
->whereTime('createtime','month')
|
|
|
->find();
|
|
|
if(empty($data)){
|
|
|
$this->error('参数有误');
|
...
|
...
|
@@ -460,9 +488,15 @@ class Exam extends Api |
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$study_id)
|
|
|
->where('study_exam_num',$study_exam_num)
|
|
|
->whereTime('createtime','month')
|
|
|
->field('sum(score) as num')
|
|
|
->find();
|
|
|
Db::name('third_exam')->where('user_id',$user_id)->where('study_id',$study_id)->where('exam_num',$study_exam_num)->update(['score'=>$score['num']]);
|
|
|
Db::name('third_exam')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$study_id)
|
|
|
->where('exam_num',$study_exam_num)
|
|
|
->wherTime('createtime','month')
|
|
|
->update(['score'=>$score['num']]);
|
|
|
}
|
|
|
}elseif ($type == 2){
|
|
|
//查询出该条题目详情
|
...
|
...
|
@@ -472,6 +506,7 @@ class Exam extends Api |
|
|
->where('type',2)
|
|
|
->where('question_id',$question_id)
|
|
|
->where('study_exam_num',$study_exam_num)
|
|
|
->wherTime('createtime','month')
|
|
|
->find();
|
|
|
if(empty($data)){
|
|
|
$this->error('参数有误');
|
...
|
...
|
@@ -504,8 +539,14 @@ class Exam extends Api |
|
|
->where('study_id',$study_id)
|
|
|
->where('study_exam_num',$study_exam_num)
|
|
|
->field('sum(score) as num')
|
|
|
->wherTime('createtime','month')
|
|
|
->find();
|
|
|
Db::name('third_exam')->where('user_id',$user_id)->where('study_id',$study_id)->where('exam_num',$study_exam_num)->update(['score'=>$score['num']]);
|
|
|
Db::name('third_exam')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$study_id)
|
|
|
->where('exam_num',$study_exam_num)
|
|
|
->wherTime('createtime','month')
|
|
|
->update(['score'=>$score['num']]);
|
|
|
}
|
|
|
}elseif ($type == 3){
|
|
|
//查询出该条题目详情
|
...
|
...
|
@@ -515,6 +556,7 @@ class Exam extends Api |
|
|
->where('type',3)
|
|
|
->where('question_id',$question_id)
|
|
|
->where('study_exam_num',$study_exam_num)
|
|
|
->wherTime('createtime','month')
|
|
|
->find();
|
|
|
if(empty($data)){
|
|
|
$this->error('参数有误');
|
...
|
...
|
@@ -534,9 +576,15 @@ class Exam extends Api |
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$study_id)
|
|
|
->where('study_exam_num',$study_exam_num)
|
|
|
->wherTime('createtime','month')
|
|
|
->field('sum(score) as num')
|
|
|
->find();
|
|
|
Db::name('third_exam')->where('user_id',$user_id)->where('study_id',$study_id)->where('exam_num',$study_exam_num)->update(['score'=>$score['num']]);
|
|
|
Db::name('third_exam')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$study_id)
|
|
|
->where('exam_num',$study_exam_num)
|
|
|
->wherTime('createtime','month')
|
|
|
->update(['score'=>$score['num']]);
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|