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