From a9136bd8d040dadbbc15dfc707f322b0251ce95c Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Wed, 26 Oct 2016 11:18:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E5=BE=AE=E4=BF=A1=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=94=B9=E4=B8=BA=E5=BC=82=E6=AD=A5=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/news_controller.rb | 24 ++++++++++++------------ app/models/news.rb | 22 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 07a3ba393..53afa50aa 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -228,18 +228,18 @@ class NewsController < ApplicationController @news.safe_attributes = params[:news] @news.save_attachments(params[:attachments]) if @news.save - @course.members.each do |m| - if m.user_id != User.current.id - #self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{@news.course_id}").count - if count == 0 - ws = WechatService.new - content = @news.title - name = @news.course.syllabus.nil? ? @news.course.name : @news.course.syllabus.title+" • "+@news.course.name - ws.class_notice m.user_id, "course_notice", @news.id, "#{l(:label_new_notice_template)}", name, @news.author.show_name, format_time(@news.created_on), content, "点击查看通知详情" - end - end - end + # @course.members.each do |m| + # if m.user_id != User.current.id + # #self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) + # count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{@news.course_id}").count + # if count == 0 + # ws = WechatService.new + # content = @news.title + # name = @news.course.syllabus.nil? ? @news.course.name : @news.course.syllabus.title+" • "+@news.course.name + # ws.class_notice m.user_id, "course_notice", @news.id, "#{l(:label_new_notice_template)}", name, @news.author.show_name, format_time(@news.created_on), content, "点击查看通知详情" + # end + # end + # end if params[:asset_id] ids = params[:asset_id].split(',') diff --git a/app/models/news.rb b/app/models/news.rb index 0a893e34e..a6c0e574d 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -65,7 +65,7 @@ class News < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score, :act_as_system_message, :delay_news_send + after_create :act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score, :act_as_system_message, :delay_news_send,:delay_news_wechat_send after_update :update_activity after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score @@ -186,6 +186,26 @@ class News < ActiveRecord::Base end end + def delay_news_wechat_send + if self.course + self.delay.contain_news_message + end + end + + def news_wechat_message + self.course.members.each do |m| + if m.user_id != self.author_id + #self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_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 = self.title + ws.class_notice m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", self.course.name, self.author.show_name, format_time(self.created_on), content, "点击查看通知详情" + end + end + end + end + def delay_news_send if self.course self.delay.contain_news_message