From 582e8921db2a83848e16921a03fbcb4f9f86938f Mon Sep 17 00:00:00 2001 From: daiao <35855898@qq.com> Date: Mon, 11 Mar 2019 14:17:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E5=85=B3=E5=8D=B4=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=8E=B7=E5=BE=97=E9=87=91=E5=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/games_service.rb | 2 +- ...190311032811_add_passed_score_for_users.rb | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190311032811_add_passed_score_for_users.rb diff --git a/app/services/games_service.rb b/app/services/games_service.rb index 0ed0cbe1..2b1e9b80 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -697,7 +697,7 @@ class GamesService if had_passed && !game.had_passed? game.update_attributes(:status => 2, :end_time => Time.now) # TPM实训已发布并且没有查看答案 - if shixun.is_published? && !game.answer_open + if shixun.is_published? && game.answer_open == 0 # 查看答案的时候处理final_scor和扣分记录 experience = score reward_grade(myshixun.owner, game.id, 'Game', score) diff --git a/db/migrate/20190311032811_add_passed_score_for_users.rb b/db/migrate/20190311032811_add_passed_score_for_users.rb new file mode 100644 index 00000000..c65550eb --- /dev/null +++ b/db/migrate/20190311032811_add_passed_score_for_users.rb @@ -0,0 +1,40 @@ +class AddPassedScoreForUsers < ActiveRecord::Migration + def up + games = Game.where("final_score = 0 and status = 2 and answer_open = 0 and created_at > '2019-03-09 00:00:00'").includes(:challenge) + puts "game_count: #{games.count}" + games.find_each do |game| + puts "#{game.id}" + challenge = game.challenge + # 选择题和实践题的分数 + score = challenge.choose_score + user = game.user + game.update_column(:final_score, score) + # 奖励金币和提供记录 + grade = Grade.where(:user_id => user.id, :container_id => game.id, :container_type => "Game").first + if grade.nil? + Grade.create!(:user_id => user.id, + :container_id => game.id, + :container_type => "Game", + :score => score, + :created_at => game.end_time || Time.now, + :updated_at => game.end_time || Time.now) + user.update_column(:grade, (score + user.grade.to_i)) + end + # 经验奖励 + experience = Experience.where(:user_id => user.id, :container_id => game.id, :container_type => "Game").first + if experience.nil? + Experience.create!(:user_id => user.id, + :container_id => game.id, + :container_type => "Game", + :score => score, + :created_at => game.end_time || Time.now, + :updated_at => game.end_time || Time.now) + user.update_column(:experience, (score + user.experience.to_i)) + end + end + + end + + def down + end +end