From ee030e6fb5bf888855f3ae463ed3270d26757eaf Mon Sep 17 00:00:00 2001 From: z9hang Date: Mon, 9 Jun 2014 17:37:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=8C=BA=E5=8F=91=E5=B8=96?= =?UTF-8?q?=E5=8D=8F=E5=90=8C=E5=BE=97=E5=88=86+2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/message.rb | 8 +++++++ app/models/user_score.rb | 32 ++++++++++++++++++++++------ app/views/users/_show_score.html.erb | 6 +++--- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/models/message.rb b/app/models/message.rb index 2421a7d4f..c266d9a8c 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -54,6 +54,7 @@ class Message < ActiveRecord::Base # fq after_create :act_as_activity + before_save :be_user_score # end scope :visible, lambda {|*args| @@ -121,4 +122,11 @@ class Message < ActiveRecord::Base self.acts << Activity.new(:user_id => self.author_id) end # end + + # update user score + def be_user_score + if self.new_record? + UserScore.joint(:post_message, User.current,nil, { message_id: self.id }) + end + end end diff --git a/app/models/user_score.rb b/app/models/user_score.rb index 662229fad..e9975a3eb 100644 --- a/app/models/user_score.rb +++ b/app/models/user_score.rb @@ -47,16 +47,28 @@ class UserScore < ActiveRecord::Base # # Returns boolean. 返回积分保存结果 def self.joint(operate, current_user, target_user, options={}) + current_user, target_user = get_users(current_user, target_user) + user_score = current_user.user_score_attr case operate - when :post_message # current_user 发帖了 - Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a message. options => (#{options.to_s})" - when :post_issue # current_user 对 target_user 的缺陷留言了 + when :post_message # current_user 发帖了 + user_score.collaboration = user_score.collaboration.to_i + 2 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a message. options => (#{options.to_s})" + when :post_issue # current_user 对 target_user 的缺陷留言了 + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a issue. options => (#{options.to_s})" - when :change_issue_status # current_user 更改了缺陷的状态 + when :change_issue_status # current_user 更改了缺陷的状态 + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save Rails.logger.info "[UserScore#joint] ===> User: #{current_user} change issue status. options => (#{options.to_s})" - when :reply_message # current_user 对 target_user 留言的回复 + when :reply_message # current_user 对 target_user 留言的回复 + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply message. options => (#{options.to_s})" - when :reply_posting # current_user 对 target_user 帖子的回复 + when :reply_posting # current_user 对 target_user 帖子的回复 + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply posting. options => (#{options.to_s})" else Rails.logger.error "[UserScore#joint] ===> #{operate} is not define." @@ -77,8 +89,12 @@ class UserScore < ActiveRecord::Base # # Returns boolean. 返回积分保存结果 def self.influence(operate, current_user, target_user, options={}) + current_user, target_user = get_users(current_user, target_user) + user_score = current_user.user_score_attr case operate - when :followed_by # current_user 关注了target_user + when :followed_by # current_user 关注了target_user + user_score.active = user_score.influence.to_i + 2 + user_score.save Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})" else Rails.logger.error "[UserScore#influence] ===> #{operate} is not define." @@ -99,6 +115,8 @@ class UserScore < ActiveRecord::Base # # Returns boolean. 返回积分保存结果 def self.skill(operate, current_user, target_user, options={}) + current_user, target_user = get_users(current_user, target_user) + user_score = current_user.user_score_attr case operate # when :treading # current_user 踩了 target_user 的帖子 # Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treading #{target_user}'s posting. options => (#{options.to_s})" diff --git a/app/views/users/_show_score.html.erb b/app/views/users/_show_score.html.erb index 447e04e8b..ca1193c95 100644 --- a/app/views/users/_show_score.html.erb +++ b/app/views/users/_show_score.html.erb @@ -26,7 +26,7 @@

<%= l(:label_user_score) %>

- +
<%= image_tag(url_to_avatar(@user), :class => 'avatar2') %> @@ -46,7 +46,7 @@
- +
<%= link_to l(:label_user_score), {:controller => 'users', :action => 'score_index', :remote => true} %> : <%= format("%.2f" , finall_user_score).to_f %> @@ -71,6 +71,6 @@ -
+
<%= render :partial => 'users/score_index', :locals => {:index => 0 } %>