功能:24小时内系统消息显示

This commit is contained in:
huang 2015-09-17 13:58:55 +08:00
parent e7fc0ca6d3
commit b5f4b1dd96
1 changed files with 6 additions and 5 deletions

View File

@ -107,17 +107,18 @@ class UsersController < ApplicationController
end
# 记录当前点击按钮的时间
# 考虑到用户未退出刷新消息页面
if OnclickTime.where("user_id =?", User.current).first.nil?
message_time = OnclickTime.where("user_id =?", User.current).first
if message_time.nil?
message_new_time = OnclickTime.new
message_new_time.user_id = User.current.id
message_new_time.onclick_time = Time.now
message_new_time.save
else
message_new_time = OnclickTime.where("user_id =?", User.current).first
message_last_time = message_new_time.onclick_time
message_new_time.update_attributes(:onclick_time => Time.now)
# 24小时内显示
contrast_time = Time.now - 86400
message_time.update_attributes(:onclick_time => Time.now)
end
@user_system_messages = SystemMessage.where("created_at >?", message_last_time).order("created_at desc")
@user_system_messages = SystemMessage.where("created_at >?", contrast_time).order("created_at desc")
# 当前用户查看消息,则设置消息为已读
if params[:viewed] == "all"
course_querys = @user.course_messages