通关却没有获得金币

dev_shixuns
daiao 6 years ago
parent fa1af83d6d
commit 582e8921db

@ -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)

@ -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
Loading…
Cancel
Save