|
|
|
@ -221,12 +221,12 @@ class GamesController < ApplicationController
|
|
|
|
|
@result = challenge.st == 0 ? challenge.try(:answer) : challenge.choose_answer
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取答案
|
|
|
|
|
# 获取实践题答案
|
|
|
|
|
# GET: /tasks/:identifier/get_answer_info
|
|
|
|
|
# 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框
|
|
|
|
|
def get_answer_info
|
|
|
|
|
challenge = @game.challenge
|
|
|
|
|
@challenge_answers = challenge.challenge_answers
|
|
|
|
|
@challenge = @game.challenge
|
|
|
|
|
@challenge_answers = @challenge.challenge_answers
|
|
|
|
|
# 平台已认证的老师需要控制
|
|
|
|
|
@power = (@identity < User::EDU_GAME_MANAGER)
|
|
|
|
|
if !@power
|
|
|
|
@ -243,12 +243,25 @@ class GamesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 获取选择题答案
|
|
|
|
|
def get_choose_answer
|
|
|
|
|
@challenge = @game.challenge
|
|
|
|
|
tip_exception("本接口只能获取选择题答案") if @challenge.st != 1
|
|
|
|
|
@power = (@identity < User::EDU_GAME_MANAGER)
|
|
|
|
|
# 如果没权限,也没看过答案,则需要解锁
|
|
|
|
|
if @game.answer_open == 0 && !@power
|
|
|
|
|
tip_exception(1, @challenge.choose_score)
|
|
|
|
|
else
|
|
|
|
|
@challenge_chooses = @challenge.challenge_chooses
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 解锁答案
|
|
|
|
|
# 解锁实践题答案
|
|
|
|
|
# GET: /tasks/:identifier/get_answer_info?answer_id=?
|
|
|
|
|
def unlock_answer
|
|
|
|
|
@challenge = @game.challenge
|
|
|
|
|
@answer = ChallengeAnswer.find(params[:answer_id])
|
|
|
|
|
challenge = @answer.challenge
|
|
|
|
|
# 解锁需要本层级的答案是否需要扣分
|
|
|
|
@ -263,15 +276,16 @@ class GamesController < ApplicationController
|
|
|
|
|
begin
|
|
|
|
|
# 积分消耗情况记录
|
|
|
|
|
score = challenge.st.zero? ? -deduct_score : -challenge.choose_score.to_i
|
|
|
|
|
RewardGradeService.call(current_user, container_id: @answer.id, container_type: 'Answer', score: score)
|
|
|
|
|
RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: score)
|
|
|
|
|
|
|
|
|
|
# 通关查看答案 不扣 得分
|
|
|
|
|
answer_open = @challenge.st == 1 ? 1 : @answer.level
|
|
|
|
|
if @game.status == 2
|
|
|
|
|
@game.update_attributes!(:answer_open => @answer.level)
|
|
|
|
|
@game.update_attributes!(:answer_open =>answer_open)
|
|
|
|
|
else
|
|
|
|
|
# 扣除总分计算
|
|
|
|
|
answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score)
|
|
|
|
|
@game.update_attributes!(:answer_open => @answer.level, :answer_deduction => answer_deduction)
|
|
|
|
|
@game.update_attributes!(:answer_open => answer_open, :answer_deduction => answer_deduction)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
@ -279,7 +293,32 @@ class GamesController < ApplicationController
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 解锁选择题答案
|
|
|
|
|
def unlock_choose_answer
|
|
|
|
|
@challenge = @game.challenge
|
|
|
|
|
score = @challenge.choose_score
|
|
|
|
|
unless current_user.grade.to_i - score > 0
|
|
|
|
|
tip_exception("您没有足够的金币")
|
|
|
|
|
end
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
# 积分消耗情况记录
|
|
|
|
|
RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: -score)
|
|
|
|
|
# 通关查看答案 不扣 得分
|
|
|
|
|
if @game.status == 2
|
|
|
|
|
@game.update_attributes!(:answer_open => 1)
|
|
|
|
|
else
|
|
|
|
|
# 扣除总分计算
|
|
|
|
|
@game.update_attributes!(:answer_open => 1, :answer_deduction => 100)
|
|
|
|
|
end
|
|
|
|
|
@challenge_answers = @challenge.challenge_chooses
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error("#######金币扣除异常: #{e.message}")
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 查看答案需要扣取金币
|
|
|
|
|