邮件按天发送,内容按课程划分

This commit is contained in:
huang 2015-07-03 15:49:03 +08:00
parent b5badbd25f
commit 6da8cf237d
1 changed files with 9 additions and 9 deletions

View File

@ -120,12 +120,12 @@ class Mailer < ActionMailer::Base
count = courses.count
count = count - 1
for i in 0..count do
bids = courses[i].homework_commons.where("homework_commons.created_at between '#{date_from}' and '#{date_to}'").order("homework_commons.created_at desc")
attachments = courses[i].attachments.where("attachments.created_on between '#{date_from}' and '#{date_to}'").order('attachments.created_on DESC')
bids = courses[i].homework_commons.where("homework_commons.created_at between '#{date_from}' and '#{date_to}'").order(" '#{courses[i].id}', homework_commons.created_at desc")
attachments = courses[i].attachments.where("attachments.created_on between '#{date_from}' and '#{date_to}'").order(" '#{courses[i].id}',attachments.created_on DESC' ")
@bids += bids if bids.count > 0
@attachments += attachments if attachments.count > 0
end
@bids = @bids.sort_by { |obj| obj.created_at }
# @bids = @bids.sort_by { |obj| obj.created_at }
end
# 项目附件
@ -144,7 +144,7 @@ class Mailer < ActionMailer::Base
course_mesages = Message.find_by_sql("select DISTINCT me.* from messages me, boards b, members m where
b.id = me.board_id and b.course_id = m.course_id
and b.course_id is not Null and m.user_id = '#{user.id}'
and (me.created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
and (me.created_on between '#{date_from}' and '#{date_to}') order by m.course_id, created_on desc")
# 查询user在项目中发布的讨论帖子
project_messages = Message.find_by_sql("select DISTINCT me.* from messages me, boards b, members m where
@ -168,11 +168,11 @@ class Mailer < ActionMailer::Base
# 查询user在课程中发布的通知和回复通知
@course_news = (course_ids && !course_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n
where n.course_id in (#{course_ids})
and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : []
and (created_on between '#{date_from}' and '#{date_to}') order by n.course_id, created_on desc") : []
@course_news_comments = Comment.find_by_sql("select cm.* from comments cm, members m, courses c, news n
where m.user_id = '#{user.id}' and c.id = m.course_id and n.course_id = c.id and cm.commented_id = n.id
and cm.commented_type ='News' and (cm.created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
and cm.commented_type ='News' and (cm.created_on between '#{date_from}' and '#{date_to}') order by m.course_id, created_on desc")
# 查询user在项目中添加新闻和回复新闻
@project_news = (project_ids && !project_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids})
@ -180,19 +180,19 @@ class Mailer < ActionMailer::Base
@project_news_comments = Comment.find_by_sql("select c.* from comments c, members m, projects p, news n
where m.user_id = '#{user.id}' and p.id = m.project_id and n.project_id = p.id and c.commented_id = n.id
and c.commented_type ='News' and (c.created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
and c.commented_type ='News' and (c.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, created_on desc")
# 查询user在课程及个人中留言
@course_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT jfm.* from journals_for_messages jfm, members m, courses c
where m.user_id = '#{user.id}' and c.id = m.course_id and jfm.jour_id = c.id
and jfm.jour_type='Course' and (jfm.created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
and jfm.jour_type='Course' and (jfm.created_on between '#{date_from}' and '#{date_to}') order m.course_id, by created_on desc")
@user_journal_messages = user.journals_for_messages.where("jour_type='Principal' and (created_on between '#{date_from}' and '#{date_to}')").order('created_on DESC')
# 查询user在项目中留言用户反馈
@project_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT jfm.* from journals_for_messages jfm, members m, projects p
where m.user_id = '#{user.id}' and p.id = m.project_id and jfm.jour_id = p.id
and jfm.jour_type='Project' and (jfm.created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
and jfm.jour_type='Project' and (jfm.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, created_on desc")
# 查询user新建贴吧或发布帖子
@forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc")