educode_sales 1.10.48 → 1.10.58
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/educode_sales/modules/easyeditor/easyeditor.css +130 -0
- data/app/assets/stylesheets/educode_sales/modules/easyeditor/fangge-style.css +4 -0
- data/app/controllers/educode_sales/application_controller.rb +22 -0
- data/app/controllers/educode_sales/business_courses_controller.rb +255 -0
- data/app/controllers/educode_sales/businesses_controller.rb +43 -7
- data/app/controllers/educode_sales/contracts_controller.rb +6 -0
- data/app/controllers/educode_sales/home_controller.rb +7 -0
- data/app/controllers/educode_sales/money_plan_records_controller.rb +6 -2
- data/app/controllers/educode_sales/money_plans_controller.rb +3 -0
- data/app/controllers/educode_sales/sale_trends_controller.rb +1 -1
- data/app/controllers/educode_sales/shixun_dectects_controller.rb +172 -0
- data/app/controllers/educode_sales/shixuns_controller.rb +218 -0
- data/app/controllers/educode_sales/subject_trends_controller.rb +144 -0
- data/app/controllers/educode_sales/subjects_controller.rb +213 -0
- data/app/helpers/educode_sales/application_helper.rb +10 -0
- data/app/helpers/educode_sales/business_courses_helper.rb +60 -0
- data/app/helpers/educode_sales/sale_trends_helper.rb +52 -52
- data/app/helpers/educode_sales/subject_helper.rb +33 -0
- data/app/models/educode_sales/business.rb +22 -0
- data/app/models/educode_sales/business_deliver_subject.rb +49 -0
- data/app/models/educode_sales/business_subject.rb +68 -0
- data/app/models/educode_sales/business_subject_shixun.rb +75 -0
- data/app/models/educode_sales/business_subject_staff.rb +36 -0
- data/app/models/educode_sales/permission.rb +2 -1
- data/app/models/educode_sales/shixun_dectect.rb +12 -0
- data/app/views/educode_sales/business_courses/edit.html.erb +174 -0
- data/app/views/educode_sales/business_courses/index.html.erb +334 -0
- data/app/views/educode_sales/business_courses/index.json.jbuilder +16 -0
- data/app/views/educode_sales/business_courses/list_shixuns.html.erb +292 -0
- data/app/views/educode_sales/business_courses/list_shixuns.json.jbuilder +23 -0
- data/app/views/educode_sales/business_courses/list_subjects.html.erb +212 -0
- data/app/views/educode_sales/business_courses/list_subjects.json.jbuilder +17 -0
- data/app/views/educode_sales/business_courses/new.html.erb +237 -0
- data/app/views/educode_sales/businesses/index.html.erb +11 -9
- data/app/views/educode_sales/contracts/_list.html.erb +16 -1
- data/app/views/educode_sales/contracts/index.html.erb +5 -2
- data/app/views/educode_sales/contracts/list.js.erb +4 -1
- data/app/views/educode_sales/money_plan_records/_index.html.erb +21 -5
- data/app/views/educode_sales/money_plan_records/index.js.erb +4 -1
- data/app/views/educode_sales/money_plans/list.html.erb +6 -2
- data/app/views/educode_sales/sale_trends/_return_money_forecast.html.erb +1 -1
- data/app/views/educode_sales/sale_trends/_user_stat.html.erb +1 -1
- data/app/views/educode_sales/sale_trends/_visit_analysis.html.erb +1 -1
- data/app/views/educode_sales/sale_trends/return_money_forecast.js.erb +1 -1
- data/app/views/educode_sales/sale_trends/trends.html.erb +6 -6
- data/app/views/educode_sales/sale_trends/user_stat.js.erb +1 -1
- data/app/views/educode_sales/sale_trends/visit_analysis.js.erb +1 -1
- data/app/views/educode_sales/shixun_dectects/index.html.erb +516 -0
- data/app/views/educode_sales/shixun_dectects/index.json.jbuilder +23 -0
- data/app/views/educode_sales/shixun_dectects/markdown.html.erb +60 -0
- data/app/views/educode_sales/shixuns/edit.html.erb +208 -0
- data/app/views/educode_sales/shixuns/index.html.erb +723 -0
- data/app/views/educode_sales/shixuns/index.json.jbuilder +26 -0
- data/app/views/educode_sales/shixuns/new.html.erb +261 -0
- data/app/views/educode_sales/subject_trends/trends.html.erb +676 -0
- data/app/views/educode_sales/subjects/edit.html.erb +86 -0
- data/app/views/educode_sales/subjects/index.html.erb +285 -0
- data/app/views/educode_sales/subjects/index.json.jbuilder +16 -0
- data/app/views/educode_sales/subjects/list_shixuns.html.erb +354 -0
- data/app/views/educode_sales/subjects/list_shixuns.json.jbuilder +22 -0
- data/app/views/educode_sales/subjects/new.html.erb +254 -0
- data/app/views/layouts/educode_sales/application.html.erb +38 -0
- data/config/routes.rb +37 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +42 -7
- data/app/assets/images/educode_sales/indexlogo.png +0 -0
@@ -80,6 +80,9 @@ module EducodeSales
|
|
80
80
|
gon.edit_money_plan = can?(:update, EducodeSales::MoneyPlan)
|
81
81
|
gon.edit_money_plan_self = can?(:update_self, EducodeSales::MoneyPlan)
|
82
82
|
gon.staff_id = @current_admin.id
|
83
|
+
if params[:date_at].present? && params[:date_at] != '全部'
|
84
|
+
gon.date = Time.new(params[:date_at]).beginning_of_year.strftime("%Y-%m-%d") + " - " + Time.new(params[:date_at]).end_of_year.strftime("%Y-%m-%d")
|
85
|
+
end
|
83
86
|
end
|
84
87
|
|
85
88
|
end
|
@@ -943,7 +943,7 @@ module EducodeSales
|
|
943
943
|
staff_id = params[:staff_id] || nil
|
944
944
|
@forecast_count_range = params[:forecast_count_range] || "month"
|
945
945
|
forecast_default_dates = ("#{Time.now.year}-01-01".to_date.."#{Time.now.year}-#{Time.now.month}-01".to_date).map { |d| d.strftime("%Y-%m") }.uniq
|
946
|
-
sale_names = %w[
|
946
|
+
sale_names = %w[计划回款额 计划回款额-全部 实际回款额 实际回款额-累计 计划回款额-O类]
|
947
947
|
case @forecast_count_range
|
948
948
|
when "week"
|
949
949
|
# 年初第一天周数是0会导致周数重复计算
|
@@ -0,0 +1,172 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# 实践项目管理
|
4
|
+
module EducodeSales
|
5
|
+
class ShixunDectectsController < ApplicationController
|
6
|
+
before_action :subject_members, :subject_url
|
7
|
+
def index
|
8
|
+
authorize! :checkout, BusinessDeliverSubject
|
9
|
+
respond_to do |format|
|
10
|
+
format.html do
|
11
|
+
end
|
12
|
+
format.json do
|
13
|
+
# 默认显示为待审核的
|
14
|
+
index = 1
|
15
|
+
if params[:q].present? && params[:q][:index].present?
|
16
|
+
index = params[:q][:index].to_i
|
17
|
+
end
|
18
|
+
@shixun_dectects = BusinessSubjectShixun.left_joins(:shixun)
|
19
|
+
.left_joins(:school)
|
20
|
+
.joins(last_dectect: [reviewed_staff: :user])
|
21
|
+
|
22
|
+
if params[:q].present? && params[:q][:category].present? && params[:q][:category].to_i != 0
|
23
|
+
@shixun_dectects = @shixun_dectects.where(category: params[:q][:category])
|
24
|
+
end
|
25
|
+
if params[:q].present? && params[:q][:shixun_name].present?
|
26
|
+
@shixun_dectects = @shixun_dectects.where("shixuns.name like '%#{params[:q][:shixun_name]}%'")
|
27
|
+
end
|
28
|
+
|
29
|
+
case index
|
30
|
+
when 1 # 显示待审核的
|
31
|
+
@shixun_dectects = @shixun_dectects.where("dectect_type = 0")
|
32
|
+
|
33
|
+
when 2 # 显示已审核的
|
34
|
+
str = 'dectect_type = 1 or dectect_type = 2'
|
35
|
+
if params[:q].present? && params[:q][:dectect_type].present?
|
36
|
+
if params[:q][:dectect_type].to_i == 1
|
37
|
+
str = "dectect_type = 1"
|
38
|
+
elsif params[:q][:dectect_type].to_i == 2
|
39
|
+
str = "dectect_type = 2"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@shixun_dectects = @shixun_dectects.where(str)
|
43
|
+
else
|
44
|
+
render_failure("操作失败,index只能为1,2")
|
45
|
+
end
|
46
|
+
times = {}
|
47
|
+
BusinessSubjectShixun.includes(business_subject:[ business_deliver_subject: [:manages, business: [:school, last_follow_up: :assign_follow_ups]] ]).find_each do |d|
|
48
|
+
b_d_s = d.business_subject
|
49
|
+
if b_d_s.blank? || b_d_s.business.blank?
|
50
|
+
times.merge!({"#{d.id}": d.deliver_date })
|
51
|
+
elsif b_d_s.business.present?
|
52
|
+
times.merge!({ "#{d.id}": b_d_s.business.last_follow_up.reception_at })
|
53
|
+
end
|
54
|
+
end
|
55
|
+
@times = times.stringify_keys
|
56
|
+
@url
|
57
|
+
@shixun_dectects = @shixun_dectects.select("educode_sales_business_subject_shixuns.*,
|
58
|
+
schools.name as school_name,
|
59
|
+
shixuns.identifier,
|
60
|
+
educode_sales_business_subject_shixuns.name as shixun_name,
|
61
|
+
educode_sales_business_subject_shixuns.id as shixuns_id,
|
62
|
+
CONCAT(users.lastname, users.firstname) as real_name,
|
63
|
+
educode_sales_shixun_dectects.dectect_type,
|
64
|
+
educode_sales_shixun_dectects.content")
|
65
|
+
.page(params[:page])
|
66
|
+
.per(params[:limit])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
# 审核提交
|
73
|
+
def submit
|
74
|
+
authorize! :checkout, BusinessDeliverSubject
|
75
|
+
respond_to do |format|
|
76
|
+
format.json do
|
77
|
+
ActiveRecord::Base.transaction do
|
78
|
+
@shixuns = ShixunDectect.order(created_at: :desc).find_by(business_subject_shixun_id: params[:id])
|
79
|
+
if @shixuns.blank?
|
80
|
+
@shixuns = ShixunDectect.create!(business_subject_shixun_id: params[:id],
|
81
|
+
reviewed_id: current_user.id,
|
82
|
+
dectect_type: 0)
|
83
|
+
BusinessSubjectShixun.find(params[:id]).update(shixun_dectect_id: @shixuns.id,
|
84
|
+
shixun_status:4)
|
85
|
+
render_success
|
86
|
+
elsif @shixuns.present? && @shixuns.dectect_type == 'agreed'
|
87
|
+
@shixuns = ShixunDectect.create!(business_subject_shixun_id: params[:id],
|
88
|
+
reviewed_id: current_user.id,
|
89
|
+
dectect_type: 0)
|
90
|
+
BusinessSubjectShixun.find(params[:id]).update(shixun_dectect_id: @shixuns.id,
|
91
|
+
shixun_status:4)
|
92
|
+
render_success
|
93
|
+
else
|
94
|
+
render_failure("已经提交过了")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# 通过审核
|
102
|
+
def examine
|
103
|
+
authorize! :checkout, BusinessDeliverSubject
|
104
|
+
ActiveRecord::Base.transaction do
|
105
|
+
if params[:id].present? && params[:type].present?
|
106
|
+
business_subject_shixun = BusinessSubjectShixun.find(params[:id])
|
107
|
+
if business_subject_shixun.present? && business_subject_shixun.last_dectect.present?
|
108
|
+
|
109
|
+
shixun_dectect = business_subject_shixun.last_dectect
|
110
|
+
.update(reviewed_id: current_user.id,
|
111
|
+
date: Time.now,
|
112
|
+
content: params[:content].gsub(/\r\n?/, "\n").strip,
|
113
|
+
business_subject_shixun_id: params[:id],
|
114
|
+
dectect_type: params[:type].to_i)
|
115
|
+
if params[:type].to_i == 2
|
116
|
+
business_subject_shixun.update( shixun_status: 5)
|
117
|
+
elsif params[:type].to_i == 1
|
118
|
+
# 审核通过
|
119
|
+
business_subject_shixun.update( shixun_status: 9)
|
120
|
+
end
|
121
|
+
arrs = []
|
122
|
+
user_list = business_subject_shixun.all_staff.map{ |item| item.id}
|
123
|
+
|
124
|
+
user_list.each do |item|
|
125
|
+
attr = {
|
126
|
+
user_id: item,
|
127
|
+
trigger_user_id: 0,
|
128
|
+
container_id: business_subject_shixun.shixun_dectect_id.to_i,
|
129
|
+
container_type: 'EducodeSales::ShixunDectect',
|
130
|
+
tiding_type: "Project",
|
131
|
+
belong_container_type: "User",
|
132
|
+
belong_container_id: item,
|
133
|
+
created_at: Time.now,
|
134
|
+
updated_at: Time.now
|
135
|
+
}
|
136
|
+
arrs << attr
|
137
|
+
end
|
138
|
+
Tiding.create!(arrs)
|
139
|
+
|
140
|
+
end
|
141
|
+
render_success
|
142
|
+
else
|
143
|
+
render_failure("操作失败")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# 审核拒绝通过
|
149
|
+
|
150
|
+
def edit
|
151
|
+
authorize! :checkout, BusinessDeliverSubject
|
152
|
+
render layout: false
|
153
|
+
end
|
154
|
+
|
155
|
+
def update
|
156
|
+
authorize! :checkout, BusinessDeliverSubject
|
157
|
+
end
|
158
|
+
|
159
|
+
def new
|
160
|
+
authorize! :checkout, BusinessDeliverSubject
|
161
|
+
render layout: false
|
162
|
+
end
|
163
|
+
|
164
|
+
def create
|
165
|
+
end
|
166
|
+
|
167
|
+
def markdown
|
168
|
+
authorize! :checkout, BusinessDeliverSubject
|
169
|
+
render layout: false
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# 实践项目管理
|
4
|
+
module EducodeSales
|
5
|
+
class ShixunsController < ApplicationController
|
6
|
+
before_action :subject_members, :subject_staffs, :create_filter, :subject_url
|
7
|
+
def index
|
8
|
+
|
9
|
+
authorize! :shixun, BusinessDeliverSubject
|
10
|
+
|
11
|
+
# 判断类型是否存在 1 管培 2 全职 3 专职 如果不存在就默认为1
|
12
|
+
category = params[:q].present? ? params[:q][:category].to_i : BusinessSubjectShixun::CATEGORY_TYPE::TRAINING
|
13
|
+
trends_category = params[:trends_category]
|
14
|
+
|
15
|
+
gon.category = trends_category.present? ? trends_category.to_i : 1
|
16
|
+
gon.is_admin = is_commissioner_above?
|
17
|
+
|
18
|
+
business_subject_shixuns = BusinessSubjectShixun
|
19
|
+
|
20
|
+
# 根据身份获取对应数据
|
21
|
+
business_subject_shixuns = if is_commissioner_above?
|
22
|
+
business_subject_shixuns
|
23
|
+
else
|
24
|
+
# 实训本身的成员
|
25
|
+
smembers_ids = business_subject_shixuns.joins(shixun_members: :staff).where("educode_sales_staffs.id = #{@current_admin.id} ")
|
26
|
+
.ids
|
27
|
+
|
28
|
+
# 父类课程经理
|
29
|
+
deliver_ids = business_subject_shixuns.joins(business_subject: [business_deliver_subject: [manages: :staff]])
|
30
|
+
.where("educode_sales_staffs.id = #{@current_admin.id} ")
|
31
|
+
.ids
|
32
|
+
|
33
|
+
subject_ids = business_subject_shixuns.joins(business_subject: [manages: :staff])
|
34
|
+
.where("educode_sales_business_subjects.business_id is null and educode_sales_staffs.id = #{@current_admin.id} ")
|
35
|
+
.ids
|
36
|
+
|
37
|
+
business_subject_shixuns.where(id: smembers_ids + deliver_ids + subject_ids)
|
38
|
+
end
|
39
|
+
|
40
|
+
@shixuns = business_subject_shixuns.left_joins(:last_dectect)
|
41
|
+
.left_joins(:school, :shixun , business_subject: [:subject, business: :last_follow_up])
|
42
|
+
.where(category: category)
|
43
|
+
|
44
|
+
# if params[:q].present? && params[:q][:business_name].present?
|
45
|
+
# @shixuns = @shixuns.where("educode_sales_businesses.name like '%#{params[:q][:business_name]}%' ")
|
46
|
+
# end
|
47
|
+
|
48
|
+
# 项目级别 0 全部
|
49
|
+
if params[:q].present? && params[:q][:level].present? && params[:q][:level].to_i != 0
|
50
|
+
@shixuns = @shixuns.where(level: params[:q][:level])
|
51
|
+
end
|
52
|
+
# 项目状态 0 全部
|
53
|
+
if params[:q].present? && params[:q][:status].present? && params[:q][:status].to_i != 0
|
54
|
+
@shixuns = @shixuns.where(shixun_status: params[:q][:status])
|
55
|
+
end
|
56
|
+
if params[:q] && params[:q][:time].present?
|
57
|
+
start_time = params[:q][:time].split(" - ")[0]
|
58
|
+
end_time = params[:q][:time].split(" - ")[-1]
|
59
|
+
# @shixuns = @shixuns.where("educode_sales_follow_ups.reception_at BETWEEN '#{start_time}' AND '#{end_time}'
|
60
|
+
# or educode_sales_business_subject_shixuns.deliver_date BETWEEN '#{start_time}' AND '#{end_time}' ")
|
61
|
+
@shixuns = @shixuns.where("educode_sales_follow_ups.reception_at BETWEEN '#{start_time}' AND '#{end_time}'")
|
62
|
+
end
|
63
|
+
if params[:q].present? && params[:q][:shixun_name].present?
|
64
|
+
@shixuns = @shixuns.where("educode_sales_business_subject_shixuns.name like '%#{params[:q][:shixun_name]}%'")
|
65
|
+
end
|
66
|
+
if params[:q].present? && params[:q][:subject_name].present?
|
67
|
+
@shixuns = @shixuns.where("subjects.name like '%#{params[:q][:subject_name]}%'")
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
shixun_staffs = {}
|
72
|
+
BusinessSubjectShixun.includes(business_subject:[ business_deliver_subject: [:manages, business: [:school, last_follow_up: :assign_follow_ups]] ]).find_each do |d|
|
73
|
+
b_d_s = d.business_subject
|
74
|
+
if b_d_s.blank?
|
75
|
+
shixun_staffs.merge!({"#{d.id}": d.shixun_staff })
|
76
|
+
elsif b_d_s.present? && b_d_s.business_deliver_subject.present?
|
77
|
+
shixun_staffs.merge!({ "#{d.id}": b_d_s.business_deliver_subject.business.staff_name })
|
78
|
+
elsif b_d_s.present?
|
79
|
+
shixun_staffs.merge!({ "#{d.id}": b_d_s.staffs_name })
|
80
|
+
end
|
81
|
+
end
|
82
|
+
@shixun_staffs = shixun_staffs.stringify_keys
|
83
|
+
p @shixun_staffs
|
84
|
+
@shixuns = @shixuns.select("educode_sales_business_subject_shixuns.*,
|
85
|
+
educode_sales_follow_ups.reception_at,
|
86
|
+
schools.name as school_name,
|
87
|
+
subjects.name as subject_name,
|
88
|
+
subjects.identifier as subjects_identifier,
|
89
|
+
shixuns.name as shixun_name,
|
90
|
+
shixuns.identifier as s_identifier,
|
91
|
+
educode_sales_shixun_dectects.created_at as shixun_dectects_time,
|
92
|
+
educode_sales_shixun_dectects.content as dectects_content,
|
93
|
+
shixuns.identifier")
|
94
|
+
.page(params[:page])
|
95
|
+
.per(params[:limit])
|
96
|
+
end
|
97
|
+
|
98
|
+
def edit
|
99
|
+
authorize! :shixun, BusinessDeliverSubject
|
100
|
+
@item = BusinessSubjectShixun.find(params[:id])
|
101
|
+
@last_dectect = ''
|
102
|
+
if @item.last_dectect.present?
|
103
|
+
@last_dectect = @item.last_dectect.dectect_type
|
104
|
+
end
|
105
|
+
@producer_list = BusinessSubjectStaff.where(container_type: BusinessSubjectStaff::CONTAINER_TYPES::SHIXUN,
|
106
|
+
container_id: params[:id],
|
107
|
+
category: BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_PRODUCER)
|
108
|
+
.select(:staff_id)
|
109
|
+
.map { |item| item[:staff_id] }
|
110
|
+
|
111
|
+
@manage_list = BusinessSubjectStaff.where(container_type: BusinessSubjectStaff::CONTAINER_TYPES::SHIXUN,
|
112
|
+
container_id: params[:id],
|
113
|
+
category: BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_MANAGE)
|
114
|
+
.select(:staff_id)
|
115
|
+
.map { |item| item[:staff_id] }
|
116
|
+
gon.staffs = @manages
|
117
|
+
render layout: false
|
118
|
+
end
|
119
|
+
|
120
|
+
def update
|
121
|
+
authorize! :shixun, BusinessDeliverSubject
|
122
|
+
ActiveRecord::Base.transaction do
|
123
|
+
|
124
|
+
if params[:id].present?
|
125
|
+
item = BusinessSubjectShixun.find(params[:id])
|
126
|
+
if item.present?
|
127
|
+
item.update!(category: params[:category],
|
128
|
+
level: params[:level],
|
129
|
+
deliver_money: params[:money],
|
130
|
+
shixun_status: params[:status],
|
131
|
+
deliver_date: params[:time],
|
132
|
+
shixun_type: params[:type])
|
133
|
+
item.staffs.where(category: BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_MANAGE).destroy_all
|
134
|
+
item.staffs.where(category: BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_PRODUCER).destroy_all
|
135
|
+
BusinessSubjectStaff.bulk_insert(:staff_id, :container_id, :container_type, :created_at, :updated_at, :category) do |d|
|
136
|
+
params[:manage_id].split(",").each do |m|
|
137
|
+
d.add [m.to_i, params[:id], BusinessSubjectStaff::CONTAINER_TYPES::SHIXUN, Time.now, Time.now, BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_MANAGE]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
BusinessSubjectStaff.bulk_insert(:staff_id, :container_id, :container_type, :created_at, :updated_at, :category) do |d|
|
141
|
+
params[:producer_id].split(",").each do |m|
|
142
|
+
d.add [m.to_i, params[:id], BusinessSubjectStaff::CONTAINER_TYPES::SHIXUN, Time.now, Time.now, BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_PRODUCER]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
render_success
|
147
|
+
else
|
148
|
+
render_failure("操作失败")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def new
|
154
|
+
authorize! :shixun, BusinessDeliverSubject
|
155
|
+
gon.manage = @manages
|
156
|
+
gon.staffs = @staffs
|
157
|
+
render layout: false
|
158
|
+
end
|
159
|
+
|
160
|
+
def create
|
161
|
+
authorize! :shixun, BusinessDeliverSubject
|
162
|
+
begin
|
163
|
+
ActiveRecord::Base.transaction do
|
164
|
+
|
165
|
+
attr = {
|
166
|
+
name: params[:name].to_s,
|
167
|
+
category: params[:category].to_i,
|
168
|
+
shixun_type: params[:type].to_i,
|
169
|
+
shixun_status: params[:status].to_i,
|
170
|
+
level: params[:level].to_i,
|
171
|
+
link: params[:link].to_s,
|
172
|
+
deliver_money: params[:money].to_s,
|
173
|
+
deliver_date: params[:time],
|
174
|
+
school_id: params[:school_id]
|
175
|
+
}
|
176
|
+
|
177
|
+
if params[:shixun_type].to_i == 1
|
178
|
+
# 目前支持名称关联实训
|
179
|
+
origin_shixun = Shixun.where(hidden: 0).find_by_name(params[:name].to_s)
|
180
|
+
attr = origin_shixun.blank? ? attr : attr.merge({shixun_id: origin_shixun.id})
|
181
|
+
end
|
182
|
+
shixun = BusinessSubjectShixun.create!(attr)
|
183
|
+
|
184
|
+
BusinessSubjectStaff.bulk_insert(:staff_id, :container_id, :container_type, :created_at, :updated_at, :category) do |d|
|
185
|
+
params[:manage_id].split(",").each do |m|
|
186
|
+
d.add [m.to_i, shixun.id, BusinessSubjectStaff::CONTAINER_TYPES::SHIXUN, Time.now, Time.now, BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_MANAGE]
|
187
|
+
end
|
188
|
+
end
|
189
|
+
BusinessSubjectStaff.bulk_insert(:staff_id, :container_id, :container_type, :created_at, :updated_at, :category) do |d|
|
190
|
+
params[:producer_id].split(",").each do |m|
|
191
|
+
d.add [m.to_i, shixun.id, BusinessSubjectStaff::CONTAINER_TYPES::SHIXUN, Time.now, Time.now, BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_PRODUCER]
|
192
|
+
end
|
193
|
+
end
|
194
|
+
BusinessSubjectStaff.bulk_insert(:staff_id, :container_id, :container_type, :created_at, :updated_at, :category) do |d|
|
195
|
+
params[:staff_id].split(",").each do |m|
|
196
|
+
d.add [m.to_i, shixun.id, BusinessSubjectStaff::CONTAINER_TYPES::SHIXUN, Time.now, Time.now, BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_STAFF]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
render_success
|
201
|
+
rescue => e
|
202
|
+
Rails.logger.error("操作失败:#{e}")
|
203
|
+
render_failure("操作失败")
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def create_filter
|
209
|
+
filter_data = { "school_name" => 0, "subject_name" => 0, "reception_at" => 0, "shixun_name" => 0, "level" => 0, "shixun_status" => 0,
|
210
|
+
"deliver_date" => 0, "commit_dectect_time" => 0, "dectect_feedback" => 0, "shixun_producer" => 0, "shixun_manages" => 0,
|
211
|
+
"max_manage"=> 0, "shixun_staff" => 0 }
|
212
|
+
filter = Filter.create_with(extras: filter_data).find_or_create_by(staff_id: @current_admin.id, clazz: "shixuns")
|
213
|
+
|
214
|
+
gon.filter = filter.extras
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require_dependency "educode_sales/application_controller"
|
2
|
+
|
3
|
+
module EducodeSales
|
4
|
+
class SubjectTrendsController < ApplicationController
|
5
|
+
# authorize_resource class: false
|
6
|
+
include SaleTrendsHelper
|
7
|
+
include SaleTrendsCountHelper
|
8
|
+
|
9
|
+
before_action :subject_url
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def trends
|
14
|
+
authorize! :status, BusinessDeliverSubject
|
15
|
+
|
16
|
+
|
17
|
+
@year = params[:year] ? params[:year] : Time.now.year
|
18
|
+
@month = params[:month] ? params[:month] : Time.now.month
|
19
|
+
@months = ['全部','1','2','3','4','5','6','7','8','9','10','11','12']
|
20
|
+
@years = (1..(Time.now.year - 2014)).reverse_each.map { |d| 2014 + d }
|
21
|
+
|
22
|
+
search_year = Time.now.change(year: @year)
|
23
|
+
# 统计时间
|
24
|
+
start_time = @month == "全部" ? search_year.change(month: 1).beginning_of_month : search_year.change(month: @month).beginning_of_month
|
25
|
+
end_time = @month == "全部" ? search_year.change(month: 12).end_of_month : search_year.change(month: @month).end_of_month
|
26
|
+
|
27
|
+
# 商机交付课程(已交付项目)
|
28
|
+
b_d_s = BusinessDeliverSubject.joins(business: :last_follow_up).where("educode_sales_follow_ups.reception_at BETWEEN '#{start_time}' AND '#{end_time}' ")
|
29
|
+
@completed_b_count = b_d_s.delivered.count
|
30
|
+
@uncompleted_b_count = b_d_s.undelivered.count
|
31
|
+
|
32
|
+
# 实践课程
|
33
|
+
b_subjects = b_d_s.joins(:subjects)
|
34
|
+
|
35
|
+
un_b_subjects = BusinessSubject.joins(:subject)
|
36
|
+
.where.not(subject_id: b_subjects.pluck("subjects.id"))
|
37
|
+
.where("educode_sales_business_subjects.deliver_date BETWEEN '#{start_time}' AND '#{end_time}' ")
|
38
|
+
|
39
|
+
@completed_s_count = un_b_subjects.where("subjects.status = 2 or public = 2").count + b_subjects.where("subjects.status = 2 or public = 2").count
|
40
|
+
@uncompleted_s_count = un_b_subjects.where.not("subjects.status = 2 or public = 2").count + b_subjects.where.not("subjects.status = 2 or public = 2").count
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
# 实践项目
|
45
|
+
|
46
|
+
un_b_shixun_ids = b_d_s.joins(business_subjects: :business_subject_shixuns).pluck("educode_sales_business_subject_shixuns.id")
|
47
|
+
un_s_shixun_ids = un_b_subjects.joins(:business_subject_shixuns).pluck("educode_sales_business_subject_shixuns.id")
|
48
|
+
un_shixun_ids = BusinessSubjectShixun.left_joins(:business_subject)
|
49
|
+
.where("educode_sales_business_subjects.id is null and educode_sales_business_subject_shixuns.deliver_date BETWEEN '#{start_time}' AND '#{end_time}' ")
|
50
|
+
.pluck("educode_sales_business_subject_shixuns.id")
|
51
|
+
|
52
|
+
shixuns = BusinessSubjectShixun.where(id: un_b_shixun_ids + un_s_shixun_ids + un_shixun_ids).left_joins(shixun_producer: [staff: :user])
|
53
|
+
|
54
|
+
# todo 待优化
|
55
|
+
shixuns = shixuns.distinct("DISTINCT educode_sales_business_subject_shixuns.id")
|
56
|
+
all_shixun = shixuns.where("educode_sales_business_subject_shixuns.shixun_type = 1")
|
57
|
+
un_shixun = shixuns.where("educode_sales_business_subject_shixuns.shixun_type = 2")
|
58
|
+
@money = shixuns.pluralist.completed.sum(:deliver_money)
|
59
|
+
|
60
|
+
|
61
|
+
# all_shixun_users = all_shixun.left_joins(shixun_producer: [staff: :user])
|
62
|
+
# un_shixun_users = un_shixun.left_joins(shixun_producer: [staff: :user])
|
63
|
+
|
64
|
+
# 管培
|
65
|
+
@training_completed_shixuns = all_shixun.training.completed.count
|
66
|
+
@training_un_completed_shixuns = all_shixun.training.un_completed.count
|
67
|
+
@training_completed_un_shixuns = un_shixun.training.completed.count
|
68
|
+
@training_un_completed_un_shixuns = un_shixun.training.un_completed.count
|
69
|
+
|
70
|
+
@training_shixuns = all_shixun.training.pluck("DISTINCT users.id ").count == 0 ? 0 : all_shixun.training.count / all_shixun.training.pluck("DISTINCT users.id ").count
|
71
|
+
@training_un_shixuns = un_shixun.training.pluck("DISTINCT users.id ").count == 0 ? 0 : un_shixun.training.count / un_shixun.training.pluck("DISTINCT users.id ").count
|
72
|
+
|
73
|
+
# 全职
|
74
|
+
@worker_completed_shixuns = all_shixun.worker.completed.count
|
75
|
+
@worker_un_completed_shixuns = all_shixun.worker.un_completed.count
|
76
|
+
@worker_completed_un_shixuns = un_shixun.worker.completed.count
|
77
|
+
@worker_un_completed_un_shixuns = un_shixun.worker.un_completed.count
|
78
|
+
|
79
|
+
@worker_shixuns = all_shixun.worker.pluck("DISTINCT users.id ").count == 0 ? 0 : all_shixun.worker.count / all_shixun.worker.pluck("DISTINCT users.id ").count
|
80
|
+
@worker_un_shixuns = un_shixun.worker.pluck("DISTINCT users.id ").count == 0 ? 0 : un_shixun.worker.count / un_shixun.worker.pluck("DISTINCT users.id ").count
|
81
|
+
|
82
|
+
|
83
|
+
# 专职(兼职)
|
84
|
+
@pluralist_completed_shixuns = all_shixun.pluralist.completed.count
|
85
|
+
@pluralist_un_completed_shixuns = all_shixun.pluralist.un_completed.count
|
86
|
+
|
87
|
+
@pluralist_completed_shixun_money = all_shixun.pluralist.completed.sum(:deliver_money)
|
88
|
+
@pluralist_completed_un_shixuns = un_shixun.pluralist.completed.count
|
89
|
+
@pluralist_un_completed_un_shixuns = un_shixun.pluralist.un_completed.count
|
90
|
+
@pluralist_completed_un_shixun_money = un_shixun.pluralist.completed.sum(:deliver_money)
|
91
|
+
|
92
|
+
@pluralist_shixuns = all_shixun.pluralist.pluck("DISTINCT users.id ").count == 0 ? 0 : all_shixun.pluralist.count / all_shixun.pluralist.pluck("DISTINCT users.id ").count
|
93
|
+
@pluralist_un_shixuns = un_shixun.pluralist.pluck("DISTINCT users.id ").count == 0 ? 0 : un_shixun.pluralist.count / un_shixun.pluralist.pluck("DISTINCT users.id ").count
|
94
|
+
|
95
|
+
# 排名
|
96
|
+
|
97
|
+
producer = BusinessSubjectStaff.joins(staff: :user).shixun_producer.group("users.id").select("COUNT(users.id) num, CONCAT(users.lastname, users.firstname) user_name")
|
98
|
+
@max_users = producer.order("num desc").limit(3).map{|d| d.user_name }.join("、")
|
99
|
+
@min_users = producer.order("num asc").limit(3).map{|d| d.user_name }.join("、")
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
def distinct_count(item)
|
105
|
+
item.count("DISTINCT educode_sales_business_subject_shixuns.id")
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def demo
|
110
|
+
# 管培
|
111
|
+
@training_completed_shixuns = distinct_count(all_shixun.training.completed)
|
112
|
+
p @training_completed_shixuns
|
113
|
+
@training_un_completed_shixuns = distinct_count all_shixun.training.un_completed
|
114
|
+
@training_completed_un_shixuns = distinct_count un_shixun.training.completed
|
115
|
+
@training_un_completed_un_shixuns = distinct_count un_shixun.training.un_completed
|
116
|
+
#
|
117
|
+
@training_shixuns = all_shixun.training.pluck("DISTINCT users.id ").count == 0 ? 0 : distinct_count(all_shixun.training) / all_shixun.training.pluck("DISTINCT users.id ").count
|
118
|
+
@training_un_shixuns = un_shixun.training.pluck("DISTINCT users.id ").count == 0 ? 0 : distinct_count(un_shixun.training) / un_shixun.training.pluck("DISTINCT users.id ").count
|
119
|
+
#
|
120
|
+
# # 全职
|
121
|
+
# @worker_completed_shixuns = distinct_count all_shixun.worker.completed
|
122
|
+
# @worker_un_completed_shixuns = distinct_count all_shixun.worker.un_completed
|
123
|
+
# @worker_completed_un_shixuns = distinct_count un_shixun.worker.completed
|
124
|
+
# @worker_un_completed_un_shixuns = distinct_count un_shixun.worker.un_completed
|
125
|
+
#
|
126
|
+
# @worker_shixuns = all_shixun.worker.pluck("DISTINCT users.id ").count == 0 ? 0 : distinct_count all_shixun.worker / all_shixun.worker.pluck("DISTINCT users.id ").count
|
127
|
+
# @worker_un_shixuns = un_shixun.worker.pluck("DISTINCT users.id ").count == 0 ? 0 : distinct_count un_shixun.worker / un_shixun.worker.pluck("DISTINCT users.id ").count
|
128
|
+
#
|
129
|
+
#
|
130
|
+
# # 专职(兼职)
|
131
|
+
# @pluralist_completed_shixuns = distinct_count all_shixun.pluralist.completed
|
132
|
+
# @pluralist_un_completed_shixuns = distinct_count all_shixun.pluralist.un_completed
|
133
|
+
#
|
134
|
+
# @pluralist_completed_shixun_money = all_shixun.pluralist.completed.distinct("DISTINCT educode_sales_business_subject_shixuns.id").sum(:deliver_money)
|
135
|
+
# @pluralist_completed_un_shixuns = distinct_count un_shixun.pluralist.completed
|
136
|
+
# @pluralist_un_completed_un_shixuns = distinct_count un_shixun.pluralist.un_completed
|
137
|
+
# @pluralist_completed_un_shixun_money = un_shixun.pluralist.completed.distinct("DISTINCT educode_sales_business_subject_shixuns.id").sum(:deliver_money)
|
138
|
+
#
|
139
|
+
# @pluralist_shixuns = all_shixun.pluralist.pluck("DISTINCT users.id ").count == 0 ? 0 : distinct_count all_shixun.pluralist.count / all_shixun.pluralist.pluck("DISTINCT users.id ").count
|
140
|
+
# @pluralist_un_shixuns = un_shixun.pluralist.pluck("DISTINCT users.id ").count == 0 ? 0 : distinct_count un_shixun.pluralist.count / un_shixun.pluralist.pluck("DISTINCT users.id ").count
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|