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, #is_commissioner_above?, #paginate, #render_failure, #render_success, #subject_members, #subject_staffs, #subject_url

Methods included from ApplicationHelper

#add_businesses_score, #base_url, #collection_amount_score, #completion_rate, #current?, #disk_filename, #get_businesses_chart, #handled_data, #handled_time_data, #handled_time_data_accurate, #relative_path, #signed_amount_score, #storage_path, #url_to_avatar, #visits_score

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



101
102
103
104
105
106
107
# File 'app/controllers/educode_sales/home_controller.rb', line 101

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/educode_sales/home_controller.rb', line 49

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_activityObject



110
111
112
# File 'app/controllers/educode_sales/home_controller.rb', line 110

def search_activity
  @data = Activity.where("name like ?", "%#{params[:q]}%").limit(20)
end

#search_contractsObject



87
88
89
90
91
92
# File 'app/controllers/educode_sales/home_controller.rb', line 87

def search_contracts
  @data = Business
  if params[:q].present?
    @data = @data.joins(:school).where("educode_sales_businesses.name like :q OR educode_sales_businesses.number like :q OR schools.name like :q ", q: "%#{params[:q]}%").limit(20)
  end
end

#search_customerObject



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/educode_sales/home_controller.rb', line 114

def search_customer
  if params[:type] == '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)
  elsif params[:type] == 'active'
    @data = Activity.where("name like ?", "%#{params[:q]}%").limit(20)
  elsif params[:type] == 'place'
    @data = EducodeSales::Place
    @data = @data.where("name like :q", q: "%#{params[:q].strip}%").limit(20)
  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_edu_userObject



45
46
47
# File 'app/controllers/educode_sales/home_controller.rb', line 45

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

#search_money_plansObject



128
129
130
131
132
133
134
# File 'app/controllers/educode_sales/home_controller.rb', line 128

def search_money_plans
  # @data = MoneyPlan.joins(business: [:school, :last_follow_up])
  @data = MoneyPlan.joins("JOIN educode_sales_businesses ON educode_sales_businesses.last_follow_up_id = educode_sales_money_plans.follow_up_id JOIN schools ON schools.id = educode_sales_businesses.school_id")
  if params[:q].present?
    @data = @data.where.not(business_id: nil).where("educode_sales_businesses.name like :q OR educode_sales_businesses.number like :q OR schools.name like :q ", q: "%#{params[:q]}%").limit(20)
  end
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_businessObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/educode_sales/home_controller.rb', line 73

def staff_business
  @schools = Business.all
  if params[:q].present?
    @schools = @schools.where("name like :q ", q: "%#{params[:q]}%").page(params[:page]).per(10)
    # 商机搜索为空时 去搜索学校名 如果搜索到学校名 则返回学校id相关的商机
    if @schools.empty?
    @schools = Business.joins(:school)
                         .where("schools.name LIKE :q", q: "%#{params[:q]}%")
                         .page(params[:page])
                         .per(10)
    end
  end
end

#staff_departmentsObject



94
95
96
97
98
99
# File 'app/controllers/educode_sales/home_controller.rb', line 94

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

#staff_schoolsObject



66
67
68
69
70
71
# File 'app/controllers/educode_sales/home_controller.rb', line 66

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