From 89e00b687929269c4ba3c57793fa8366c2ef8e0e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 12 Mar 2020 22:02:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E7=A7=BB=E4=B8=8B=E7=A7=BB=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 33 +++++++++++++++++------- app/models/challenge.rb | 4 +-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index e73243b94..762943183 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -287,21 +287,34 @@ class ChallengesController < ApplicationController def index_down next_challenge = @challenge.next_challenge position = @challenge.position - @challenge.update_attribute(:position, (position + 1)) - next_challenge.update_attribute(:position, next_challenge.position - 1) - # 关卡位置被修改,需要修改脚本 - script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.shixun_info.update_column(:evaluate_script, script) + begin + ActiveRecord::Base.transaction do + @challenge.update_attributes!(position: (position + 1)) + next_challenge.update_attributes!(position: next_challenge.position - 1) + # 关卡位置被修改,需要修改脚本 + script = modify_shixun_script @shixun, @shixun.evaluate_script + @shixun.shixun_info.update_attributes!(evaluate_script: script) + end + rescue => e + tip_exception("下移失败: #{e.message}") + end end def index_up position = @challenge.position last_challenge = @challenge.last_challenge - @challenge.update_attribute(:position, (position - 1)) - last_challenge.update_attribute(:position, last_challenge.position + 1) - # 关卡位置被修改,需要修改脚本 - script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.shixun_info.update_column(:evaluate_script, script) + begin + ActiveRecord::Base.transaction do + @challenge.update_attribute(:position, (position - 1)) + last_challenge.update_attribute(:position, last_challenge.position + 1) + # 关卡位置被修改,需要修改脚本 + script = modify_shixun_script @shixun, @shixun.evaluate_script + @shixun.shixun_info.update_column(:evaluate_script, script) + end + rescue => e + tip_exception("上移失败: #{e.message}") + end + end def destroy diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 38aa2812a..44cd8574c 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -69,13 +69,13 @@ class Challenge < ApplicationRecord end # 开启挑战 - def open_game shixun + def open_game shixun, position # 这里的identifier,status是关联了games取了games的identifier,status identifier = self.identifier if identifier.present? shixun.task_pass || self.status != 3 ? "/tasks/#{identifier}" : "" else - self.position == 1 ? "/shixuns/#{shixun.identifier}/shixun_exec.json" : "" + position == 1 ? "/shixuns/#{shixun.identifier}/shixun_exec.json" : "" end end