From d5cdca31c9ba561a1e995caa08b01eb39d48fd3f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 7 May 2019 12:26:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/account_controller.rb | 14 ++++++++++++++ app/controllers/exercise_controller.rb | 2 ++ 2 files changed, 16 insertions(+) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index d58b9bdf..88c435a6 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -949,6 +949,20 @@ class AccountController < ApplicationController if @se.identity == 0 && @user.certification == 1 join_ex_course @user end + + if @user.certification != 1 && @se.identity == 1 + school_ids = School.where(:auto_users_trial => 1).map(&:id) + # 授权单位中的只有学生身份才自动授权,且创建试用授权记录 + if !@se.school.nil? && school_ids.include?(@se.school_id) + @user.update_attributes(:certification => 1) + apply_action = ApplyAction.where(:user_id => @user.id, :container_type => "TrialAuthorization", :status => 0).first + if apply_action.present? + apply_action.update_attributes(:status => 1, :noticed => 1) + else + ApplyAction.create(:user_id => @user.id, :container_type => "TrialAuthorization", :ip_addr => request.remote_ip, :status => 1, :noticed => 1) + end + end + end end redirect_to my_account_path end diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 07234e17..96faa005 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1375,6 +1375,8 @@ class ExerciseController < ApplicationController @exercise.exercise_users.where(:user_id => params[:user_id]).update_all(:score => nil, :start_at => nil, :end_at => nil, :status => nil, :commit_status => 0, :objective_score => -1, :subjective_score => -1) ExerciseAnswer.where(:user_id => params[:user_id], :exercise_question_id => @exercise.exercise_questions.pluck(:id)).destroy_all ExerciseShixunAnswer.where(:user_id => params[:user_id], :exercise_question_id => @exercise.exercise_questions.pluck(:id)).destroy_all + ExerciseUserQuestion.where(:exercise_id => @exercise.id, :exercise_user_id => + @exercise.exercise_users.where(:user_id => params[:user_id]).pluck(:id)).destroy_all end redirect_to student_exercise_list_exercise_path(@exercise) end