Class: EducodeSales::Staff

Inherits:
ApplicationRecord show all
Defined in:
app/models/educode_sales/staff.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.month_listObject



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_permissionsObject



43
44
45
46
# File 'app/models/educode_sales/staff.rb', line 43

def all_permissions
  ids = Array(self.role&.permissions&.ids) + self.permissions.ids
  Permission.where(id: ids)
end

#area_idsObject



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 (request)
  unless Rails.cache.data.get(self.)
    # 第二天还在线访问,记用户登录一次
    (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 (request)
  # 登录状态保存到当天结束时间后+10分钟
  Rails.cache.data.set(self., 1)
  Rails.cache.data.expireat(self., Time.now.end_of_day.to_i + 600)

  last_history = self..last
  self..create(current_ip: request.remote_ip, last_ip: last_history&.current_ip, last_login_at: last_history&.created_at)
end

#is_enabledObject



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_keyObject

attr_writer :month



39
40
41
# File 'app/models/educode_sales/staff.rb', line 39

def 
  "login_user_#{self.id}"
end

#monthObject



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