diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb index 1a71173c6..29109fd80 100644 --- a/app/controllers/admins/system_notifications_controller.rb +++ b/app/controllers/admins/system_notifications_controller.rb @@ -6,7 +6,7 @@ class Admins::SystemNotificationsController < Admins::BaseController sort_by = SystemNotification.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' q = SystemNotification.ransack(subject_cont: params[:search]) - notifications = q.result(distinct: true).order("#{sort_by} #{sort_direction},created_at desc") + notifications = q.result(distinct: true).reorder("#{sort_by} #{sort_direction},created_at desc") @notifications = paginate(notifications) end @@ -25,7 +25,7 @@ class Admins::SystemNotificationsController < Admins::BaseController @notification = SystemNotification.new(notification_params) if @notification.save redirect_to admins_system_notifications_path - flash[:success] = '系统保留关键词创建成功' + flash[:success] = '系统消息创建成功' else redirect_to admins_system_notifications_path flash[:danger] = @notification.errors.full_messages.join(",") @@ -38,7 +38,7 @@ class Admins::SystemNotificationsController < Admins::BaseController if @notification.update_attributes(notification_params) format.html do redirect_to admins_system_notifications_path - flash[:success] = '系统保留关键词更新成功' + flash[:success] = '系统消息更新成功' end format.js {render_ok} else @@ -54,10 +54,10 @@ class Admins::SystemNotificationsController < Admins::BaseController def destroy if @notification.destroy redirect_to admins_system_notifications_path - flash[:success] = "系统保留关键词删除成功" + flash[:success] = "系统消息删除成功" else redirect_to admins_system_notifications_path - flash[:danger] = "系统保留关键词删除失败" + flash[:danger] = "系统消息删除失败" end end @@ -70,7 +70,7 @@ class Admins::SystemNotificationsController < Admins::BaseController @notification = SystemNotification.find_by(id: params[:id]) unless @notification.present? redirect_to admins_system_notifications_path - flash[:danger] = "系统保留关键词不存在" + flash[:danger] = "系统消息不存在" end end end \ No newline at end of file diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index b6662f661..b2dc2e900 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -4,7 +4,7 @@ class SettingsController < ApplicationController get_add_menu get_common_menu get_personal_menu - + get_top_system_notification end private @@ -40,6 +40,10 @@ class SettingsController < ApplicationController end end + def get_top_system_notification + @top_system_notification = SystemNotification.is_top.first + end + def get_site_url(key, value) key.to_s === "url" ? append_http(reset_site_url(value)) : reset_site_url(value) end diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 76c514cd3..11220dfc1 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -12,6 +12,15 @@ class SystemNotification < ApplicationRecord + default_scope { order(created_at: :desc)} + has_many :system_notification_histories has_many :users, through: :system_notification_histories + + scope :is_top, lambda { where(is_top: true) } + + + def read_member?(user_id) + self.system_notification_histories.where(user_id: user_id).present? ? true : false + end end diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 330966aa1..c8d4c89eb 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -56,4 +56,13 @@ json.setting do end json.common @common + + if @top_system_notification.present? + json.system_notification do + json.(@top_system_notification, :subject, :sub_subject, :content) + json.is_read @top_system_notification.read_member?(current_user.id) + end + else + json.system_notification nil + end end