Sha256: c3dbdd13568e4737e7c8271a56bbd13253a33bcdd07351146505d366fe7f5402

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

module EducodeSales
  class Staff < ApplicationRecord
    belongs_to :user
    belongs_to :role, optional: true

    has_many :follow_ups, dependent: :destroy
    has_many :operation_plans, dependent: :destroy
    has_many :operation_reports, dependent: :destroy
    has_many :sale_reports, dependent: :destroy
    has_many :teacher_follows, dependent: :destroy
    has_many :teachers, dependent: :destroy
    has_many :places
    has_many :businesses, dependent: :destroy
    has_many :activities, dependent: :destroy
    has_many :sale_plans, dependent: :destroy
    has_many :staff_schools, dependent: :destroy

    has_many :market_areas, dependent: :destroy
    has_many :areas, through: :market_areas
    validates :user_id, uniqueness: { message: '已存在' }

    # attr_writer :month

    def self.month_list
      list = []
      24.times.map do |d|
        ["#{d + 1}个月", d + 1]
      end
    end

    def area_ids
      self.market_areas.pluck(:area_id)
    end

    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
educode_sales-0.9.2 app/models/educode_sales/staff.rb
educode_sales-0.9.1 app/models/educode_sales/staff.rb
educode_sales-0.8.9 app/models/educode_sales/staff.rb
educode_sales-0.8.7 app/models/educode_sales/staff.rb
educode_sales-0.8.6 app/models/educode_sales/staff.rb
educode_sales-0.8.5 app/models/educode_sales/staff.rb