diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 56c1d9347..ea09b9003 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -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,16 +243,29 @@ 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 # 解锁需要本层级的答案是否需要扣分 - 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 uid_logger("############金币数目: #{current_user.grade}") unless current_user.grade.to_i - deduct_score > 0 @@ -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 # 查看答案需要扣取金币 diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index ee2b061ba..57bbc9769 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1302,7 +1302,7 @@ class PollsController < ApplicationController sub_commit = [] user_commit = [] poll_users_info = %w(序号) - poll_ques_titles = poll_questions.pluck(:question_title).map {|k| k.strip if k.present?} + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| ActionController::Base.helpers.strip_tags(k) if k.present?} poll_un_anony = poll.un_anonymous if poll_un_anony #是否匿名,默认为false user_info = %w(登陆名 真实姓名 邮箱 学号) diff --git a/app/views/games/get_answer_info.json.jbuilder b/app/views/games/get_answer_info.json.jbuilder index 7620a991a..0f150d500 100644 --- a/app/views/games/get_answer_info.json.jbuilder +++ b/app/views/games/get_answer_info.json.jbuilder @@ -1,5 +1,6 @@ index = 0 json.status 3 +# st: 0 实践题 1 选择题 json.message do json.array! @challenge_answers do |answer| index += 1 @@ -13,3 +14,5 @@ json.message do end end + + diff --git a/app/views/games/get_choose_answer.json.jbuilder b/app/views/games/get_choose_answer.json.jbuilder new file mode 100644 index 000000000..15586de13 --- /dev/null +++ b/app/views/games/get_choose_answer.json.jbuilder @@ -0,0 +1,6 @@ +json.choose_answers do + json.array! @challenge_chooses do |choose| + json.position choose.position + json.answer choose.answer.blank? ? choose.standard_answer : choose.answer + end +end diff --git a/app/views/games/unlock_answer.json.jbuilder b/app/views/games/unlock_answer.json.jbuilder index 71018c7be..322536c2b 100644 --- a/app/views/games/unlock_answer.json.jbuilder +++ b/app/views/games/unlock_answer.json.jbuilder @@ -1 +1 @@ -json.contents @answer.contents \ No newline at end of file +json.contents @answer.contents diff --git a/app/views/games/unlock_choose_answer.json.jbuilder b/app/views/games/unlock_choose_answer.json.jbuilder new file mode 100644 index 000000000..15586de13 --- /dev/null +++ b/app/views/games/unlock_choose_answer.json.jbuilder @@ -0,0 +1,6 @@ +json.choose_answers do + json.array! @challenge_chooses do |choose| + json.position choose.position + json.answer choose.answer.blank? ? choose.standard_answer : choose.answer + end +end diff --git a/app/views/graduation_topics/export.xlsx.axlsx b/app/views/graduation_topics/export.xlsx.axlsx index ff5b58b11..2da608f6a 100644 --- a/app/views/graduation_topics/export.xlsx.axlsx +++ b/app/views/graduation_topics/export.xlsx.axlsx @@ -1,5 +1,5 @@ wb = xlsx_package.workbook -wb.use_autowidth = false +# wb.use_autowidth = false wb.use_shared_strings = true wb.styles do |s| @@ -9,13 +9,13 @@ wb.styles do |s| bg_cc = s.add_style :bg_color=> "CCC1DA",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_ff = s.add_style :bg_color=> "FFC000",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_bb = s.add_style :bg_color=> "9BBB59",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } - bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } + bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } wb.add_worksheet(:name => "毕设选题情况汇总") do |sheet| sheet.sheet_view.show_grid_lines = false sheet_title = table_columns sheet_title_c = sheet_title.count - sheet.add_row sheet_title, :style => bg_cell,:height => 15 + sheet.add_row sheet_title,:height => 32, :style => bg_cell sheet["J1:L1"].each { |c| c.style = bg_db } sheet["M1:O1"].each { |c| c.style = bg_cc } sheet["P1:Q1"].each { |c| c.style = bg_d2 } @@ -23,10 +23,10 @@ wb.styles do |s| sheet["U1:W1"].each { |c| c.style = bg_bb } if topic_users.count > 0 topic_users.each do |user| - sheet.add_row user, :style => sz_all + sheet.add_row user,:height => 18, :style => sz_all end #each_widh_index else - sheet.add_row ["--"]*sheet_title_c + sheet.add_row ["--"]*sheet_title_c,:height => 18 end sheet.column_widths *([15]*sheet.column_info.count) diff --git a/config/routes.rb b/config/routes.rb index e09808f6c..cf5bad608 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -124,6 +124,8 @@ Rails.application.routes.draw do get :get_answer_info get :unlock_answer get :check_test_sets + get :unlock_choose_answer + get :get_choose_answer end collection do