From a3abf098419e77605be9b5f152553d2fef30b6f9 Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 23 May 2016 16:04:06 +0800 Subject: [PATCH] =?UTF-8?q?delayjob=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/news.rb | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/models/news.rb b/app/models/news.rb index 7131969a4..beb58799f 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -167,17 +167,7 @@ class News < ActiveRecord::Base # 消息发送原则:除了消息的发布者,课程的其它成员都能收到消息提醒 def act_as_system_message if self.course - self.course.members.each do |m| - if m.user_id != self.author_id - self.delay.send_message(m.user_id, self.course_id) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count - if count == 0 - ws = WechatService.new - content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200 - ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", content, format_time(self.created_on) - end - end - end + self.delay.send_message else if !self.project.nil? self.project.members.each do |m| @@ -189,8 +179,19 @@ class News < ActiveRecord::Base end end - def send_message user_id, course_id - self.course_messages << CourseMessage.new(:user_id => user_id, :course_id => course_id, :viewed => false) + def send_message + self.course.members.each do |m| + if m.user_id != self.author_id + self.course_messages << CourseMessage.new(:user_id => user_id, :course_id => container_id, :viewed => false) + # 微信相关 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count + if count == 0 + ws = WechatService.new + content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200 + ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", content, format_time(self.created_on) + end + end + end end # Time 2015-03-31 13:50:54