Class: EducodeSales::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ApplicationHelper
Defined in:
app/controllers/educode_sales/application_controller.rb

Instance Method Summary collapse

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

#authenticate_adminObject



56
57
58
59
60
# File 'app/controllers/educode_sales/application_controller.rb', line 56

def authenticate_admin
  unless current_user&.is_admin
    redirect_to no_permission_path
  end
end

#authenticate_requestObject



48
49
50
51
52
53
54
# File 'app/controllers/educode_sales/application_controller.rb', line 48

def authenticate_request
  if current_user
    current_user.(request)
  else
    redirect_to 
  end
end

#current_userObject



44
45
46
# File 'app/controllers/educode_sales/application_controller.rb', line 44

def current_user
  @current_admin ||= Staff.find_by_id(session[:admin_id])
end

#filterObject



62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/educode_sales/application_controller.rb', line 62

def filter
  params[:check] = params[:check] == "true" ? 0:1
  begin
    filter = Filter.find_or_create_by!(staff_id: @current_admin.id, clazz: params[:type])
    filter.extras["#{params[:name]}"] = params[:check]
    filter.save!
    render json: {success: true ,hidden: params[:check]}
  rescue => e
    render_failure("操作失败")
  end
end

#is_commissioner_above?(clazz_type = "business") ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/educode_sales/application_controller.rb', line 8

def is_commissioner_above?(clazz_type="business")
  return true  if @current_admin.is_admin?
  case clazz_type
  when "business"
    can?(:all_business, EducodeSales::BusinessDeliverSubject)
  when "shixun"
    can?(:all_shixun, EducodeSales::BusinessDeliverSubject)
  when "subject"
    can?(:all_subject, EducodeSales::BusinessDeliverSubject)
  end
end

#paginate(relation) ⇒ Object



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

def paginate(relation)
  limit = params[:limit] || params[:per_page]
  limit  = (limit.to_i.zero? || limit.to_i > 100) ? 20 : limit.to_i
  page   = params[:page].to_i.zero? ? 1 : params[:page].to_i
  offset = (page - 1) * limit

  if relation.is_a?(Array)
    relation[offset, limit]
  else
    relation.limit(limit).offset(offset)
  end
end

#render_failure(msg) ⇒ Object



40
41
42
# File 'app/controllers/educode_sales/application_controller.rb', line 40

def render_failure(msg)
  render json: { success: false, msg: msg.is_a?(String) ? msg : msg.errors.full_messages.join(",") }, status: 403
end

#render_successObject



36
37
38
# File 'app/controllers/educode_sales/application_controller.rb', line 36

def render_success
  render json: { success: true }
end

#subject_membersObject



21
22
23
24
# File 'app/controllers/educode_sales/application_controller.rb', line 21

def subject_members
  common = Common.find_by(clazz: 'staff_type', name: '课程')
  @manages = Staff.joins(:user).where(job_type: common.id.to_i).where.not(role_id: 11).map { |d| {name: d.user.real_name, value: d.id}}
end

#subject_staffsObject



26
27
28
29
# File 'app/controllers/educode_sales/application_controller.rb', line 26

def subject_staffs
  common = Common.find_by(clazz: 'staff_type', name: '销售')
  @staffs = Staff.joins(:user).where(job_type: common.id).where.not(role_id: 11).map { |d| { value: d.id, name: d.name } }
end

#subject_urlObject



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

def subject_url
  @url =  "https://data.educoder.net"
  @admins_url = "https://data.educoder.net"
end