From 90208e166f5ba09146c00c2d9477f1bfe894de44 Mon Sep 17 00:00:00 2001
From: huang <huang.jingquan@163.com>
Date: Tue, 23 Feb 2016 13:24:20 +0800
Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=9F=E8=AE=A1=E6=95=B0?=
 =?UTF-8?q?=E5=B0=8F=E4=BA=8E0=E6=83=85=E5=86=B5=E5=88=A4=E6=96=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/models/attachment.rb | 7 +------
 app/models/issue.rb      | 2 +-
 app/models/journal.rb    | 5 +++--
 app/models/message.rb    | 4 ++--
 app/models/news.rb       | 2 +-
 5 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 0bbbd9a54..588ee144d 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -644,12 +644,7 @@ class Attachment < ActiveRecord::Base
   def decrease_attchments_count
     if self.container_type == "Project" && !self.project.project_score.nil?
       attach_count = self.container.project_score.attach_num - 1
-      if attach_count < 0
-        self.container.project_score.update_attribute(:attach_num, 0)
-      else
-        self.container.project_score.update_attribute(:attach_num, attach_count)
-      end
-
+      self.container.project_score.update_attribute(:attach_num, attach_count < 0 ? 0 : attach_count)
     end
   end
 end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index e1de4cd9e..c82f6f0be 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -184,7 +184,7 @@ class Issue < ActiveRecord::Base
   def decrease_issues_count
     unless self.project.project_score.nil?
       issue_count = self.project.project_score.issue_num - 1
-      self.project.project_score.update_attribute(:issue_num, issue_count)
+      self.project.project_score.update_attribute(:issue_num, issue_count < 0 ? 0 : issue_count)
     end
   end
 
diff --git a/app/models/journal.rb b/app/models/journal.rb
index b184c82e6..c37b8d2c5 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -219,8 +219,9 @@ class Journal < ActiveRecord::Base
   # 减少留言数量统计
   def decrease_issues_journal_count
     unless self.issue.project.nil?
-      project = self.issue.project
-      project.project_score.update_attribute(:issue_journal_num, project.project_score.issue_journal_num - 1)
+      journal_count = self.issue.project.project_score.issue_journal_num - 1
+      # project = self.issue.project
+       self.issue.project.project_score.update_attribute(:issue_journal_num, journal_count < 0 ? 0 : journal_count)
     end
   end
 
diff --git a/app/models/message.rb b/app/models/message.rb
index 675d37790..6381f444f 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -146,10 +146,10 @@ class Message < ActiveRecord::Base
       # 讨论区
       if self.parent_id.nil?
         count = self.project.project_score.board_num - 1
-        self.project.project_score.update_attribute(:board_num, count)
+        self.project.project_score.update_attribute(:board_num, count < 0 ? 0 : count)
       else # 回复
         count = self.project.project_score.board_message_num - 1
-        self.project.project_score.update_attribute(:board_message_num, count)
+        self.project.project_score.update_attribute(:board_message_num, count < 0 ? 0 : count)
       end
     end
   end
diff --git a/app/models/news.rb b/app/models/news.rb
index fee5d2801..d0fccae17 100644
--- a/app/models/news.rb
+++ b/app/models/news.rb
@@ -126,7 +126,7 @@ class News < ActiveRecord::Base
   def decrease_news_count
     if self.project && !self.project.project_score.nil?
       count = self.project.project_score.news_num - 1
-      self.project.project_score.update_attribute(:news_num, count)
+      self.project.project_score.update_attribute(:news_num, count < 0 ? 0 : count)
     end
   end