require_dependency "educode_sales/application_controller" module EducodeSales class HomeController < ApplicationController def index end def statistics end def no_permission end def search_users @users = User.where("concat(lastname, firstname) like :q OR login like :q OR phone like :q or mail like :q", q: "%#{params[:q]}%").limit(50) end def search if params[:type] == 'department' @data = Department.joins(:school).where("schools.name like :q", q: "%#{params[:q]}%").limit(1000) unless @data.present? @data = Department.where("name like ?", "%#{params[:q]}%").limit(1000) end elsif params[:type] == "school" data = School.where("name like ? ", "%#{params[:q]}%").limit(1000) end end def search_teacher @data = Teacher.where("name like ? and is_key = false", "%#{params[:q]}%").limit(20) user_ids = @data.pluck(:user_id).compact.uniq @data += User.joins(:user_extension).where.not(id: user_ids).where("identity='teacher'", user_ids).where("lastname like ?", "%#{params[:q]}%").limit(50) end def search_operation_teacher @data = @current_admin.teachers.where("name like ? and is_key = false", "%#{params[:q]}%").limit(20) end def search_edu_teacher @data = User.joins(:user_extension).where("identity='teacher'").where("concat(lastname, firstname) like :q OR phone like :q OR mail like :q", q: "%#{params[:q]}%").limit(50) end def search_edu_user @data = User.joins(:user_extension).where("identity='teacher'").where("concat(lastname, firstname) like :q OR phone like :q OR mail like :q", q: "%#{params[:q]}%").limit(20) end def sales_staff @staffs = Staff if params[:teacher_assist].present? common = Common.find_by(clazz: 'staff_type', name: '运营') else common = Common.find_by(clazz: 'staff_type', name: '销售') end if params[:q].present? @staffs = @staffs.joins(user: :user_extension).where("concat(lastname, firstname) like :q", q: "%#{params[:q]}%") end if params[:teacher_assist].present? @staffs = @staffs.where(is_admin: false).where(job_type: common.id).page(params[:page]).per(10) else @staffs = @staffs.where(is_admin: false).where.not(id: @current_admin.id).where(job_type: common.id).page(params[:page]).per(10) end end def staff_schools @schools = School.all if params[:q].present? @schools = @schools.where("name like :q OR province like :q", q: "%#{params[:q]}%").page(params[:page]).per(10) end end def staff_business @schools = Business.all if params[:q].present? @schools = @schools.where("name like :q ", q: "%#{params[:q]}%").page(params[:page]).per(10) end end def staff_departments @departments = Department.where(school_id: params[:school_id]) if params[:q].present? @departments = @departments.where("name like :q", q: "%#{params[:q]}%").page(params[:page]).per(10) end end def sales_place @places = EducodeSales::Place if params[:q].present? @places = @places.where("name like :q", q: "%#{params[:q].strip}%") end @places = @places.page(params[:page]).per(10) end def search_activity @data = Activity.where("name like ?", "%#{params[:q]}%").limit(20) end def search_customer part_a_ids = EducodeSales::CustomerFollow.all.pluck(:school_id) part_b_ids = EducodeSales::Business.pluck(:school_id) school_ids = (part_a_ids + part_b_ids + EducodeSales::CustomerAdd.all.pluck(:school_id)).uniq @data = Department.joins(:school).where("schools.name like ?", "%#{params[:q]}%").where("schools.id in (?)", school_ids).limit(20) p @data end end end