From b6ccd6562cc18fb81e3405541ebfb7c375d9fcf3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 16:27:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E7=AD=94=E6=A1=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 38 +++++++++---------- app/views/games/get_answer_info.json.jbuilder | 28 +++++--------- app/views/games/unlock_answer.json.jbuilder | 6 ++- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 0142ef2ba..eea4e4dc0 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -225,18 +225,8 @@ class GamesController < ApplicationController # GET: /tasks/:identifier/get_answer_info # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 def get_answer_info - @challenge = @game.challenge - if @challenge.st == 0 - @challenge_answers = @challenge.challenge_answers - else - result = [] - @challenge.challenge_chooses.each do |choose| - result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} - end - @challenge_answers = result - end - - + challenge = @game.challenge + @challenge_answers = challenge.challenge_answers # 平台已认证的老师需要控制 @power = (@identity < User::EDU_GAME_MANAGER) if !@power @@ -259,14 +249,22 @@ class GamesController < ApplicationController # 解锁答案 # GET: /tasks/:identifier/get_answer_info?answer_id=? def unlock_answer - @answer = ChallengeAnswer.find(params[:answer_id]) - challenge = @answer.challenge - # 解锁需要本层级的答案是否需要扣分 - points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) - deduct_score = ((points / 100.0) * challenge.score).to_i - uid_logger("############金币数目: #{current_user.grade}") - unless current_user.grade.to_i - deduct_score > 0 - tip_exception("您没有足够的金币") + @challenge = @game.challenge + if @challenge.st == 0 + @answer = ChallengeAnswer.find(params[:answer_id]) + challenge = @answer.challenge + # 解锁需要本层级的答案是否需要扣分 + points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) + deduct_score = ((points / 100.0) * challenge.score).to_i + uid_logger("############金币数目: #{current_user.grade}") + unless current_user.grade.to_i - deduct_score > 0 + tip_exception("您没有足够的金币") + end + else + @answer = [] + @challenge.challenge_chooses.each do |choose| + @answer << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} + end end ActiveRecord::Base.transaction do diff --git a/app/views/games/get_answer_info.json.jbuilder b/app/views/games/get_answer_info.json.jbuilder index 57b180816..0f150d500 100644 --- a/app/views/games/get_answer_info.json.jbuilder +++ b/app/views/games/get_answer_info.json.jbuilder @@ -1,26 +1,18 @@ index = 0 json.status 3 # st: 0 实践题 1 选择题 -if @challenge.st == 0 - json.message do - json.array! @challenge_answers do |answer| - index += 1 - json.answer_id answer.id - json.answer_name answer.name - json.answer_score answer.score - # 高层级不给答案 - if @power || @game.answer_open >= index - json.answer_contents answer.contents - end - end - end -else - json.message do - json.array! @challenge_answers do |answer| - json.position answer[:postion] - json.answer_contents answer[:answer] +json.message do + json.array! @challenge_answers do |answer| + index += 1 + json.answer_id answer.id + json.answer_name answer.name + json.answer_score answer.score + # 高层级不给答案 + if @power || @game.answer_open >= index + json.answer_contents answer.contents end end end + diff --git a/app/views/games/unlock_answer.json.jbuilder b/app/views/games/unlock_answer.json.jbuilder index 71018c7be..9776fde46 100644 --- a/app/views/games/unlock_answer.json.jbuilder +++ b/app/views/games/unlock_answer.json.jbuilder @@ -1 +1,5 @@ -json.contents @answer.contents \ No newline at end of file +if @challenge.st == 0 + json.contents @answer.contents +else + json.contents @answer +end