添加用户升级功能(用户达到一定条件时自动升级,未在前端体现)

This commit is contained in:
z9hang 2014-06-12 16:35:59 +08:00
parent 5a47c52d23
commit a42c79cea2
4 changed files with 20 additions and 11 deletions

View File

@ -302,6 +302,8 @@ class Changeset < ActiveRecord::Base
def be_user_score
if self.new_record?
UserScore.project(:push_code, self.user, { changeset_id: self.id })
#更新用户等级
self.user.update_user_level
end
end

View File

@ -37,6 +37,8 @@ class PraiseTread < ActiveRecord::Base
obj = find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author
UserScore.skill(:praised_by_user, User.current,target_user,{ praise_tread_id: self.id })
#更新用户等级
target_user.update_user_level
end
end
end

View File

@ -5,7 +5,7 @@ class ProjectInfo < ActiveRecord::Base
belongs_to :user
validates_presence_of :project_id, :user_id
validates_uniqueness_of :project_id, :scope => :user_id
after_save :update_user_level
def self.manager? (user_id, project)
for project_info in project.project_infos
if project_info.user_id == user_id
@ -14,4 +14,9 @@ class ProjectInfo < ActiveRecord::Base
end
return false
end
#更新用户等级
def update_user_level
self.user.update_user_level
end
end

View File

@ -110,11 +110,11 @@ class UserScore < ActiveRecord::Base
current_user, target_user = get_users(current_user, target_user)
user_score = target_user.user_score_attr
case operate
when :followed_by # current_user 关注了target_user
when :followed_by # current_user 关注了target_user Add watcher
user_score.influence = user_score.influence.to_i + 2
user_score.save
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})"
when :cancel_followed # current_uer 取消了对 target_user的关注
when :cancel_followed # current_uer 取消了对 target_user的关注 delete watcher
user_score.influence = user_score.influence.to_i - 2
user_score.save
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} canceled followed. options => (#{options.to_s})"
@ -144,7 +144,7 @@ class UserScore < ActiveRecord::Base
# when :treading # current_user 踩了 target_user 的帖子
# Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treading #{target_user}'s posting. options => (#{options.to_s})"
when :treaded_by_user # current_user 踩了 target_user 的帖子
current_user_score.skill = current_user_score.skill.to_i - 2 #踩别人的帖子减2分
current_user_score.skill = current_user_score.skill.to_i - 2 #踩别人的帖子减2分 add praise_tread
current_user_score.save
if current_user.id == target_user.id
target_user.reload
@ -152,13 +152,13 @@ class UserScore < ActiveRecord::Base
end
level = current_user.get_level
if level == 1
target_user_score.skill = target_user_score.skill.to_i - 2 #帖子被一级会员踩-2分
target_user_score.skill = target_user_score.skill.to_i - 2 #帖子被一级会员踩-2分 add praise_tread
target_user_score.save
elsif level == 2
target_user_score.skill = target_user_score.skill.to_i - 4 #帖子被二级会员踩-4分
target_user_score.skill = target_user_score.skill.to_i - 4 #帖子被二级会员踩-4分 add praise_tread
target_user_score.save
elsif level == 3
target_user_score.skill = target_user_score.skill.to_i - 6 #帖子被三级会员踩-6分
target_user_score.skill = target_user_score.skill.to_i - 6 #帖子被三级会员踩-6分 add praise_tread
target_user_score.save
end
@ -166,13 +166,13 @@ class UserScore < ActiveRecord::Base
when :praised_by_user # current_user 顶了 target_user 的帖子
level = current_user.get_level
if level == 1
target_user_score.skill = target_user_score.skill.to_i + 4 #帖子被一级会员顶+4分
target_user_score.skill = target_user_score.skill.to_i + 4 #帖子被一级会员顶+4分 add praise_tread
target_user_score.save
elsif level == 2
target_user_score.skill = target_user_score.skill.to_i + 6 #帖子被二级会员顶+6分
target_user_score.skill = target_user_score.skill.to_i + 6 #帖子被二级会员顶+6分 add praise_tread
target_user_score.save
elsif level == 3
target_user_score.skill = target_user_score.skill.to_i + 8 #帖子被三级会员顶+8分
target_user_score.skill = target_user_score.skill.to_i + 8 #帖子被三级会员顶+8分 add praise_tread
target_user_score.save
end
@ -200,7 +200,7 @@ class UserScore < ActiveRecord::Base
user_score = current_user.try(:user_score_attr)
return false if current_user.nil?
case operate
when :push_code # current_user 提交了代码
when :push_code # current_user 提交了代码 changeset
user_score = user_score.active.to_i + 4
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})"