From a42c79cea2cdb9448e32a25fb58a8245584795a5 Mon Sep 17 00:00:00 2001 From: z9hang Date: Thu, 12 Jun 2014 16:35:59 +0800 Subject: [PATCH] =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=8A=9F=E8=83=BD=EF=BC=88=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=BE=BE=E5=88=B0=E4=B8=80=E5=AE=9A=E6=9D=A1=E4=BB=B6=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8D=87=E7=BA=A7=EF=BC=8C=E6=9C=AA=E5=9C=A8?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E4=BD=93=E7=8E=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/changeset.rb | 2 ++ app/models/praise_tread.rb | 2 ++ app/models/project_info.rb | 7 ++++++- app/models/user_score.rb | 20 ++++++++++---------- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 93248850b..36f78d32f 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -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 diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 8fc604671..fba48629f 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -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 diff --git a/app/models/project_info.rb b/app/models/project_info.rb index c6edab81c..4cb984b06 100644 --- a/app/models/project_info.rb +++ b/app/models/project_info.rb @@ -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 diff --git a/app/models/user_score.rb b/app/models/user_score.rb index 288370845..3e052f110 100644 --- a/app/models/user_score.rb +++ b/app/models/user_score.rb @@ -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})"