class SalesmanChannel < ApplicationRecord belongs_to :salesman, :touch => true, counter_cache: true belongs_to :school def school_name school.name end def teacher_count UserExtension.where(school_id: school_id).where.not(identity: 1).count end def student_count UserExtension.where(school_id: school_id, identity: 1).count end def course_count Course.where(school_id: school_id).count end def shixuns_count ShixunMember.joins("join user_extensions on user_extensions.user_id = shixun_members.user_id") .where(user_extensions: {school_id: school_id}).pluck(:shixun_id).uniq.count end end