2022-05-31 16:34:08 +08:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: message_templates
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# type :string(255)
|
|
|
|
# sys_notice :text(65535)
|
|
|
|
# email :text(65535)
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# notification_url :string(255)
|
|
|
|
# email_title :string(255)
|
|
|
|
#
|
|
|
|
|
|
|
|
# 统一模板(
|
|
|
|
|
|
|
|
class MessageTemplate::CustomTip < MessageTemplate
|
|
|
|
|
|
|
|
# MessageTemplate::CustomTip.get_message_content(User.where(login: 'yystopf'), "hahah")
|
|
|
|
def self.get_message_content(receivers, template, props={})
|
|
|
|
return '', '', '' if receivers.blank? || template.blank?
|
|
|
|
content = template.sys_notice
|
|
|
|
notification_url = template.notification_url
|
|
|
|
props.each do |k, v|
|
|
|
|
content.gsub!("{#{k}}", v)
|
|
|
|
notification_url.gsub!("{#{k}}", v)
|
|
|
|
end
|
2022-06-01 16:11:18 +08:00
|
|
|
notification_url.gsub!('{baseurl}', base_url)
|
2022-05-31 16:34:08 +08:00
|
|
|
return receivers_string(receivers), content, notification_url
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.info("MessageTemplate::CustomTip.get_message_content [ERROR] #{e}")
|
|
|
|
return '', '', ''
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get_email_message_content(receiver, template, props={})
|
|
|
|
return '', '', '' if receiver.blank? || template.blank?
|
|
|
|
title = template.email_title
|
|
|
|
content = template.email
|
|
|
|
props.each do |k, v|
|
|
|
|
title.gsub!("{#{k}}", v)
|
|
|
|
content.gsub!("{#{k}}", v)
|
|
|
|
end
|
|
|
|
content.gsub!('{receiver}', receiver&.real_name)
|
|
|
|
title.gsub!('{platform}', PLATFORM)
|
|
|
|
content.gsub!('{platform}', PLATFORM)
|
2022-06-01 16:11:18 +08:00
|
|
|
content.gsub!('{baseurl}', base_url)
|
2022-05-31 16:34:08 +08:00
|
|
|
|
|
|
|
return receiver&.mail, title, content
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.info("MessageTemplate::CustomTip.get_email_message_content [ERROR] #{e}")
|
|
|
|
return '', '', ''
|
|
|
|
end
|
2022-06-01 15:23:05 +08:00
|
|
|
|
|
|
|
def self.get_email_content(template, props = {})
|
|
|
|
return '', '', '' if template.blank?
|
|
|
|
title = template.email_title
|
|
|
|
content = template.email
|
|
|
|
props.each do |k, v|
|
|
|
|
title.gsub!("{#{k}}", v)
|
|
|
|
content.gsub!("{#{k}}", v)
|
|
|
|
end
|
|
|
|
title.gsub!('{platform}', PLATFORM)
|
|
|
|
content.gsub!('{platform}', PLATFORM)
|
2022-06-08 20:54:00 +08:00
|
|
|
content.gsub!('{baseurl}', base_url)
|
2022-06-01 15:23:05 +08:00
|
|
|
|
|
|
|
return title, content
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.info("MessageTemplate::CustomTip.get_email_content [ERROR] #{e}")
|
|
|
|
return '', ''
|
|
|
|
end
|
2022-05-31 16:34:08 +08:00
|
|
|
end
|