Class: EducodeSales::Staff
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- EducodeSales::Staff
- Defined in:
- app/models/educode_sales/staff.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all_permissions ⇒ Object
- #area_ids ⇒ Object
- #check_login_status(request) ⇒ Object
- #create_login_history(request) ⇒ Object
- #is_enabled ⇒ Object
-
#last_login_key ⇒ Object
attr_writer :month.
- #month ⇒ Object
Class Method Details
.month_list ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/educode_sales/staff.rb', line 64 def self.month_list list = [] 24.times do |d| list << ["#{d + 1}个月", d + 1] end 8.times do |d| list << ["#{d + 3}年", (d + 3) * 12] end list end |
Instance Method Details
#all_permissions ⇒ Object
43 44 45 46 |
# File 'app/models/educode_sales/staff.rb', line 43 def ids = Array(self.role&.&.ids) + self..ids Permission.where(id: ids) end |
#area_ids ⇒ Object
75 76 77 |
# File 'app/models/educode_sales/staff.rb', line 75 def area_ids self.market_areas.pluck(:area_id) end |
#check_login_status(request) ⇒ Object
48 49 50 51 52 53 |
# File 'app/models/educode_sales/staff.rb', line 48 def check_login_status(request) unless Rails.cache.data.get(self.last_login_key) # 第二天还在线访问,记用户登录一次 create_login_history(request) end end |
#create_login_history(request) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'app/models/educode_sales/staff.rb', line 55 def create_login_history(request) # 登录状态保存到当天结束时间后+10分钟 Rails.cache.data.set(self.last_login_key, 1) Rails.cache.data.expireat(self.last_login_key, Time.now.end_of_day.to_i + 600) last_history = self.login_histories.last self.login_histories.create(current_ip: request.remote_ip, last_ip: last_history&.current_ip, last_login_at: last_history&.created_at) end |
#is_enabled ⇒ Object
87 88 89 |
# File 'app/models/educode_sales/staff.rb', line 87 def is_enabled expired_at.present? && enabled_at.present? && expired_at > Time.now && enabled_at < Time.now end |
#last_login_key ⇒ Object
attr_writer :month
39 40 41 |
# File 'app/models/educode_sales/staff.rb', line 39 def last_login_key "login_user_#{self.id}" end |
#month ⇒ Object
79 80 81 82 83 84 85 |
# File 'app/models/educode_sales/staff.rb', line 79 def month if expired_at.present? && enabled_at.present? (expired_at.year * 12 + expired_at.month) - (enabled_at.year * 12 + enabled_at.month) else nil end end |