封装点击按钮时间

This commit is contained in:
huang 2015-09-21 15:08:40 +08:00
parent b70104cee8
commit 6e9db8b922
1 changed files with 24 additions and 16 deletions

View File

@ -101,22 +101,10 @@ class UsersController < ApplicationController
elsif @user != User.current && !User.current.admin? elsif @user != User.current && !User.current.admin?
return render_403 return render_403
end end
# 记录当前点击按钮的时间 # 初始化/更新 点击按钮时间
# 考虑到用户未退出刷新消息页面 # 24小时内显示系统消息
message_time = OnclickTime.where("user_id =?", User.current).first update_onclick_time
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
# 24小时内显示
contrast_time = Time.now - 86400
message_time.update_attributes(:onclick_time => Time.now)
end
@user_system_messages = SystemMessage.where("created_at >?", contrast_time).order("created_at desc")
# 当前用户查看消息,则设置消息为已读
# DO 待优化,只需查出符合条件的再更新
if params[:viewed] == "all" if params[:viewed] == "all"
course_querys = @user.course_messages course_querys = @user.course_messages
forge_querys = @user.forge_messages forge_querys = @user.forge_messages
@ -197,6 +185,26 @@ class UsersController < ApplicationController
end end
end end
# 初始化/更新 点击按钮时间
def update_onclick_time
# 记录当前点击按钮的时间
# 考虑到用户未退出刷新消息页面
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
# 24小时内显示
contrast_time = Time.now - 86400
message_time.update_attributes(:onclick_time => Time.now)
end
# 24小时内显示系统消息
@user_system_messages = SystemMessage.where("created_at >?", contrast_time).order("created_at desc")
end
# 系统消息 # 系统消息
def user_system_messages def user_system_messages
@sytem_messages = SystemMessage.order("created_at desc").all @sytem_messages = SystemMessage.order("created_at desc").all