Module: EducodeSales::ApplicationHelper

Defined in:
app/helpers/educode_sales/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_businesses_score(staff_id, start_time, end_time) ⇒ Object

新增商机数 得分规则



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
# File 'app/helpers/educode_sales/application_helper.rb', line 84

def add_businesses_score(staff_id,start_time,end_time)
  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

  ids_a_b = Common.where(extras: %w[a_class b_class ]).pluck(:id)
  ids_c_d = Common.where(extras: %w[c_class d_class]).pluck(:id)
  @businesses_a_b_count = @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_a_b)
                               .where("educode_sales_businesses.staff_id = ?",staff_id)
                               .where("educode_sales_businesses.created_at >= ? and educode_sales_businesses.created_at <= ?", "#{@assessment_year}-#{start_time} 00:00:00".to_date,
                                            "#{@assessment_year}-#{end_time} 23:59:00".to_date)
  @businesses_c_d_count = @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_c_d)
                                     .where("educode_sales_businesses.staff_id = ?",staff_id)
                                     .where("educode_sales_businesses.created_at >= ? and educode_sales_businesses.created_at <= ?", "#{@assessment_year}-#{start_time} 00:00:00".to_date,
                                            "#{@assessment_year}-#{end_time} 23:59:00".to_date)
  @businesses_a_b_count.count.to_i*10  + @businesses_c_d_count.count.to_i*5
end

#base_urlObject



44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/educode_sales/application_helper.rb', line 44

def base_url
  url = Rails.application.config_for(:configuration)['wechat_pay']['callback_url']
  if url.include?("https://data.educoder")
    "https://www.educoder.net"
  elsif url.include?("'https://pre-data.educoder")
    "https://pre.educoder.net"
  else
    "https://test.educoder.net"
  end
end

#collection_amount_score(setting, progress) ⇒ Object

回款金额 得分规则



72
73
74
# File 'app/helpers/educode_sales/application_helper.rb', line 72

def collection_amount_score(setting,progress)
  (progress.to_i >= setting.to_i) ||  (setting.to_i == 0) ? 20:(progress.to_f/setting.to_f*20).round(2)
end

#completion_rate(setting, progress) ⇒ Object

完成率completion_rate



57
58
59
60
61
62
63
64
# File 'app/helpers/educode_sales/application_helper.rb', line 57

def completion_rate(setting,progress)
  if setting.to_i == 0 || progress.to_i >= setting.to_i
    '100%'
  else
    (progress.to_f/setting.to_f*100).round(2).to_s + "%"
  end

end

#current?(css, path) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
# File 'app/helpers/educode_sales/application_helper.rb', line 4

def current?(css, path)
  if path.is_a?(Array) ? (current_page?(path.first) || request.path == path.last) : current_page?(path)
    css
  else
    ' '
  end
end

#disk_filename(source_type, source_id, image_file = nil) ⇒ Object



32
33
34
# File 'app/helpers/educode_sales/application_helper.rb', line 32

def disk_filename(source_type,source_id,image_file=nil)
  File.join(storage_path, "#{source_type}", "#{source_id}")
end

#relative_pathObject



40
41
42
# File 'app/helpers/educode_sales/application_helper.rb', line 40

def relative_path
  "avatars"
end

#signed_amount_score(setting, progress) ⇒ Object

签单金额 得分规则



67
68
69
# File 'app/helpers/educode_sales/application_helper.rb', line 67

def signed_amount_score(setting,progress)
  progress.to_f >= setting.to_f || setting.to_i == 0 ? 40:(progress.to_f/setting.to_f*40).round(2)
end

#storage_pathObject



36
37
38
# File 'app/helpers/educode_sales/application_helper.rb', line 36

def storage_path
  File.join(Rails.root, "public", "images", relative_path)
end

#url_to_avatar(source) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/educode_sales/application_helper.rb', line 12

def url_to_avatar(source)
  return "" if source.blank?
  if File.exist?(disk_filename(source&.class, source&.id)) && File.file?(disk_filename(source&.class, source&.id))
    ctime = File.ctime(disk_filename(source&.class, source&.id)).to_i
    if source.class.to_s == 'User'
      File.join(relative_path, ["#{source&.class}", "#{source&.id}"]) + "?t=#{ctime}"
    else
      File.join("images/avatars", ["#{source&.class}", "#{source&.id}"]) + "?t=#{ctime}"
    end
  elsif source.class.to_s == 'User'
    str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g"
    File.join(relative_path, "#{source.class}", str)
  elsif source.class.to_s == 'Subject'
    File.join("images","educoder", "index", "subject", "subject#{rand(19)}.jpg")
  elsif source.class.to_s == 'Shixun'
    File.join("images","educoder", "index", "shixun", "shixun#{rand(23)}.jpg")
  end
end

#visits_score(d) ⇒ Object

拜访量 得分规则



78
79
80
# File 'app/helpers/educode_sales/application_helper.rb', line 78

def visits_score(d)
  d.to_i > 30 ? 20:0
end