Class: EducodeSales::HomeController

Inherits:
ApplicationController show all
Defined in:
app/controllers/educode_sales/home_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin, #authenticate_request, #current_user, #filter, #render_failure, #render_success

Instance Method Details

#indexObject



5
6
# File 'app/controllers/educode_sales/home_controller.rb', line 5

def index
end

#no_permissionObject



11
12
# File 'app/controllers/educode_sales/home_controller.rb', line 11

def no_permission
end

#sales_placeObject



68
69
70
71
72
73
74
# File 'app/controllers/educode_sales/home_controller.rb', line 68

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

#sales_staffObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/educode_sales/home_controller.rb', line 45

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

#searchObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/educode_sales/home_controller.rb', line 18

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

#search_edu_teacherObject



41
42
43
# File 'app/controllers/educode_sales/home_controller.rb', line 41

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

#search_operation_teacherObject



37
38
39
# File 'app/controllers/educode_sales/home_controller.rb', line 37

def search_operation_teacher
  @data = @current_admin.teachers.where("name like ? and is_key = false", "%#{params[:q]}%").limit(20)
end

#search_teacherObject



31
32
33
34
35
# File 'app/controllers/educode_sales/home_controller.rb', line 31

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

#search_usersObject



14
15
16
# File 'app/controllers/educode_sales/home_controller.rb', line 14

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

#staff_schoolsObject



61
62
63
64
65
66
# File 'app/controllers/educode_sales/home_controller.rb', line 61

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

#statisticsObject



8
9
# File 'app/controllers/educode_sales/home_controller.rb', line 8

def statistics
end