educode_sales 1.10.46 → 1.10.49
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/images/educode_sales/indexlogo.png +0 -0
- 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 +12 -0
- data/app/controllers/educode_sales/business_courses_controller.rb +230 -0
- data/app/controllers/educode_sales/follow_ups_controller.rb +6 -2
- data/app/controllers/educode_sales/home_controller.rb +7 -0
- data/app/controllers/educode_sales/shixun_dectects_controller.rb +111 -0
- data/app/controllers/educode_sales/shixuns_controller.rb +157 -0
- data/app/controllers/educode_sales/subject_trends_controller.rb +937 -0
- data/app/controllers/educode_sales/subjects_controller.rb +202 -0
- data/app/controllers/educode_sales/teachers_controller.rb +13 -2
- data/app/helpers/educode_sales/application_helper.rb +8 -0
- data/app/helpers/educode_sales/business_courses_helper.rb +37 -0
- data/app/helpers/educode_sales/subject_helper.rb +29 -0
- data/app/models/educode_sales/business.rb +22 -0
- data/app/models/educode_sales/business_deliver_subject.rb +48 -0
- data/app/models/educode_sales/business_subject.rb +62 -0
- data/app/models/educode_sales/business_subject_shixun.rb +46 -0
- data/app/models/educode_sales/business_subject_staff.rb +35 -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 +148 -0
- data/app/views/educode_sales/business_courses/index.html.erb +312 -0
- data/app/views/educode_sales/business_courses/index.json.jbuilder +16 -0
- data/app/views/educode_sales/business_courses/list_shixuns.html.erb +224 -0
- data/app/views/educode_sales/business_courses/list_shixuns.json.jbuilder +17 -0
- data/app/views/educode_sales/business_courses/list_subjects.html.erb +217 -0
- data/app/views/educode_sales/business_courses/list_subjects.json.jbuilder +12 -0
- data/app/views/educode_sales/business_courses/new.html.erb +212 -0
- data/app/views/educode_sales/shixun_dectects/index.html.erb +466 -0
- data/app/views/educode_sales/shixun_dectects/index.json.jbuilder +22 -0
- data/app/views/educode_sales/shixun_dectects/markdown.html.erb +60 -0
- data/app/views/educode_sales/shixuns/edit.html.erb +186 -0
- data/app/views/educode_sales/shixuns/index.html.erb +513 -0
- data/app/views/educode_sales/shixuns/index.json.jbuilder +22 -0
- data/app/views/educode_sales/shixuns/new.html.erb +251 -0
- data/app/views/educode_sales/subject_trends/trends.html.erb +1074 -0
- data/app/views/educode_sales/subjects/edit.html.erb +86 -0
- data/app/views/educode_sales/subjects/index.html.erb +247 -0
- data/app/views/educode_sales/subjects/index.json.jbuilder +16 -0
- data/app/views/educode_sales/subjects/list_shixuns.html.erb +228 -0
- data/app/views/educode_sales/subjects/list_shixuns.json.jbuilder +17 -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 +43 -6
@@ -0,0 +1,202 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EducodeSales
|
4
|
+
include SubjectHelper
|
5
|
+
|
6
|
+
# 实践课程管理
|
7
|
+
class SubjectsController < ApplicationController
|
8
|
+
before_action :subject_members
|
9
|
+
|
10
|
+
def index
|
11
|
+
authorize! :subject, BusinessDeliverSubject
|
12
|
+
respond_to do |format|
|
13
|
+
format.html do
|
14
|
+
end
|
15
|
+
format.json do
|
16
|
+
# d.last_follow_up&.assign_follow_ups.present? ? (d.last_follow_up.assign_follow_ups.map{ |d| d.staff.user.real_name}.join("、")) : d.staff&.user&.real_name
|
17
|
+
business_subject = BusinessSubject.joins(:subject).left_joins(business_deliver_subject: [:manages, business: [:last_follow_up]])
|
18
|
+
if params[:q] && params[:q][:shixun].present?
|
19
|
+
business_subject = business_subject.joins("INNER JOIN educode_sales_business_subject_shixuns ON educode_sales_business_subject_shixuns.business_subject_id = educode_sales_business_subjects.id")
|
20
|
+
.where("educode_sales_business_subject_shixuns.name like '%#{params[:q][:shixun]}%'")
|
21
|
+
end
|
22
|
+
# 查询条件 实践课程名称
|
23
|
+
if params[:q] && params[:q][:subjects_name].present?
|
24
|
+
business_subject = business_subject.where("subjects.name like '%#{params[:q][:subjects_name]}%'")
|
25
|
+
end
|
26
|
+
# 查询条件 时间
|
27
|
+
if params[:q] && params[:q][:time].present?
|
28
|
+
start_time = params[:q][:time].split(" - ")[0]
|
29
|
+
end_time = params[:q][:time].split(" - ")[-1]
|
30
|
+
business_subject = business_subject.where("educode_sales_business_subjects.deliver_date BETWEEN '#{start_time}' AND '#{end_time}' OR
|
31
|
+
educode_sales_follow_ups.reception_at BETWEEN'#{start_time}' AND '#{end_time}'")
|
32
|
+
end
|
33
|
+
|
34
|
+
business_subject_schools = {}
|
35
|
+
business_subject_manges = {}
|
36
|
+
business_subject_staffs = {}
|
37
|
+
BusinessSubject.includes(:school, :manages, :subject, :staffs, business_deliver_subject: [:manages, business: [:school, last_follow_up: :assign_follow_ups] ]).each do |d|
|
38
|
+
b_d_s = d.business_deliver_subject
|
39
|
+
|
40
|
+
b_d_s.present? ? business_subject_schools.merge!({ "#{d.id}": d.business.school_name }) : business_subject_schools.merge!({"#{d.id}": d.school_name })
|
41
|
+
b_d_s.present? ? business_subject_manges.merge!({ "#{d.id}": b_d_s.subject_manages}) : business_subject_manges.merge!({"#{d.id}": d.manges_name })
|
42
|
+
b_d_s.present? ? business_subject_staffs.merge!({ "#{d.id}": d.business.staff_name }) : business_subject_staffs.merge!({"#{d.id}": "--" }) # 先暂时处理
|
43
|
+
|
44
|
+
end
|
45
|
+
@business_subject_schools = business_subject_schools.stringify_keys
|
46
|
+
@business_subject_staffs = business_subject_staffs.stringify_keys
|
47
|
+
@business_subject_manges = business_subject_manges.stringify_keys
|
48
|
+
|
49
|
+
business_subject = business_subject.select("subjects.name s_name,
|
50
|
+
subjects.status status,
|
51
|
+
subjects.public public,
|
52
|
+
educode_sales_business_subjects.id,
|
53
|
+
IFNULL(educode_sales_follow_ups.reception_at, educode_sales_business_subjects.deliver_date) deliver_date,
|
54
|
+
IFNULL(educode_sales_businesses.name, '--' ) b_name
|
55
|
+
")
|
56
|
+
@count = business_subject.count("educode_sales_business_subjects.id")
|
57
|
+
@business_subject = business_subject.page(params[:page]).per(params[:limit])
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def new
|
64
|
+
authorize! :subject, BusinessDeliverSubject
|
65
|
+
# staffs = Staff.where.not(role_id: 11).includes(:user)
|
66
|
+
gon.staffs = @manages
|
67
|
+
render layout: false
|
68
|
+
end
|
69
|
+
|
70
|
+
def edit
|
71
|
+
authorize! :subject, BusinessDeliverSubject
|
72
|
+
if params[:id]
|
73
|
+
business_subject = BusinessSubject.find(params[:id])
|
74
|
+
@item = business_subject.subject
|
75
|
+
@select = @item.shixuns.map { |item| { value: item.id, name: item.name } }
|
76
|
+
@id = business_subject.id
|
77
|
+
@school_id = business_subject.school_id
|
78
|
+
@default_select = BusinessSubjectShixun.where("business_subject_id = #{params[:id]}")
|
79
|
+
.select(:shixun_id)
|
80
|
+
.map { |item| item.shixun_id }
|
81
|
+
render layout: false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def create
|
86
|
+
authorize! :subject, BusinessDeliverSubject
|
87
|
+
# 开启事务
|
88
|
+
ActiveRecord::Base.transaction do
|
89
|
+
subject = Subject.where.not(id: BusinessSubject.pluck(:subject_id) ).find_by(id: params[:subject_id])
|
90
|
+
if subject.present?
|
91
|
+
attr = {
|
92
|
+
deliver_date: params[:deliver_date],
|
93
|
+
school_id: params[:school_id],
|
94
|
+
subject_id: subject.id
|
95
|
+
}
|
96
|
+
new_object = BusinessSubject.create(attr)
|
97
|
+
|
98
|
+
subject.add_subject_shixuns(params[:shixun_ids].split(',').map(&:to_i))
|
99
|
+
|
100
|
+
|
101
|
+
BusinessSubjectStaff.bulk_insert(:staff_id, :container_id, :container_type, :created_at, :updated_at, :category) do |d|
|
102
|
+
params[:manage_id].split(",").each do |m|
|
103
|
+
d.add [m.to_i, new_object.id, BusinessSubjectStaff::CONTAINER_TYPES::SUBJECT, Time.now, Time.now, BusinessSubjectStaff::CATEGORY_TYPES::SUBJECT_MANAGE ]
|
104
|
+
end
|
105
|
+
params[:sale_id].split(",").each do |s|
|
106
|
+
d.add [s.to_i, new_object.id, BusinessSubjectStaff::CONTAINER_TYPES::SUBJECT, Time.now, Time.now, BusinessSubjectStaff::CATEGORY_TYPES::SUBJECT_STAFF ]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
render_success
|
111
|
+
else
|
112
|
+
render_failure("操作失败")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def update
|
118
|
+
authorize! :subject, BusinessDeliverSubject
|
119
|
+
# 开启事务
|
120
|
+
ActiveRecord::Base.transaction do
|
121
|
+
business_subject = BusinessSubject.find_by(id: params[:id])
|
122
|
+
|
123
|
+
if business_subject
|
124
|
+
new_shixun_ids = params[:shixun_ids].split(',').map(&:to_i)
|
125
|
+
old_shixun_ids = business_subject.business_subject_shixuns.pluck(:shixun_id)
|
126
|
+
|
127
|
+
# 需要删除的科目id
|
128
|
+
change_shixuns = old_shixun_ids - new_shixun_ids
|
129
|
+
add_shixuns = new_shixun_ids - old_shixun_ids
|
130
|
+
|
131
|
+
# 取消关联
|
132
|
+
business_subject.business_subject_shixuns.where(shixun_id: change_shixuns).update_all(business_subject_id: nil)
|
133
|
+
|
134
|
+
# 创建关联
|
135
|
+
business_subject.add_subject_shixuns(add_shixuns)
|
136
|
+
|
137
|
+
render_success
|
138
|
+
else
|
139
|
+
render_failure("操作失败")
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def shixun_list
|
146
|
+
respond_to do |format|
|
147
|
+
format.json do
|
148
|
+
@list = Shixun.unhidden.where.not(id: BusinessSubjectShixun.joins(:business_subject).pluck(:shixun_id) ) # 1先创建实践项目下,通过实践课程无法选该实践项目
|
149
|
+
if params[:q].present?
|
150
|
+
@list = @list.where("name like '%#{params[:q]}%'").page(params[:page]).per(10)
|
151
|
+
end
|
152
|
+
if params[:subject_id].present?
|
153
|
+
@list = @list.joins(:stage_shixuns).where("subject_id = #{params[:subject_id]}")
|
154
|
+
end
|
155
|
+
render json: {
|
156
|
+
data: @list.map { |item| { value: item[:id], name: item[:name] } },
|
157
|
+
code: 0
|
158
|
+
}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def search_subjects
|
164
|
+
respond_to do |format|
|
165
|
+
format.json do
|
166
|
+
@subjects = Subject.unhidden.where.not(id: BusinessSubject.pluck(:subject_id)).where("name like '%#{params[:q]}%' ").page(params[:page]).per(10)
|
167
|
+
render json: {
|
168
|
+
data: @subjects.map { |item| { value: item[:id], name: item[:name] } },
|
169
|
+
code: 0,
|
170
|
+
count: @subjects.total_count / 10
|
171
|
+
}
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def list_shixuns
|
177
|
+
if params[:id].present?
|
178
|
+
@shixuns = BusinessSubjectShixun.where("business_subject_id = #{params[:id]}")
|
179
|
+
.joins(:shixun)
|
180
|
+
if params[:q].present? && params[:q][:shixun_name].present?
|
181
|
+
@shixuns = @shixuns.where("shixuns.name like '%#{params[:q][:shixun_name]}%'")
|
182
|
+
end
|
183
|
+
if params[:q].present? && params[:q][:level].present? && params[:q][:level].to_i != 0
|
184
|
+
@shixuns = @shixuns.where(level: params[:q][:level])
|
185
|
+
end
|
186
|
+
# 项目状态 0 全部
|
187
|
+
if params[:q].present? && params[:q][:status].present? && params[:q][:status].to_i != 0
|
188
|
+
@shixuns = @shixuns.where(shixun_status: params[:q][:status])
|
189
|
+
end
|
190
|
+
if params[:q].present? && params[:q][:category].present? && params[:q][:category].to_i != 0
|
191
|
+
@shixuns = @shixuns.where(category: params[:q][:category])
|
192
|
+
end
|
193
|
+
@shixuns = @shixuns.select("educode_sales_business_subject_shixuns.*,
|
194
|
+
shixuns.name as shixun_name")
|
195
|
+
.page(params[:page])
|
196
|
+
.per(params[:limit])
|
197
|
+
end
|
198
|
+
render layout: false
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
end
|
@@ -206,8 +206,19 @@ module EducodeSales
|
|
206
206
|
if params[:q].present? && params[:q][:is_contact].present?
|
207
207
|
@teachers = @teachers.where("last_follow.is_contact = ?", params[:q][:is_contact].to_i)
|
208
208
|
end
|
209
|
-
|
210
|
-
|
209
|
+
if params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'created_at'
|
210
|
+
@teachers = @teachers.order("educode_sales_teachers.created_at #{params[:sort][:order]}")
|
211
|
+
elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'last_login_on'
|
212
|
+
@teachers = @teachers.order("users.last_login_on #{params[:sort][:order]}")
|
213
|
+
elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'created_on'
|
214
|
+
@teachers = @teachers.order("users.created_on #{params[:sort][:order]}")
|
215
|
+
elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'latest_time'
|
216
|
+
@teachers = @teachers.order("last_follow.created_at #{params[:sort][:order]}")
|
217
|
+
elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'experience'
|
218
|
+
@teachers = @teachers.order("users.experience #{params[:sort][:order]}")
|
219
|
+
elsif params[:sort].present? && params[:sort][:field] && params[:sort][:field] == 'grade'
|
220
|
+
@teachers = @teachers.order("users.grade #{params[:sort][:order]}")
|
221
|
+
elsif params[:sort].present? && params[:sort][:field]
|
211
222
|
@teachers = @teachers.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
212
223
|
else
|
213
224
|
@teachers = @teachers.order("educode_sales_teachers.created_at desc")
|
@@ -9,6 +9,14 @@ module EducodeSales
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
def handled_data(item)
|
13
|
+
item.blank? ? "--" : item
|
14
|
+
end
|
15
|
+
|
16
|
+
def handled_time_data(item)
|
17
|
+
item.blank? ? "--" : item.strftime("%Y-%m-%d")
|
18
|
+
end
|
19
|
+
|
12
20
|
def url_to_avatar(source)
|
13
21
|
return "" if source.blank?
|
14
22
|
if File.exist?(disk_filename(source&.class, source&.id)) && File.file?(disk_filename(source&.class, source&.id))
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module EducodeSales
|
2
|
+
module BusinessCoursesHelper
|
3
|
+
|
4
|
+
def real_shixun_type(type)
|
5
|
+
case type.to_i
|
6
|
+
when 1
|
7
|
+
"管培"
|
8
|
+
when 2
|
9
|
+
"专职"
|
10
|
+
when 3
|
11
|
+
"全职"
|
12
|
+
else
|
13
|
+
"管培"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def real_shixun_level(level)
|
19
|
+
case level.to_i
|
20
|
+
when 1
|
21
|
+
"不明确"
|
22
|
+
when 2
|
23
|
+
"重要紧急"
|
24
|
+
when 3
|
25
|
+
"建设重要不紧急中"
|
26
|
+
when 4
|
27
|
+
"不重要紧急"
|
28
|
+
when 5
|
29
|
+
"不重要不紧急"
|
30
|
+
else
|
31
|
+
"不明确"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module EducodeSales
|
2
|
+
module SubjectHelper
|
3
|
+
|
4
|
+
|
5
|
+
def school_name(item)
|
6
|
+
item.business ? item.business.school.name : item.school_name
|
7
|
+
end
|
8
|
+
|
9
|
+
# def deliver_date(item)
|
10
|
+
# item.business ? item.business.p_course_time : item.deliver_date.strftime("%Y-%m-%d")
|
11
|
+
# end
|
12
|
+
|
13
|
+
|
14
|
+
# def b_name(item)
|
15
|
+
# item.business ? item.business.name : ''
|
16
|
+
# end
|
17
|
+
|
18
|
+
def staffs(item)
|
19
|
+
item.business ? item.business.staff.name : item.staffs_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def manges(item)
|
23
|
+
item.business ? item.business.business_deliver_subjects.take.subject_manages : item.manges_name
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -18,6 +18,7 @@ module EducodeSales
|
|
18
18
|
has_many :business_levels, dependent: :destroy
|
19
19
|
has_many :business_watches, dependent: :destroy
|
20
20
|
has_many :business_histories, dependent: :destroy
|
21
|
+
has_many :business_deliver_subjects, dependent: :destroy # 商机交付课程
|
21
22
|
has_many :money_plans
|
22
23
|
|
23
24
|
has_one :invoice_apply
|
@@ -35,6 +36,7 @@ module EducodeSales
|
|
35
36
|
# 关联关注
|
36
37
|
has_many :users, :class_name => 'EducodeSales::BusinessRelationShip', foreign_key: 'business_id', :dependent => :destroy
|
37
38
|
|
39
|
+
after_update :change_diliver
|
38
40
|
# 每次查询时 默认的查询条件
|
39
41
|
default_scope -> { where(deleted_at: nil) }
|
40
42
|
|
@@ -75,6 +77,26 @@ module EducodeSales
|
|
75
77
|
'应收款' => ['已中标','已签单','已验收','回款中', '服务中','已结束']
|
76
78
|
}[type]
|
77
79
|
end
|
80
|
+
|
81
|
+
|
82
|
+
# 创建商机交付课程数据
|
83
|
+
def change_diliver
|
84
|
+
|
85
|
+
if previous_changes["last_follow_up_id"].present?
|
86
|
+
last_clazz_id = previous_changes["last_follow_up_id"][-1]
|
87
|
+
common_type = FollowUp.find_by(id: last_clazz_id)&.stage&.name == "已中标"
|
88
|
+
BusinessDeliverSubject.find_or_create_by(business_id: self.id) if common_type
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def school_name
|
93
|
+
department&.school&.name || "--"
|
94
|
+
end
|
95
|
+
|
96
|
+
def staff_name
|
97
|
+
last_follow_up&.assign_follow_ups.present? ? (last_follow_up.assign_follow_ups.map{ |d| d.staff.user.real_name}.join("、")) : staff&.user&.real_name
|
98
|
+
end
|
99
|
+
|
78
100
|
end
|
79
101
|
|
80
102
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module EducodeSales
|
2
|
+
class BusinessDeliverSubject < ApplicationRecord
|
3
|
+
belongs_to :business
|
4
|
+
has_many :business_subjects, dependent: :destroy
|
5
|
+
has_many :subjects ,through: :business_subjects
|
6
|
+
has_many :manages, as: :container, dependent: :destroy, class_name: "EducodeSales::BusinessSubjectStaff"
|
7
|
+
|
8
|
+
|
9
|
+
# constructed:待建设, signed: 已签协议,construction: 建设中,completed: 已完成,delivered: 已交付, accepted: 已验收
|
10
|
+
enum status: { constructed:1, signed:2, construction: 3, completed:4, delivered: 5, accepted: 6 }
|
11
|
+
|
12
|
+
# 实践课程完成统计
|
13
|
+
def subject_competed_count
|
14
|
+
all_count = subjects.count
|
15
|
+
completed_count = subjects.where("subjects.status = 2 and subjects.public = 2").count
|
16
|
+
|
17
|
+
" #{completed_count} / #{all_count} "
|
18
|
+
end
|
19
|
+
|
20
|
+
# 实训项目完成进度
|
21
|
+
def shixun_competed_count
|
22
|
+
" #{subjects.joins(:shixuns).where("shixuns.status =2 and shixuns.public = 2").count} / #{subjects.joins(:shixuns).count} "
|
23
|
+
end
|
24
|
+
|
25
|
+
# 课程经理
|
26
|
+
def subject_manages
|
27
|
+
manages.joins(staff: :user).pluck("CONCAT(users.lastname, users.firstname) ").join(",") || "--"
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def delvier_date
|
32
|
+
business.last_follow_up&.reception_at
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_subjects(subject_ids = [])
|
36
|
+
subjects = Subject.where.not(id: BusinessSubject.joins(:business_deliver_subject).pluck(:subject_id)).unhidden # 1先创建实践项目下,通过实践课程无法选该实践项目
|
37
|
+
subject_ids.each do |item|
|
38
|
+
now_subject = subjects.find_by(id: item)
|
39
|
+
if now_subject.present?
|
40
|
+
add_item = BusinessSubject.find_or_create_by(subject_id: item)
|
41
|
+
add_item.update(business: business, business_deliver_subject_id: id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module EducodeSales
|
2
|
+
class BusinessSubject < ApplicationRecord
|
3
|
+
belongs_to :business, optional: true
|
4
|
+
belongs_to :business_deliver_subject, optional: true
|
5
|
+
belongs_to :school, optional: true
|
6
|
+
belongs_to :subject, optional: true
|
7
|
+
has_many :business_subject_shixuns
|
8
|
+
has_many :staffs, ->{subject_staffs}, as: :container, dependent: :destroy, class_name: "EducodeSales::BusinessSubjectStaff"
|
9
|
+
has_many :manages, ->{subject_manges}, as: :container, dependent: :destroy, class_name: "EducodeSales::BusinessSubjectStaff"
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
# 销售名称
|
14
|
+
def staffs_name
|
15
|
+
staffs.joins(staff: :user).pluck("CONCAT(users.lastname, users.firstname) ").join(",")
|
16
|
+
end
|
17
|
+
|
18
|
+
# 课程经理名称
|
19
|
+
def manges_name
|
20
|
+
manages.joins(staff: :user).pluck("CONCAT(users.lastname, users.firstname) ").join(",")
|
21
|
+
end
|
22
|
+
|
23
|
+
# 实训完成统计
|
24
|
+
def shixun_compeled_count
|
25
|
+
" #{business_subject_shixuns.joins(:shixun).where("shixuns.status=2 and shixuns.public = 2").count} / #{business_subject_shixuns.count}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def school_name
|
29
|
+
school.try(:name)
|
30
|
+
end
|
31
|
+
|
32
|
+
# def deliver_date
|
33
|
+
# business ? business.last_follow_up.try(:reception_at)&.strftime("%Y-%m-%d") || "--" : deliver_date.strftime("%Y-%m-%d")
|
34
|
+
# end
|
35
|
+
|
36
|
+
|
37
|
+
# def b_name
|
38
|
+
# business ? business.name : '--'
|
39
|
+
# end
|
40
|
+
|
41
|
+
def staffs
|
42
|
+
business ? business.staff&.name : staffs_name
|
43
|
+
end
|
44
|
+
|
45
|
+
def manges
|
46
|
+
business_deliver_subject ? business_deliver_subject.subject_manages : manges_name
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def add_subject_shixuns(shixun_ids=[]) # 1先创建实践项目下,通过实践课程无法选该实践项目
|
51
|
+
shixuns = Shixun.where.not(id: BusinessSubjectShixun.joins(:business_subject).pluck(:shixun_id)).unhidden # 1先创建实践项目下,通过实践课程无法选该实践项目
|
52
|
+
shixun_ids.each do |item|
|
53
|
+
now_shixun = shixuns.find_by(id: item)
|
54
|
+
if now_shixun.present?
|
55
|
+
add_item = BusinessSubjectShixun.create_with(name: now_shixun.name).find_or_create_by(shixun_id: item)
|
56
|
+
add_item.update(business_subject_id: self.id )
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module EducodeSales
|
2
|
+
class BusinessSubjectShixun < ApplicationRecord
|
3
|
+
|
4
|
+
belongs_to :business_subject, optional: true
|
5
|
+
belongs_to :school, optional: true
|
6
|
+
belongs_to :shixun, optional: true
|
7
|
+
has_many :staffs, as: :container, dependent: :destroy, class_name: "EducodeSales::BusinessSubjectStaff"
|
8
|
+
belongs_to :last_dectect, foreign_key: :shixun_dectect_id, class_name: "EducodeSales::ShixunDectect", optional: true
|
9
|
+
|
10
|
+
module CATEGORY_TYPE
|
11
|
+
TRAINING = 1 # 管培
|
12
|
+
WORKER = 2 # 全职
|
13
|
+
PLURALIST = 3 # 兼职
|
14
|
+
end
|
15
|
+
|
16
|
+
# 项目状态: 待建设(constructed) 已签协议(signed) 建设中(construction) 审核中(review),返修中(repair) 已内部公开(public), 已公开发布(published) 已经付费(paid)
|
17
|
+
# enum status: { constructed: 1, signed: 2, construction: 3, review: 4, repair: 5, public: 6, published: 7,paid: 8}
|
18
|
+
|
19
|
+
def shixun_manages
|
20
|
+
staffs.joins(staff: :user).where(category:BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_MANAGE).pluck("CONCAT(users.lastname, users.firstname) ").join(",")
|
21
|
+
end
|
22
|
+
def shixun_producer
|
23
|
+
staffs.joins(staff: :user).where(category:BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_PRODUCER).pluck("CONCAT(users.lastname, users.firstname) ").join(",")
|
24
|
+
end
|
25
|
+
def shixun_staff
|
26
|
+
return business_subject.manges unless business_subject.nil?
|
27
|
+
staffs.joins(staff: :user).where(category:BusinessSubjectStaff::CATEGORY_TYPES::SHIXUN_STAFF).pluck("CONCAT(users.lastname, users.firstname) ").join(",")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# 查询审核历史和审核人
|
32
|
+
def audit_history
|
33
|
+
ShixunDectect.joins("join educode_sales_staffs on educode_sales_staffs.id = educode_sales_shixun_dectects.reviewed_id
|
34
|
+
join users on users.id = educode_sales_staffs.user_id")
|
35
|
+
.where(business_subject_shixun_id:id)
|
36
|
+
.where("dectect_type != 0")
|
37
|
+
.select("educode_sales_shixun_dectects.*,
|
38
|
+
CONCAT(users.lastname, users.firstname) as examine_name")
|
39
|
+
.all
|
40
|
+
end
|
41
|
+
# def school_name
|
42
|
+
# business_subject ? business_subject.school_name : school.name
|
43
|
+
# end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module EducodeSales
|
2
|
+
class BusinessSubjectStaff < ApplicationRecord
|
3
|
+
|
4
|
+
belongs_to :staff
|
5
|
+
belongs_to :container, polymorphic: true, optional: true, touch: true
|
6
|
+
|
7
|
+
|
8
|
+
# 类型
|
9
|
+
enum container_type: { "EducodeSales::BusinessDeliverSubject": 1, "EducodeSales::BusinessSubject": 2, "EducodeSales::BusinessSubjectShixun": 3 }
|
10
|
+
|
11
|
+
|
12
|
+
# # 项目状态: 待建设(constructed) 已签协议(signed) 建设中(construction) 审核中(review),返修中(repair) 已内部公开(public), 已公开发布(published) 已经付费(paid)
|
13
|
+
# enum category_type: { constructed: 1, signed: 2, construction: 3, review: 4, repair: 5, public: 6, published: 7,paid: 8 }
|
14
|
+
|
15
|
+
module CONTAINER_TYPES
|
16
|
+
BUSSINESS = 1
|
17
|
+
SUBJECT = 2
|
18
|
+
SHIXUN = 3
|
19
|
+
end
|
20
|
+
|
21
|
+
module CATEGORY_TYPES
|
22
|
+
BUSINESS_MANAGE = 1 # 商机交付课程: 课程经理
|
23
|
+
SUBJECT_MANAGE = 2 # 实践课程管理: 课程经理
|
24
|
+
SUBJECT_STAFF = 3 # 实践课程管理: 销售
|
25
|
+
SHIXUN_MANAGE = 4 # 实训项目管理: 课程组长
|
26
|
+
SHIXUN_PRODUCER = 5 # 实训项目管理: 制作人
|
27
|
+
SHIXUN_STAFF = 6 # 实训项目管理: 销售
|
28
|
+
end
|
29
|
+
|
30
|
+
scope :subject_staffs, ->{where(category: CATEGORY_TYPES::SUBJECT_STAFF)}
|
31
|
+
scope :subject_manges, ->{where(category: CATEGORY_TYPES::SUBJECT_MANAGE)}
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module EducodeSales
|
2
|
+
class ShixunDectect < ApplicationRecord
|
3
|
+
|
4
|
+
belongs_to :business_subject_shixun
|
5
|
+
belongs_to :reviewed_staff, foreign_key: :reviewed_id, class_name: "EducodeSales::Staff"
|
6
|
+
|
7
|
+
# 状态: refused: 拒绝, agreed: 同意 review 审核中
|
8
|
+
enum dectect_type: {review:0, refused: 1, agreed: 2}
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|