From c267b69fea863da3871f401c838b3d1f81528d03 Mon Sep 17 00:00:00 2001 From: daiao <35855898@qq.com> Date: Wed, 13 Mar 2019 14:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=AE=9E=E8=AE=AD=E9=80=9A?= =?UTF-8?q?=E5=85=B3=E5=90=8E=E6=B2=A1=E5=BE=97=E5=88=86=E7=9A=84=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20190313005345_add_score_for_pass_games.rb | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 db/migrate/20190313005345_add_score_for_pass_games.rb diff --git a/db/migrate/20190313005345_add_score_for_pass_games.rb b/db/migrate/20190313005345_add_score_for_pass_games.rb new file mode 100644 index 00000000..0517993c --- /dev/null +++ b/db/migrate/20190313005345_add_score_for_pass_games.rb @@ -0,0 +1,39 @@ +class AddScoreForPassGames < ActiveRecord::Migration + def up + games = Game.where("final_score = 0 and status = 2 and answer_open = 0 and end_time > '2019-03-08 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, + :updated_at => game.end_time) + 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, + :updated_at => game.end_time) + user.update_column(:experience, (score + user.experience.to_i)) + end + end + end + + def down + end +end