Class: EducodeSales::TeachersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- EducodeSales::TeachersController
- Defined in:
- app/controllers/educode_sales/teachers_controller.rb
Instance Method Summary collapse
- #activities ⇒ Object
- #add_courses ⇒ Object
- #add_event ⇒ Object
- #add_keys ⇒ Object
-
#assign ⇒ Object
获取该教师所指派生态经理.
-
#assign_staff ⇒ Object
指派生态经理.
- #course_list ⇒ Object
- #course_subject ⇒ Object
- #create ⇒ Object
- #create_course ⇒ Object
- #daily_paper ⇒ Object
- #delete_course ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #edit_follow_record ⇒ Object
- #import ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #new_follow_record ⇒ Object
- #search_new ⇒ Object
- #show_class ⇒ Object
- #show_follow ⇒ Object
- #show_follow_record ⇒ Object
- #unfinish_plans ⇒ Object
- #update ⇒ Object
- #update_course ⇒ Object
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
#activities ⇒ Object
440 441 442 443 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 440 def activities teacher = Teacher.find(params[:id]) @activities = teacher.activities.page(params[:page]).per(params[:limit]) end |
#add_courses ⇒ Object
350 351 352 353 354 355 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 350 def add_courses load_teacher subject_names = %w[程序设计语言 计算机基础 算法设计 计算机系统能力 大数据 人工智能 数据库 电子信息 Web技术 软件工程 网络与安全 区块链 数学与统计 物联网 云计算 虚拟仿真].map{|d| {value: d, name: d}} gon.subject_names = subject_names render layout: false end |
#add_event ⇒ Object
388 389 390 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 388 def add_event render layout: false end |
#add_keys ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 6 def add_keys follow_up = FollowUp.find(params[:follow_up_id]) if follow_up.key_people_count == 0 last_follow = follow_up.business.follow_ups.where.not(id: follow_up.id).order("id desc").first if last_follow.present? && last_follow.key_people_count > 0 @person = last_follow.key_person.last if @person&.teacher.present? gon.teacher = "t-#{@person.teacher_id}" gon.teachers = { value: "t-#{@person.teacher_id}", name: @person.name } else gon.teacher = "" gon.teachers = {} end end end @attitudes = Common.where(clazz: 'key_attitude').order("position").pluck(:name, :id) gon.attitudes = @attitudes render layout: false end |
#assign ⇒ Object
获取该教师所指派生态经理
460 461 462 463 464 465 466 467 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 460 def assign role = Role.find_by( name: '生态经理') staffs = Staff.joins(:user).where(role_id: role.id) teacher = Teacher.find(params[:id]) selected_staff_ids = teacher.assign_staffs.pluck(:staff_id) gon.staff_manages = staffs.map { |d| {name: d.user.real_name, value: d.id, selected: selected_staff_ids.include?(d.id)} } render layout: false end |
#assign_staff ⇒ Object
指派生态经理
470 471 472 473 474 475 476 477 478 479 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 470 def assign_staff @teacher = EducodeSales::Teacher.find(params[:id]) assign_staffs = [] params[:to_id].split(",").each do |i| assign_staffs << AssignStaff.find_or_initialize_by(sourcable_id: @teacher.id, staff_id: i, sourcable_type: "EducodeSales::Teacher") end @teacher.assign_staffs = assign_staffs @teacher.save render_success end |
#course_list ⇒ Object
430 431 432 433 434 435 436 437 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 430 def course_list user = User.find_by(id: params[:user_id]) if user @courses = Course.joins(:course_members).where(course_members: {user_id: user.id}).where("is_delete = 0 and role != 4 and excellent = 0 and is_hidden = 0").where("start_date is null or start_date <= '#{Date.today}'").distinct("course_id").page(params[:page]).per(params[:limit]) else @courses = Course.none end end |
#course_subject ⇒ Object
341 342 343 344 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 341 def course_subject load_teacher @courses = @teacher.course_subjects.all end |
#create ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 248 def create department = Department.find(params[:department_id]) teacher = @current_admin.teachers.build(teacher_params) params[:teacher_assist].each do |d| teacher.teacher_assign_follows.build(staff_id: d) end teacher.department_id = department.id if params[:user_id].present? user = User.find(params[:user_id]) teacher.user_id = user.id teacher.regist_at = user.created_on else teacher.regist_at = Time.now end unless params[:activity_id].present? return render json: {msg: '该教师已存在', success: false } if EducodeSales::Teacher.find_by(department_id: params[:department_id],name: params[:name]) end if params[:activity_id].present? if params[:user_id].present? # 把老师添加到活动列表,提取判断下老师列表是否存在 find_teacher = Teacher.find_by(user_id: params[:user_id]) if find_teacher teacher = find_teacher end else _teacher = EducodeSales::Teacher.find_by(department_id: params[:department_id],name: params[:name]) teacher = _teacher if _teacher.present? end return render json: {msg: '该教师已在活动中', success: false } if teacher && teacher.activity_teachers.find_by(activity_id: params[:activity_id]).present? end if params[:activity_id].present? teacher.activity_teachers.build(activity_id: params[:activity_id]) end if teacher.save render_success else render_failure teacher end end |
#create_course ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 358 def create_course load_teacher names = params[:select_subject_names].split(",") begin names.each do |name| course_subject = @teacher.course_subjects.build(name: name, role_name: params[:role_name]) course_subject.save! end render_success rescue Exception => ex render_failure(ex.) end end |
#daily_paper ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 445 def daily_paper # 累计完成教师 @total_teachers_num = @current_admin.operation_plans.where("created_at >= ?", Time.now.beginning_of_month).distinct.count("teacher_id") @today_teacher_num = @current_admin.operation_plans.where("created_at >= ?", Time.now.beginning_of_day).distinct.count("teacher_id") user_ids = @current_admin.operation_plans.joins(:teacher).where("educode_sales_teachers.user_id IS NOT NULL").pluck(:user_id) @today_course_num = Course.joins(:course_members).where(course_members: {user_id: user_ids}).where("is_delete = 0 and role != 4 and excellent = 0 and is_hidden = 0").where("courses.created_at > ?", Time.now.beginning_of_day).count my_area = @current_admin.areas.pluck(:name) @total_users_num = UserExtension.joins(department: :school).where(schools: {province: my_area}).where("user_extensions.created_at > ?", Time.now.beginning_of_month).count @today_users_num = UserExtension.joins(department: :school).where(schools: {province: my_area}).where("user_extensions.created_at > ?", Time.now.beginning_of_day).count render layout: false end |
#delete_course ⇒ Object
381 382 383 384 385 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 381 def delete_course course_subject = CourseSubject.find(params[:id]) course_subject.destroy render_success end |
#destroy ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 314 def destroy if params[:activity_id].present? activity_teacher = ActivityTeacher.find_by(activity_id: params[:activity_id], teacher_id: params[:id]) activity_teacher.destroy else teacher = Teacher.find(params[:id]) teacher.destroy end render_success end |
#edit ⇒ Object
326 327 328 329 330 331 332 333 334 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 326 def edit load_teacher gon.teacher_assist = @teacher.teacher_assign_follows.map do |d| {value: d.staff_id, name: d.staff.user.full_name} end gon.department = { value: @teacher.department_id, name: "#{@teacher.department&.school&.name}-#{@teacher.department&.name}" } gon.value = @teacher.department_id render layout: false end |
#edit_follow_record ⇒ Object
425 426 427 428 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 425 def edit_follow_record @follow_up = TeacherFollow.find(params[:id]) render layout: false end |
#import ⇒ Object
240 241 242 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 240 def import render layout: false end |
#index ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 26 def index respond_to do |format| format.html do @areas = EducodeSales::Common.where(clazz: 'area').map{|d| {name: d.name, value: d.id}} common = Common.find_by(clazz: 'staff_type', name: '运营') role = EducodeSales::Role.find_by(name: '生态经理') if role @staff_manage = Staff.where(role_id: role.id).map { |d| [d.name, d.id]} else @staff_manage = Staff.none end @follow_upers = Staff.all.map { |d| [d.name, d.id]} @staffs = Staff.where(job_type: common.id).map { |d| [d.name, d.id]} @more = can?(:create, EducodeSales::OperationPlan) || can?(:update, EducodeSales::Teacher) || can?(:destroy, EducodeSales::Teacher) gon. = [] if can?(:create, EducodeSales::OperationPlan) gon. << { title: '添加周计划', event: 'week' } gon. << { title: '添加月计划', event: 'month' } end if can?(:update, EducodeSales::Teacher) gon. << { title: '编辑', event: 'edit' } end if can?(:destroy, EducodeSales::Teacher) gon. << { title: '删除', event: 'delete' } end filter = Filter.find_or_create_by(staff_id: @current_admin.id, clazz: "teachers") gon.filter = filter.extras || {} # if filter.extras.present? # # if filter.extras['area'].nil? # # filter.extras['area'] = 1 # # filter.extras['property'] = 1 # # filter.extras['sale_way'] = 1 # # end # # filter.save # gon.filter = filter.extras # else # gon.filter = {'area': 1, 'property': 1, 'sale_way': 1} # end end format.json do @staff_manages = {} @sales_manages = {} role = EducodeSales::Role.find_by(name: '生态经理') EducodeSales::Common.joins(market_areas: :staff).includes(market_areas: :staff).where(clazz: '区域').where("educode_sales_staffs.role_id = #{role.id}").each do |d| @staff_manages[d.name] = d.market_areas.map { |d| d.staff&.name }.uniq.compact end if role sales_common = EducodeSales::Common.find_by(clazz: 'staff_type', name: '销售') EducodeSales::Common.joins(market_areas: :staff).includes(market_areas: :staff).where(clazz: '区域').where("educode_sales_staffs.job_type = ?", sales_common.id).each do |d| @sales_manages[d.name] = d.market_areas.map { |d| d.staff&.user&.real_name }.uniq.compact end if @current_admin.is_admin? @teachers = Teacher else level = @current_admin.role.role_areas.find_by(clazz: '教师运营').level case level when '自己' @teachers = Teacher @teachers = @teachers.where(staff_id: @current_admin.id) teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.all.pluck(:Teacher_id) + EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id) + @teachers.ids @teachers = Teacher.where(id: teacher_ids) when '区域' school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id) @teachers = Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where("departments.school_id in (?) OR educode_sales_teachers.staff_id = #{@current_admin.id}", school_ids) teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.all.pluck(:Teacher_id) + EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id) + @teachers.ids @teachers = Teacher.where(id: teacher_ids) else @teachers = Teacher end end @teachers = @teachers.includes(department: [:department_majors, :school]) if @current_admin.job_type == Common.find_by(clazz: 'staff_type', name: '销售').id public_teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id) @teachers = @teachers.where.not(id: public_teacher_ids) end if params[:q].present? && params[:q][:assist].present? staff_id = params[:q][:assist].to_i teacher_ids = EducodeSales::TeacherAssignFollow.where(staff_id: staff_id).pluck(:teacher_id) @teachers = @teachers.where(id: teacher_ids) end if params[:q].present? && params[:q][:name].present? @teachers = @teachers.where("educode_sales_teachers.name like ?", "%#{params[:q][:name]}%") end if params[:q].present? && params[:q][:realname].present? @teachers = @teachers.where("educode_sales_teachers.realname like ?", "%#{params[:q][:realname]}%") end if params[:q].present? && params[:q][:professional_title].present? @teachers = @teachers.where("educode_sales_teachers.professional_title = ?", "#{params[:q][:professional_title]}") end if params[:q].present? && params[:q][:job].present? @teachers = @teachers.where("educode_sales_teachers.job = ?", "#{params[:q][:job]}") end # if params[:q].present? && params[:q][:regist_at].present? # @teachers = @teachers.where("educode_sales_teachers.regist_at like ?", "%#{params[:q][:regist_at]}%") # end if params[:q].present? && params[:q][:regist_at].present? date = params[:q][:regist_at].split(" - ") @teachers = @teachers.where("educode_sales_teachers.regist_at >= ? AND educode_sales_teachers.regist_at <= ?",date[0] + " 00:00:00", date[1] + " 23:59:59") end if params[:q].present? && params[:q][:status].present? if params[:q][:status] == "1" @teachers = @teachers.where("educode_sales_teachers.user_id is not null") else @teachers = @teachers.where("educode_sales_teachers.user_id is null") end end if params[:q].present? && params[:q][:mobile].present? @teachers = @teachers.joins(:user).where("users.phone like ?", "%#{params[:q][:mobile]}%") end if params[:q].present? && params[:q][:attitude].present? # @teachers = @teachers.where("educode_sales_teachers.attitude_id = ?", "#{params[:q][:attitude]}") @teachers = @teachers.joins(" JOIN educode_sales_teacher_follows ON educode_sales_teachers.follow_up_id = educode_sales_teacher_follows.id ").where("educode_sales_teacher_follows.attitude_id = ?", params[:q][:attitude]) end if params[:q].present? && params[:q][:teacher_source].present? @teachers = @teachers.where("educode_sales_teachers.source_id = ?", "#{params[:q][:teacher_source]}") end if params[:q].present? && params[:q][:school].present? departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:school]}%").pluck(:id) @teachers = @teachers.joins(:department).where("departments.id in (?)", departments_ids) end if params[:q].present? && params[:q][:area].present? p = EducodeSales::Common.where("id in (?)", params[:q][:area]).pluck(:name).uniq @teachers = @teachers.joins(" JOIN departments ON educode_sales_teachers.department_id = departments.id JOIN schools ON departments.school_id = schools.id ").where("province in (?)", p) end if params[:activity_id].present? if params[:school_id].present? @teachers = @teachers.joins(activity_teachers: [teacher: :department]).where("educode_sales_activity_teachers.activity_id = ? AND departments.school_id = ?", params[:activity_id], params[:school_id]) else @teachers = @teachers.joins(:activity_teachers).where("educode_sales_activity_teachers.activity_id = ?", params[:activity_id]) end end if params[:q].present? && params[:q][:date].present? date = params[:q][:date].split(" - ") @teachers = @teachers.where("educode_sales_teachers.created_at > ? AND educode_sales_teachers.created_at < ?", date[0], date[1]) end if params[:q].present? && params[:q][:staff_manage].present? staff = Staff.find(params[:q][:staff_manage]) school_ids = School.where(province: staff.areas.pluck(:name)).pluck(:id) assign_teacher_ids = EducodeSales::AssignStaff.where("educode_sales_assign_staffs.sourcable_type = 'EducodeSales::Teacher' and educode_sales_assign_staffs.staff_id = ?", params[:q][:staff_manage]).pluck(:sourcable_id) teacher_ids = EducodeSales::Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where("departments.school_id in (?)", school_ids).pluck(:id) + assign_teacher_ids @teachers = @teachers.where(id: teacher_ids) end if params[:q].present? && params[:q][:staff_id].present? @teachers = @teachers.select(" educode_sales_teachers.*, users.created_on, last_follow.created_at as latest_time, users.grade, users.experience, users.last_login_on").joins(" JOIN educode_sales_teacher_follows AS last_follow ON last_follow.id = educode_sales_teachers.follow_up_id AND last_follow.deleted_at IS NULL LEFT JOIN users ON educode_sales_teachers.user_id = users.id ") @teachers = @teachers.where("last_follow.staff_id = ?", params[:q][:staff_id].to_i) else @teachers = @teachers.select(" educode_sales_teachers.*, users.created_on, last_follow.created_at as latest_time, users.grade, users.experience, users.last_login_on").joins(" LEFT JOIN users ON educode_sales_teachers.user_id = users.id LEFT JOIN educode_sales_teacher_follows AS last_follow ON last_follow.id = educode_sales_teachers.follow_up_id AND last_follow.deleted_at IS NULL ") end if params[:q].present? && params[:q][:is_contact].present? @teachers = @teachers.where("last_follow.is_contact = ?", params[:q][:is_contact].to_i) end if params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'created_at' @teachers = @teachers.order("educode_sales_teachers.created_at #{params[:sort][:order]}") elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'last_login_on' @teachers = @teachers.order("users.last_login_on #{params[:sort][:order]}") elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'created_on' @teachers = @teachers.order("users.created_on #{params[:sort][:order]}") elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'latest_time' @teachers = @teachers.order("last_follow.created_at #{params[:sort][:order]}") elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'experience' @teachers = @teachers.order("users.experience #{params[:sort][:order]}") elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'grade' @teachers = @teachers.order("users.grade #{params[:sort][:order]}") elsif params[:sort].present? && params[:sort][:field] @teachers = @teachers.order("#{params[:sort][:field]} #{params[:sort][:order]}") else @teachers = @teachers.order("educode_sales_teachers.created_at desc") end @teachers = @teachers.includes(:teacher_assign_follows, :department, :user, :follow_up, :activity_teachers, [assign_staffs: :staff]) if params[:type].to_s == 'export' @teachers = @teachers.page(1).per(1000) else @teachers = @teachers.page(params[:page]).per(params[:limit]) end end end end |
#new ⇒ Object
244 245 246 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 244 def new render layout: false end |
#new_follow_record ⇒ Object
415 416 417 418 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 415 def new_follow_record @teacher = Teacher.find(params[:id]) render layout: false end |
#search_new ⇒ Object
346 347 348 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 346 def search_new render layout: false end |
#show_class ⇒ Object
411 412 413 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 411 def show_class render layout: false end |
#show_follow ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 392 def show_follow @teacher = Teacher.find(params[:id]) respond_to do |format| format.html do render layout: false end format.json do @follow_ups = @teacher.teacher_follows @latest = @follow_ups.order(created_at: :desc).first if params[:field] @follow_ups = @follow_ups.order("#{params[:field]} #{params[:order]}") else @follow_ups = @follow_ups.order("created_at desc") end @follow_ups = @follow_ups.page(params[:page]).per(params[:limit]) end end end |
#show_follow_record ⇒ Object
420 421 422 423 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 420 def show_follow_record @follow_up = TeacherFollow.find(params[:id]) render layout: false end |
#unfinish_plans ⇒ Object
336 337 338 339 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 336 def unfinish_plans load_teacher @plans = @teacher.operation_plans.where.not(finish_rate: 100).page(params[:page]).per(params[:limit]) end |
#update ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 291 def update department = Department.find(params[:department_id]) teacher = Teacher.find(params[:id]) teacher.department_id = department.id teacher.assign_attributes(teacher_params) teacher_assists = [] params[:teacher_assist].each do |d| teacher_assists << teacher.teacher_assign_follows.find_or_initialize_by(staff_id: d) end teacher.teacher_assign_follows = teacher_assists if params[:user_id].present? user = User.find(params[:user_id]) teacher.user_id = user.id end if teacher.save render_success else render_failure teacher end end |
#update_course ⇒ Object
372 373 374 375 376 377 378 379 |
# File 'app/controllers/educode_sales/teachers_controller.rb', line 372 def update_course course_subject = CourseSubject.find(params[:id]) if course_subject.update(name: params[:name], role_name: params[:role_name]) render_success else render_failure course_subject end end |