socialforge/db/migrate/20150831093918_about_user_f...

37 lines
1.4 KiB
Ruby
Raw Normal View History

2015-08-31 17:45:14 +08:00
class AboutUserFeedbackMessage < ActiveRecord::Migration
2015-08-31 16:41:52 +08:00
def up
JournalsForMessage.all.each do |jour_for_message|
transaction do
# 主留言
if jour_for_message.jour_type == 'Principal'
receivers = []
if jour_for_message.reply_id == 0
if jour_for_message.user_id != jour_for_message.jour_id # 过滤自己给自己的留言消息
receivers << jour_for_message.jour
end
else # 留言回复
reply_to = User.find(jour_for_message.reply_id)
if jour_for_message.user_id != jour_for_message.reply_id # 添加我回复的那个人
receivers << reply_to
end
unless jour_for_message.parent.nil?
if jour_for_message.user_id != jour_for_message.parent.jour_id && jour_for_message.reply_id != jour_for_message.parent.jour_id # 给东家发信息,如果回复的对象是东家则不发
receivers << jour_for_message.parent.jour
end
end
end
unless receivers.blank?
receivers.each do |r|
2015-08-31 17:45:14 +08:00
puts jour_for_message.id
jour_for_message.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => jour_for_message.id, :journals_for_message_type => "Principal", :viewed => true)
2015-08-31 16:41:52 +08:00
end
end
end
end
end
end
def down
end
end