Class: EducodeSales::SalesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/educode_sales/sales_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

load_and_authorize_resource authorize_resource class: false



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/educode_sales/sales_controller.rb', line 8

def index
  authorize! :sales, Staff
  respond_to do |format|
    format.html do
      @year = params[:year] ? params[:year] : "全部"
      @years = ["全部"]+(2015..Time.now.year).to_a.reverse
    end
    format.json do
      @year = params[:year] ? params[:year] : "全部"
      common = Common.find_by(clazz: 'staff_type', name: '销售')
      @a_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name)
      @b_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name)
      @c_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::CTYPE)&.name)
      @d_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::DTYPE)&.name)
      @e_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::ETYPE)&.name)
      @o_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::OTYPE)&.name)
      @x = Common.find_by(extras: EducodeSales::Common::XTYPE)
      @step_ids = Common.where(name: %w(已中标 已签单 已验收 回款中 服务中 已结束), clazz: 'business_step').pluck(:id)
      
      @staffs = Staff.where(job_type: common.id).page(params[:page]).per(params[:limit])
    end
  end
end

#operationsObject



48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/educode_sales/sales_controller.rb', line 48

def operations
  authorize! :operations, Staff
  respond_to do |format|
    format.html do
    end
    format.json do
      common_id = Common.where(clazz: 'staff_type', name: ['销售', '运营']).pluck(:id)
      @staffs = Staff.where(job_type: common_id).page(params[:page]).per(params[:limit])
    end
  end
end


38
39
40
41
42
43
44
45
46
# File 'app/controllers/educode_sales/sales_controller.rb', line 38

def sale_trends
  authorize! :sale_trends, SaleTrend
  sale_trend = SaleTrend.find_by(year: params[:year])
  if sale_trend.update(sale_trend_params)
    render_success
  else
    render_failure sale_trend
  end
end

#schoolObject



60
61
62
# File 'app/controllers/educode_sales/sales_controller.rb', line 60

def school
  render layout: false
end


32
33
34
35
36
# File 'app/controllers/educode_sales/sales_controller.rb', line 32

def trends
  authorize! :trends, SaleTrend
  @year = params[:year] ? params[:year] : Time.now.year
  @sale_trend = SaleTrend.find_or_create_by(year: @year)
end

#xschoolObject



64
65
66
# File 'app/controllers/educode_sales/sales_controller.rb', line 64

def xschool
  render layout: false
end