Class: EducodeSales::AssessmentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- EducodeSales::AssessmentsController
- Defined in:
- app/controllers/educode_sales/assessments_controller.rb
Instance Method Summary collapse
-
#attendances ⇒ Object
签到记录.
-
#batch_delete ⇒ Object
批量删除签到记录.
-
#busniness_add ⇒ Object
新增商机数.
-
#busniness_jurisdiction ⇒ Object
busniness 权限.
-
#collection_count ⇒ Object
回款金额 权限.
-
#count_data(data_list, data_count) ⇒ Object
将统计到的数据转入a中.
-
#create ⇒ Object
新增.
-
#customer_and_busniness_visits ⇒ Object
拜访量.
-
#delete_attendance ⇒ Object
删除签到记录.
-
#destroy ⇒ Object
删除接口.
-
#edit ⇒ Object
编辑.
-
#edit_attendance ⇒ Object
编辑签到记录界面.
- #finished ⇒ Object
-
#get_export_data ⇒ Object
导出数据.
-
#import ⇒ Object
跳转导入界面.
-
#import_attendances ⇒ Object
导入签到记录接口.
- #index ⇒ Object
- #new ⇒ Object
-
#progress ⇒ Object
考核完成情况.
-
#progress_main ⇒ Object
todo 主方法 统计用户的数据.
- #progress_or_get_export_data ⇒ Object
-
#signed_count ⇒ Object
签单金额.
-
#update ⇒ Object
根新.
-
#update_assessments_progress(data_count, staff_id) ⇒ Object
更新assessments_settings表中数据.
-
#update_attendance ⇒ Object
更新签到记录信息.
-
#visits ⇒ 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
#attendances ⇒ Object
签到记录
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 386 def attendances respond_to do |format| format.html do end format.js do end format.json do @attendances = EducodeSales::Attendance if params[:q].present? && params[:q][:name].present? @attendances = @attendances.where("name like ?", "%#{params[:q][:name].strip}%") end if params[:q].present? && params[:q][:attendance_date].present? date = params[:q][:attendance_date].split(" - ") @attendances = @attendances.where("attendance_date >= ? and attendance_date <= ?", date[0] + ' 00:00:00', date[1] + ' 23:59:59') end if params[:q].present? && params[:q][:customer].present? @attendances = @attendances.where("customer like ?", "%#{params[:q][:customer]}%") end @attendances = @attendances.page(params[:page]).per(params[:limit]) end end end |
#batch_delete ⇒ Object
批量删除签到记录
444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 444 def batch_delete begin ActiveRecord::Base.transaction do if params[:ids].present? ids = params[:ids] attendances = EducodeSales::Attendance.where(id: ids) attendances.destroy_all end end render_success rescue Exception => e render_failure(e.) end end |
#busniness_add ⇒ Object
新增商机数
319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 319 def busniness_add @businesses = @businesses.where("educode_sales_businesses.created_at >= ? and educode_sales_businesses.created_at <= ?", "#{@assessment_year}-01-01 00:00:00","#{@assessment_year}-12-31 23:59:59") ids = Common.where(extras: %w[a_class b_class c_class d_class]).pluck(:id) @businesses = @businesses.joins("JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id").where("educode_sales_follow_ups.clazz_id in (?) ",ids) @staff_ids.each do |d| businesses = @businesses.where(staff_id: d) data_count = [] data_list = businesses.map do |m| {date: m.created_at.to_s[5..6].to_i, value: 1} end count_data(data_list,data_count) # 统计数据 update_assessments_progress(data_count, d) # 批量更新assessment数据 事物 一个commit end end |
#busniness_jurisdiction ⇒ Object
busniness 权限
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 336 def busniness_jurisdiction # busniness 权限 if @current_admin.is_admin? @businesses = Business.all else level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level case level when '自己' # Business.joins(Business字段: :表的名称)----> Business表(belongs_to) Business字段关联的表(has_many) Business字段关联的表在关联的表(belongs_to) business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id) @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids) when '区域' school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id) business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id) @businesses = Business.joins("JOIN departments ON educode_sales_businesses.department_id = departments.id").where("departments.school_id in (?) OR educode_sales_businesses.staff_id = #{@current_admin.id} OR educode_sales_businesses.id in (?)", school_ids, business_ids) else @businesses = Business.all end end end |
#collection_count ⇒ Object
回款金额 权限
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 235 def collection_count follow_up_ids = Business.pluck(:last_follow_up_id) if @current_admin.is_admin? @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids) else level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level case level when '自己' @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id) when '区域' a_ids = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id).pluck(:follow_up_id) school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id) b_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id) ids = a_ids + b_ids @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: ids) else @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids) end end # todo 1 :实际回款 0:计划回款 where(clazz: 1 OR 实际回款 ) @money_plans = @money_plans.where(clazz: 1).where.not(date_at: nil) @staff_ids.each do |d| data_count = [] data_list = @money_plans.where(staff_id: d).map do |m| {date:m.date_at.to_s[5..6].to_i, value:m.amount.to_f} end count_data(data_list,data_count) update_assessments_progress(data_count, d) end end |
#count_data(data_list, data_count) ⇒ Object
将统计到的数据转入a中
374 375 376 377 378 379 380 381 382 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 374 def count_data(data_list,data_count) data_list.each do |d| if data_count[d[:date]-1].present? data_count[d[:date]-1] = data_count[d[:date]-1] + d[:value] else data_count[d[:date]-1] = d[:value] end end end |
#create ⇒ Object
新增
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 93 def create begin assessment = AssessmentsSetting.new(params_create) assessment.user_id = current_user.user_id assessment.total_score = (params[:first_quarter_score].to_f + params[:second_quarter_score].to_f + params[:third_quarter_score].to_f + params[:fourth_quarter_score].to_f).round(2) assessment.assessment_year = "#{params[:assessment_year]}-01-01" AssessmentsSetting.transaction do params[:staffs_ids].split(",").each do |d| staff = assessment.dup staff.staff_id = d.to_i staff.save end end render_success rescue => e render_failure '增加数据错误' end end |
#customer_and_busniness_visits ⇒ Object
拜访量
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 295 def customer_and_busniness_visits @staff_ids.each do |m| customers = @customers.where(id: EducodeSales::CustomerExtension.where(customer_staff_id: m).pluck(:school_id)) data_list = [] data_count = [] CustomerFollow.joins(:school).where(school_id: customers.pluck(:id)) .where("Educode_Sales_customer_follows.created_at >= ? and Educode_Sales_customer_follows.created_at <= ?","#{@assessment_year}-01-01 ","#{@assessment_year}-12-31 23:59:59" ) .each do |d| data_list << {value: 1, date: d.created_at.to_s[5..6].to_i} end FollowUp.joins(:business).where("Educode_Sales_businesses.id in (?)",EducodeSales::Business.where(school_id: customers.pluck(:id)).pluck(:id)) .where("Educode_Sales_follow_ups.created_at >= ? and Educode_Sales_follow_ups.created_at <= ?","#{@assessment_year}-01-01 00:00:00", "#{@assessment_year}-12-31 23:59:59").each do |d| data_list << {date: d.created_at.to_s[5..6].to_i, value: 1} end count_data(data_list,data_count) assessment = @assessments.where(staff_id: m) update_assessments_progress(data_count, assessment) end end |
#delete_attendance ⇒ Object
删除签到记录
426 427 428 429 430 431 432 433 434 435 436 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 426 def delete_attendance begin ActiveRecord::Base.transaction do attendance = EducodeSales::Attendance.find(params[:id]) attendance.destroy! render_success end rescue Exception => e render_failure(e.) end end |
#destroy ⇒ Object
删除接口
135 136 137 138 139 140 141 142 143 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 135 def destroy begin assessment = AssessmentsSetting.find(params[:id]) assessment.destroy render_success rescue => e render_failure '暂不能删除' end end |
#edit ⇒ Object
编辑
117 118 119 120 121 122 123 124 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 117 def edit @assessment = AssessmentsSetting.find_by(id: params[:id]) @username = @assessment.staff.user.real_name @year = @assessment.assessment_year.to_s[0..3] @assessment_name = EducodeSales::AssessmentsSetting::CLAZZ[@assessment.assessment] render layout: false end |
#edit_attendance ⇒ Object
编辑签到记录界面
410 411 412 413 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 410 def edit_attendance @attendance = EducodeSales::Attendance.find(params[:id]) render layout: false end |
#finished ⇒ Object
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 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 56 def finished @year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year] : Time.now.year EducodeSales::AssessmentsSetting.update_stats(@year, params[:assessment_id]) if @current_admin.is_admin? @assessments = AssessmentsSetting.all else level = @current_admin.role.role_areas.find_by(clazz: '绩效考核').level case level when '自己' @assessments = AssessmentsSetting.where(staff_id: @current_admin.id) when '区域' @staffs = EducodeSales::Staff.joins(:areas).where("educode_sales_commons.id in (?)", @current_admin.areas.pluck(:id)).distinct @assessments = EducodeSales::AssessmentsSetting.where(staff_id: @staffs.select(:id)) else @assessments = AssessmentsSetting.all end end if params[:assessment_year].present? @assessments = @assessments.where(assessment_year: Time.new(params[:assessment_year])..Time.new(params[:assessment_year]).end_of_year) end if params[:assessment_id].present? @assessments = @assessments.where(assessment: params[:assessment_id]) end if params[:staff_id].present? @assessments = @assessments.where(staff_id: params[:staff_id]) end @assessments = @assessments.order("created_at desc") end |
#get_export_data ⇒ Object
导出数据
146 147 148 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 146 def get_export_data p 'get_export_data' end |
#import ⇒ Object
跳转导入界面
439 440 441 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 439 def import render layout: false end |
#import_attendances ⇒ Object
导入签到记录接口
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 460 def import_attendances render_failure("文件不存在或格式错误") if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile) doc = SimpleXlsxReader.open(params[:file].to_io) size = doc.sheets.size attendance_attrs = %i[name attendance_date longitude latitude location address mobile_id ip_address customer target created_at updated_at] attendance_vales = [] (0..size - 1).each do |index| doc.sheets[index].rows.each_with_index do |d, i| next if i <= 2 name = d[0] attendance_date_time = "#{d[1]} #{d[2]}" attendance_date = attendance_date_time.strip longitude = d[3] latitude = d[4] location = d[5] address = d[6] mobile_id = d[7] ip_address = d[8] if d[9].blank? school_college_name = d[5].split("学院")[0] school_university_name = d[5].split("大学")[0] + "大学" school = School.where("name like ?", "%#{school_college_name}%").first school01 = School.where("name like ?", "%#{school_university_name}%").first if school.present? customer = school.name elsif school01.present? customer = school01.name else customer = "" end else customer = d[9] end target = d[10] attendance_vales << {name: name, attendance_date: attendance_date, longitude: longitude, latitude: latitude, location: location, address: address, mobile_id: mobile_id, ip_address: ip_address, customer: customer, target: target} end end EducodeSales::Attendance.bulk_insert(*attendance_attrs) do |worker| attendance_vales.each do |attendance| worker.add(name: attendance[:name], attendance_date: attendance[:attendance_date].to_datetime, longitude: attendance[:longitude], latitude: attendance[:latitude], location: attendance[:location], address: attendance[:address], mobile_id: attendance[:mobile_id], ip_address: attendance[:ip_address], customer: attendance[:customer], target: attendance[:target]) end end render_success end |
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 8 def index respond_to do |format| format.html do gon.assement_list = EducodeSales::AssessmentsSetting::CLAZZ.map { |d, i| {value: d, name: i } } common = Common.find_by(clazz: 'staff_type', name: '销售') @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]} # [[], [], ............] # 导出 gon. = [] gon. << { title: '导出到Csv文件', event: 'export_csv' } gon. << { title: '导出到Excel文件', event: 'export_excel' } # index页面new弹出层下使用 gon.staff_ids = Staff.joins(:user).where(job_type: common.id).map do |d| {value: d.id, name: d.user.real_name } end filter = Filter.find_or_create_by(staff_id: @current_admin.id, clazz: "assessments_setup") if filter.extras.present? gon.filter = filter.extras else gon.filter = {} end end format.json do if @current_admin.is_admin? @assessments = AssessmentsSetting.all else level = @current_admin.role.role_areas.find_by(clazz: '绩效考核').level case level when '自己' @assessments = AssessmentsSetting.where(staff_id: @current_admin.id) when '区域' @staffs = EducodeSales::Staff.joins(:areas).where("educode_sales_commons.id in (?)", @current_admin.areas.pluck(:id)).distinct @assessments = EducodeSales::AssessmentsSetting.where(staff_id: @staffs.select(:id)) else @assessments = AssessmentsSetting.all end end @year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year]:Time.now.year # @assessments_id = params[:q].present? && params[:q][:assessment_id].present? ? params[:q][:assessment_id]: '1' @assessments = @assessments.where("assessment_year >= ? and assessment_year <= ?", "#{@year}-01-01 00:00:00".to_date, "#{@year}-12-31 23:59:00".to_date) @assessments = @assessments.where(assessment: params[:q][:assessment_id]) if params[:q].present? && params[:q][:assessment_id].present? if params[:q].present? && params[:q][:staff_id].present? @assessments = @assessments.where(staff_id: params[:q][:staff_id]) end @assessments = @assessments.page(params[:page]).per(params[:limit]).order("created_at desc") end end end |
#new ⇒ Object
112 113 114 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 112 def new render layout: false end |
#progress ⇒ Object
考核完成情况
151 152 153 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 151 def progress p 'progress' end |
#progress_main ⇒ Object
todo 主方法 统计用户的数据
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 190 def progress_main case @assessment_id when '1' # 签单金额 busniness_jurisdiction signed_count when '2' # 回款金额 collection_count when '3' # 拜访量 visits customer_and_busniness_visits when '4' # 新增商机数 busniness_jurisdiction busniness_add end end |
#progress_or_get_export_data ⇒ Object
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 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 157 def progress_or_get_export_data if @current_admin.is_admin? @assessments = AssessmentsSetting.all else level = @current_admin.role.role_areas.find_by(clazz: '绩效考核').level case level when '自己' @assessments = AssessmentsSetting.where(staff_id: @current_admin.id) when '区域' @staffs = EducodeSales::Staff.joins(:areas).where("educode_sales_commons.id in (?)", @current_admin.areas.pluck(:id)).distinct @assessments = EducodeSales::AssessmentsSetting.where(staff_id: @staffs.select(:id)) else @assessments = AssessmentsSetting.all end end # common = Common.find_by(clazz: 'staff_type', name: '销售') # @staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id) @assessment_id = params[:q].present? && params[:q][:assessment_id].present? ? params[:q][:assessment_id]:'1' @assessment_year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year] : Time.now.year @assessments =@assessments.where(assessment: @assessment_id) .where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date) .order("created_at desc") if @assessments.present? # 小优化 @staff_ids = params[:q].present? && params[:q][:staff_id].present? ? [params[:q][:staff_id].to_i]:@assessments.distinct.pluck(:staff_id) progress_main # 注意一下 @assessments = @assessments.where(staff_id: @staff_ids) end end |
#signed_count ⇒ Object
签单金额
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 209 def signed_count # 过滤x类商机 ids = Common.where.not(extras: %w[x_class]).pluck(:id) @businesses = @businesses.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id in (?) ",ids) .where("educode_sales_follow_ups.signed_date >= ? and educode_sales_follow_ups.signed_date <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:59".to_date) # 得到最新阶段为已签单商机 s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id) @businesses = @businesses.joins(" JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id ").where("educode_sales_follow_ups.stage_id IN (?)",s_stage_ids) @staff_ids.each do |d| # 注意 businesses = @businesses.where(staff_id: d) data_count=[] data_list = FollowUp.joins("JOIN educode_sales_businesses ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id") .where("educode_sales_businesses.id in (?)",businesses.pluck(:id)).map do |m| {value: m.actual_amount.to_f, date:m.signed_date.to_s[5..6].to_i} end count_data(data_list,data_count) # 统计数据 update_assessments_progress(data_count,d) # 批量更新assessment数据 事物 一个commit end end |
#update ⇒ Object
根新
127 128 129 130 131 132 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 127 def update @assessment = AssessmentsSetting.find_by(id: params[:id]) @assessment.total_score = (params[:first_quarter_score].to_f + params[:second_quarter_score].to_f + params[:third_quarter_score].to_f + params[:fourth_quarter_score].to_f).round(2) @assessment.update_attributes(params_update) render_success end |
#update_assessments_progress(data_count, staff_id) ⇒ Object
更新assessments_settings表中数据
359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 359 def update_assessments_progress(data_count,staff_id) data_count[12] = data_count[0].to_f + data_count[1].to_f + data_count[2].to_f data_count[13] = data_count[3].to_f + data_count[4].to_f + data_count[5].to_f data_count[14] = data_count[6].to_f + data_count[7].to_f + data_count[8].to_f data_count[15] = data_count[9].to_f + data_count[10].to_f + data_count[11].to_f data_count[16] = data_count[12].to_f + data_count[13].to_f + data_count[14].to_f + data_count[15].to_f # 开启事物 处理 批量修改数据 assessments = @assessments.where(staff_id: staff_id) assessments.update(annual_progress: data_count[16], first_quarter_progress: data_count[12], second_quarter_progress: data_count[13], third_quarter_progress: data_count[14], fourth_quarter_progress: data_count[15], january_progress: data_count[0], february_progress: data_count[1], march_progress: data_count[2], april_progress: data_count[3], may_progress: data_count[4], june_progress: data_count[5], july_progress: data_count[6], august_progress: data_count[7], september_progress: data_count[8], october_progress: data_count[9], november_progress: data_count[10], december_progress: data_count[11]) end |
#update_attendance ⇒ Object
更新签到记录信息
416 417 418 419 420 421 422 423 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 416 def update_attendance ActiveRecord::Base.transaction do @attendance = EducodeSales::Attendance.find(params[:id]) @attendance.attendance_date = params[:attendance_datetime] @attendance.update_attributes(attendance_update) render_success end end |
#visits ⇒ Object
权限获取拜访量
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'app/controllers/educode_sales/assessments_controller.rb', line 269 def visits if @current_admin.is_admin? @customers = School.all else level = @current_admin.role.role_areas.find_by(clazz: '客户管理').level case level when '自己' school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id) @customers = School.where(id: school_ids) when '区域' a_school_ids = School.where(province: @current_admin.areas.pluck(:name)).ids b_school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id) school_ids = a_school_ids + b_school_ids + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id) @customers = School.where(id: school_ids) else @customers = School.all end end part_a_ids = CustomerFollow.all.pluck(:school_id) part_b_ids = Business.where(id: EducodeSales::FollowUp.pluck(:business_id)).pluck(:school_id) ids = part_a_ids + part_b_ids + CustomerAdd.all.pluck(:school_id) @customers = @customers.where(id: ids) end |