修改用户的状态判断

dev_course
SylorHuang 6 years ago
parent 9034e1a534
commit ff3e34510e

@ -94,28 +94,39 @@ class ExerciseAnswersController < ApplicationController
def get_exercise_question
@exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id])
@exercise = @exercise_question.exercise
@course = @exercise.course
@exercise_user = @exercise.exercise_users.find_by(user_id: current_user.id) #当前用户
@exercise = @exercise_question&.exercise
@course = @exercise&.course
@exercise_user = @exercise&.exercise_users.find_by(user_id: current_user.id) #当前用户
@exercise_user_status = @exercise.get_exercise_status(current_user.id)
if @exercise_question.blank?
normal_status(-1,"试卷问题不存在!")
elsif @exercise.blank?
normal_status(-1,"试卷不存在!")
elsif @course.blank?
normal_status(-1,"该课堂不存在!")
elsif (@exercise_user.present? && @exercise_user&.commit_status == 1) || @exercise_user_status == 3 #已提交答案的/时间已结束的试卷不允许再修改
elsif @exercise_user.blank?
normal_status(-1,"试卷用户不存在!")
elsif @exercise_user_status == 3 || @exercise_user.commit_status == 1
normal_status(-1,"已提交/已结束的试卷不允许修改!")
elsif @exercise.time > 0
user_start_at = @exercise_user&.start_at
exercise_time = @exercise.time.to_i + 1 #
if (user_start_at + exercise_time.minutes) < Time.now
normal_status(-1,"限时试卷已结束!")
else
if @exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)
objective_score = calculate_student_score(@exercise,current_user)[:total_score]
subjective_score = @exercise_user.subjective_score < 0.0 ? 0.0 : @exercise_user.subjective_score
total_score = objective_score + subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => objective_score,
:score => total_score,
:subjective_score => subjective_score
}
@exercise_user.update_attributes(commit_option)
normal_status(-1,"试卷提交时间已截止!")
end
end
end
end

Loading…
Cancel
Save