模板消息的重构
This commit is contained in:
parent
73ad787e23
commit
275895f805
|
@ -16,6 +16,8 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class Comment < ActiveRecord::Base
|
||||
require 'net/http'
|
||||
require 'json'
|
||||
include Redmine::SafeAttributes
|
||||
include ApplicationHelper
|
||||
has_many_kindeditor_assets :assets, :dependent => :destroy
|
||||
|
@ -42,10 +44,12 @@ class Comment < ActiveRecord::Base
|
|||
if self.commented.course
|
||||
if self.author_id != self.commented.author_id
|
||||
self.course_messages << CourseMessage.new(:user_id => self.commented.author_id, :course_id => self.commented.course.id, :viewed => false)
|
||||
Wechat.api.comment_template self.commented.author_id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.comments.html_safe
|
||||
end
|
||||
else # 项目相关
|
||||
if self.author_id != self.commented.author_id
|
||||
self.forge_messages << ForgeMessage.new(:user_id => self.commented.author_id, :project_id => self.commented.project.id, :viewed => false)
|
||||
Wechat.api.comment_template self.commented.author_id, "#{l(:label_news_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.comments.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,6 +59,7 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
self.course.members.each do |m|
|
||||
# if m.user_id != self.user_id
|
||||
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
|
||||
Wechat.api.homework_template(m.user_id, "#{l(:label_new_homework_template)}", self.course.name, self.name, self.end_time.to_s + " 23:59:59")
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
@ -104,44 +105,7 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
#修改作业后发送微信模板消息
|
||||
def wechat_message
|
||||
self.course.members.each do |member|
|
||||
uw = UserWechat.where("user_id=?", member.user_id).first
|
||||
unless uw.nil?
|
||||
data = {
|
||||
touser:uw.openid,
|
||||
template_id:"3e5Dj2GIx8MOcMyRKpTUEQnM7Tg0ASSCNc01NS9HCGI",
|
||||
url:"http://www.trustie.net/",
|
||||
topcolor:"#FF0000",
|
||||
data:{
|
||||
first: {
|
||||
value:"您的作业已被修改",
|
||||
color:"#173177"
|
||||
},
|
||||
keyword1:{
|
||||
value:self.course.name,
|
||||
color:"#173177"
|
||||
},
|
||||
keyword2:{
|
||||
value:self.name,
|
||||
color:"#173177"
|
||||
},
|
||||
keyword3:{
|
||||
value:self.end_time.to_s + "23:59:59",
|
||||
color:"#173177"
|
||||
},
|
||||
remark:{
|
||||
value:"具体内容请点击详情查看网站",
|
||||
color:"#173177"
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info "start send template message: #{data}"
|
||||
begin
|
||||
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||
rescue Exception => e
|
||||
logger.error "[homework_common] ===> #{e}"
|
||||
end
|
||||
logger.info "send over. #{req}"
|
||||
end
|
||||
Wechat.api.homework_template(member.user_id, "#{l(:label_update_homework_template)}", self.course.name, self.name, self.end_time.to_s + " 23:59:59")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -239,44 +239,6 @@ class Journal < ActiveRecord::Base
|
|||
|
||||
#缺陷回复微信模板消息
|
||||
def issue_wechat_message
|
||||
uw = UserWechat.where(user_id: self.issue.author_id).first
|
||||
#unless uw.nil? && self.issue.author_id != User.current.id
|
||||
unless uw.nil?
|
||||
data = {
|
||||
touser:uw.openid,
|
||||
template_id:"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",
|
||||
url:"http://www.trustie.net/",
|
||||
topcolor:"#FF0000",
|
||||
data:{
|
||||
first: {
|
||||
value:"您的缺陷有新回复了",
|
||||
color:"#173177"
|
||||
},
|
||||
keyword1:{
|
||||
value:self.user.try(:realname),
|
||||
color:"#173177"
|
||||
},
|
||||
keyword2:{
|
||||
value:format_time(self.created_on),
|
||||
color:"#173177"
|
||||
},
|
||||
keyword3:{
|
||||
value:self.notes.html_safe,
|
||||
color:"#173177"
|
||||
},
|
||||
remark:{
|
||||
value:"具体内容请点击详情查看网站",
|
||||
color:"#173177"
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info "start send template message: #{data}"
|
||||
begin
|
||||
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||
rescue Exception => e
|
||||
logger.error "[journal] ===> #{e}"
|
||||
end
|
||||
logger.info "send over. #{req}"
|
||||
end
|
||||
Wechat.api.comment_template self.issue.author_id, "#{l(:label_issue_comment_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe
|
||||
end
|
||||
end
|
||||
|
|
|
@ -256,7 +256,7 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
if self.jour_type == 'HomeworkCommon'
|
||||
journal_wechat_message '您的作业有新回复了',self.jour.user_id
|
||||
Wechat.api.comment_template self.jour.user_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -269,7 +269,7 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
if self.reply_id == 0
|
||||
if self.user_id != self.jour_id # 过滤自己给自己的留言消息
|
||||
receivers << self.jour
|
||||
journal_wechat_message "您有新留言了",self.jour_id
|
||||
Wechat.api.comment_template self.jour_id, "#{l(:label_new_journals_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe
|
||||
end
|
||||
else # 留言回复
|
||||
reply_to = User.find(self.reply_id)
|
||||
|
@ -279,12 +279,11 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
if self.user_id != self.parent.jour_id && self.reply_id != self.parent.jour_id # 给东家发信息,如果回复的对象是东家则不发
|
||||
receivers << self.parent.jour
|
||||
end
|
||||
journal_wechat_message "您的留言有新回复了",self.reply_id
|
||||
Wechat.api.comment_template self.reply_id, "#{l(:label_journals_comment_template)}", self.user.try(:realname), format_time(self.created_on), self.notes.html_safe
|
||||
end
|
||||
receivers.each do |r|
|
||||
self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -305,48 +304,4 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
down_course_score_num(self.jour.course_id, self.user_id, "HomeworkCommon")
|
||||
end
|
||||
end
|
||||
|
||||
#微信模板消息
|
||||
def journal_wechat_message type, user_id
|
||||
uw = UserWechat.where(user_id: user_id).first
|
||||
#unless uw.nil? && self.reply_id != User.current.id
|
||||
unless uw.nil?
|
||||
data = {
|
||||
touser:uw.openid,
|
||||
template_id:"A_3f5v90-zK73V9Kijm-paDkl9S-NuM8Cf-1UJi92_c",
|
||||
url:"http://www.trustie.net/",
|
||||
topcolor:"#FF0000",
|
||||
data:{
|
||||
first: {
|
||||
value:type,
|
||||
color:"#173177"
|
||||
},
|
||||
keyword1:{
|
||||
value:self.user.try(:realname),
|
||||
color:"#173177"
|
||||
},
|
||||
keyword2:{
|
||||
value:format_time(self.created_on),
|
||||
color:"#173177"
|
||||
},
|
||||
keyword3:{
|
||||
value:self.notes.html_safe,
|
||||
color:"#173177"
|
||||
},
|
||||
remark:{
|
||||
value:"具体内容请点击详情查看网站",
|
||||
color:"#173177"
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info "start send template message: #{data}"
|
||||
begin
|
||||
req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data)
|
||||
rescue Exception => e
|
||||
logger.error "[journal_for_message] ===> #{e}"
|
||||
end
|
||||
logger.info "send over. #{req}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#encoding: utf-8
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
|
@ -16,6 +17,8 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class Message < ActiveRecord::Base
|
||||
require 'net/http'
|
||||
require 'json'
|
||||
include Redmine::SafeAttributes
|
||||
include UserScoreHelper
|
||||
include ApplicationHelper
|
||||
|
@ -262,12 +265,14 @@ class Message < ActiveRecord::Base
|
|||
self.course.members.each do |m|
|
||||
if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息
|
||||
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false)
|
||||
Wechat.api.topic_publish_template m.user_id, "#{l(:label_course_topic_template)}", self.subject, self.author.try(:realname), format_time(self.created_on)
|
||||
end
|
||||
end
|
||||
else # 回帖
|
||||
self.course.members.each do |m|
|
||||
if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
|
||||
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false)
|
||||
Wechat.api.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.content.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -276,12 +281,14 @@ class Message < ActiveRecord::Base
|
|||
self.project.members.each do |m|
|
||||
if m.user_id != self.author_id
|
||||
self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false)
|
||||
Wechat.api.topic_publish_template m.user_id, "#{l(:label_project_topic_template)}", self.subject, self.author.try(:realname), format_time(self.created_on)
|
||||
end
|
||||
end
|
||||
else # 回帖
|
||||
self.project.members.each do |m|
|
||||
if m.user_id == Message.find(self.parent_id).author_id && m.user_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
|
||||
self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false)
|
||||
Wechat.api.comment_template m.user_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), self.content.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2123,4 +2123,29 @@ zh:
|
|||
label_resource_download_times: 下载次数
|
||||
label_resource_upload_author: 上传者
|
||||
label_resource_belongs_course: 所属课程
|
||||
label_resource_belongs_project: 所属项目
|
||||
label_resource_belongs_project: 所属项目
|
||||
|
||||
#微信模板消息
|
||||
label_new_homework_template: 您的课程有新作业了
|
||||
label_update_homework_template: 您的作业已被修改
|
||||
label_course_topic_template: 课程问答区有新帖子发布了
|
||||
label_topic_comment_template: 您的帖子有新回复了
|
||||
label_project_topic_template: 项目讨论区有新帖子发布了
|
||||
label_issue_comment_template: 您的缺陷有新回复了
|
||||
label_notice_comment_template: 您的课程通知有新回复了
|
||||
label_news_comment_template: 您的项目新闻有新回复了
|
||||
label_homework_comment_template: 您的作业有新回复了
|
||||
label_new_journals_template: 您有新留言了
|
||||
label_journals_comment_template: 您的留言有新回复了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
label_resource_name: 您的课程有新作业了
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ button:
|
|||
-
|
||||
type: "view"
|
||||
name: "进入网站"
|
||||
url: "http://www.trustie.net/"
|
||||
url: "https://www.trustie.net/"
|
||||
-
|
||||
type: "view"
|
||||
name: "使用手册"
|
||||
|
|
Loading…
Reference in New Issue