|
|
@ -221,12 +221,12 @@ class GamesController < ApplicationController
|
|
|
|
@result = challenge.st == 0 ? challenge.try(:answer) : challenge.choose_answer
|
|
|
|
@result = challenge.st == 0 ? challenge.try(:answer) : challenge.choose_answer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 获取答案
|
|
|
|
# 获取实践题答案
|
|
|
|
# GET: /tasks/:identifier/get_answer_info
|
|
|
|
# GET: /tasks/:identifier/get_answer_info
|
|
|
|
# 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框
|
|
|
|
# 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框
|
|
|
|
def get_answer_info
|
|
|
|
def get_answer_info
|
|
|
|
challenge = @game.challenge
|
|
|
|
@challenge = @game.challenge
|
|
|
|
@challenge_answers = challenge.challenge_answers
|
|
|
|
@challenge_answers = @challenge.challenge_answers
|
|
|
|
# 平台已认证的老师需要控制
|
|
|
|
# 平台已认证的老师需要控制
|
|
|
|
@power = (@identity < User::EDU_GAME_MANAGER)
|
|
|
|
@power = (@identity < User::EDU_GAME_MANAGER)
|
|
|
|
if !@power
|
|
|
|
if !@power
|
|
|
@ -243,16 +243,29 @@ class GamesController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 解锁答案
|
|
|
|
# 解锁实践题答案
|
|
|
|
# GET: /tasks/:identifier/get_answer_info?answer_id=?
|
|
|
|
# GET: /tasks/:identifier/get_answer_info?answer_id=?
|
|
|
|
def unlock_answer
|
|
|
|
def unlock_answer
|
|
|
|
|
|
|
|
@challenge = @game.challenge
|
|
|
|
@answer = ChallengeAnswer.find(params[:answer_id])
|
|
|
|
@answer = ChallengeAnswer.find(params[:answer_id])
|
|
|
|
challenge = @answer.challenge
|
|
|
|
challenge = @answer.challenge
|
|
|
|
# 解锁需要本层级的答案是否需要扣分
|
|
|
|
# 解锁需要本层级的答案是否需要扣分
|
|
|
|
points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score)
|
|
|
|
points = challenge.challenge_answers.where(level: @game.answer_open + 1..@answer.level).sum(:score)
|
|
|
|
deduct_score = ((points / 100.0) * challenge.score).to_i
|
|
|
|
deduct_score = ((points / 100.0) * challenge.score).to_i
|
|
|
|
uid_logger("############金币数目: #{current_user.grade}")
|
|
|
|
uid_logger("############金币数目: #{current_user.grade}")
|
|
|
|
unless current_user.grade.to_i - deduct_score > 0
|
|
|
|
unless current_user.grade.to_i - deduct_score > 0
|
|
|
@ -263,15 +276,16 @@ class GamesController < ApplicationController
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
# 积分消耗情况记录
|
|
|
|
# 积分消耗情况记录
|
|
|
|
score = challenge.st.zero? ? -deduct_score : -challenge.choose_score.to_i
|
|
|
|
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
|
|
|
|
if @game.status == 2
|
|
|
|
@game.update_attributes!(:answer_open => @answer.level)
|
|
|
|
@game.update_attributes!(:answer_open =>answer_open)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
# 扣除总分计算
|
|
|
|
# 扣除总分计算
|
|
|
|
answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score)
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
@ -279,7 +293,32 @@ class GamesController < ApplicationController
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 查看答案需要扣取金币
|
|
|
|
# 查看答案需要扣取金币
|
|
|
|