educode_sales 0.7.8 → 0.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/educode_sales/assessments_controller.rb +111 -245
- data/app/controllers/educode_sales/businesses_controller.rb +58 -1
- data/app/controllers/educode_sales/customers_controller.rb +0 -3
- data/app/helpers/educode_sales/application_helper.rb +2 -2
- data/app/models/educode_sales/business.rb +8 -0
- data/app/models/educode_sales/business_relation_ship.rb +6 -0
- data/app/models/educode_sales/customer_follow.rb +1 -0
- data/app/models/educode_sales/follow_up.rb +2 -0
- data/app/models/educode_sales/role_area.rb +1 -1
- data/app/views/educode_sales/assessments/edit.html.erb +3 -2
- data/app/views/educode_sales/assessments/index.html.erb +1 -2
- data/app/views/educode_sales/assessments/index.json.jbuilder +1 -1
- data/app/views/educode_sales/assessments/new.html.erb +1 -0
- data/app/views/educode_sales/assessments/progress.json.jbuilder +2 -198
- data/app/views/educode_sales/businesses/following_businesses.jbuilder +44 -0
- data/app/views/educode_sales/businesses/index.html.erb +122 -6
- data/app/views/educode_sales/businesses/index.json.jbuilder +1 -0
- data/app/views/layouts/educode_sales/application.html.erb +1 -1
- data/config/routes.rb +3 -0
- data/db/migrate/20220420071909_create_educode_sales_business_relation_ships.rb +10 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9403e25df2848c96f744c79481e62ea3ebe44c6da7d265bd1e107885c13b108
|
4
|
+
data.tar.gz: 994b9567c3b88d6a804b43484447932725dcfe5d3c0f1e6113233c309a1f1f62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 202b2c2d096f7b8d949658605ed1eb1d9b288a2764ee8144e83efb60b7c718720471f3acec0f5a818302798550eef40c53b1642421465bb3370dec1160272fee
|
7
|
+
data.tar.gz: d5cd014d540019070da9da22c4b7439c4a71b242d6841d34494fdff9af0b049e9d14e22200af16b8c5a32f06bdd6ba9c18bb7b1c21a8c8a78c94f7ec446f7d7f
|
@@ -2,6 +2,9 @@ require_dependency "educode_sales/application_controller"
|
|
2
2
|
|
3
3
|
module EducodeSales
|
4
4
|
class AssessmentsController < ApplicationController
|
5
|
+
before_action :progress_or_get_export_data, only: [:progress, :get_export_data]
|
6
|
+
|
7
|
+
|
5
8
|
def index
|
6
9
|
respond_to do |format|
|
7
10
|
format.html do
|
@@ -17,22 +20,17 @@ module EducodeSales
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
format.json do
|
20
|
-
@assessments = AssessmentsSetting.all
|
21
23
|
@year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year]:'2022'
|
22
24
|
@assessments_id = params[:q].present? && params[:q][:assessment_id].present? ? params[:q][:assessment_id]: '1'
|
23
|
-
@assessments =
|
25
|
+
@assessments = AssessmentsSetting.where("assessment_year >= ? and assessment_year <= ?", "#{@year}-01-01 00:00:00".to_date, "#{@year}-12-31 23:59:00".to_date)
|
24
26
|
@assessments = @assessments.where(assessment: @assessments_id).order("updated_at desc")
|
25
27
|
if params[:q].present? && params[:q][:staff_id].present?
|
26
28
|
@assessments = @assessments.where(staff_id: params[:q][:staff_id]).order("updated_at desc")
|
27
29
|
end
|
28
|
-
# 对数据进行分页 默认为page=1 limit=10
|
29
|
-
# @assessments = @assessments.order("id desc").page(params[:page]).per(params[:limit])
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
34
|
# 新增
|
37
35
|
def create
|
38
36
|
begin
|
@@ -50,7 +48,6 @@ module EducodeSales
|
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
53
|
-
|
54
51
|
def new
|
55
52
|
render layout: false
|
56
53
|
end
|
@@ -73,17 +70,13 @@ module EducodeSales
|
|
73
70
|
render layout: false
|
74
71
|
end
|
75
72
|
|
76
|
-
#
|
73
|
+
# 根新
|
77
74
|
def update
|
78
75
|
@assessment = AssessmentsSetting.find_by(id: params[:id])
|
79
76
|
@assessment.update_attributes(params_update)
|
80
77
|
render_success
|
81
78
|
end
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
80
|
# 删除接口
|
88
81
|
def destroy
|
89
82
|
begin
|
@@ -98,141 +91,87 @@ module EducodeSales
|
|
98
91
|
|
99
92
|
|
100
93
|
|
101
|
-
|
102
94
|
# 导出数据
|
103
95
|
def get_export_data
|
104
|
-
|
105
|
-
@staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
|
106
|
-
@assessment_id = params[:assessment_id].present? ? params[:assessment_id]:'1'
|
107
|
-
@assessment_year = params[:assessment_year] ? params[:assessment_year] : '2022'
|
108
|
-
@assessments =AssessmentsSetting.where(assessment: @assessment_id).
|
109
|
-
where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
|
110
|
-
if params[:staff_id].present?
|
111
|
-
@assessments = @assessments.where(staff_id: params[:staff_id])
|
112
|
-
progress_main
|
113
|
-
else
|
114
|
-
# @assessments = @assessments.where(staff_id: @staff_ids) 注意 这样写有问题
|
115
|
-
@staff_ids.each do |s|
|
116
|
-
@assessments = @assessments.where(staff_id: s).order("updated_at desc")
|
117
|
-
progress_main
|
118
|
-
end
|
119
|
-
@assessments = AssessmentsSetting.where(assessment: @assessment_id).
|
120
|
-
where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
|
121
|
-
end
|
96
|
+
p 'get_export_data'
|
122
97
|
end
|
123
98
|
|
124
99
|
|
125
100
|
|
101
|
+
# 考核完成情况
|
102
|
+
def progress
|
103
|
+
p 'progress'
|
104
|
+
end
|
126
105
|
|
127
106
|
|
128
107
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
def progress
|
133
|
-
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
134
|
-
@staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
|
108
|
+
def progress_or_get_export_data
|
109
|
+
# common = Common.find_by(clazz: 'staff_type', name: '销售')
|
110
|
+
# @staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
|
135
111
|
@assessment_id = params[:q].present? && params[:q][:assessment_id].present? ? params[:q][:assessment_id]:'1'
|
136
|
-
@assessment_year = params[:q].present? && params[:q][:assessment_year] ? params[:q][:assessment_year] : '2022'
|
137
|
-
@assessments =AssessmentsSetting.where(assessment: @assessment_id)
|
138
|
-
|
139
|
-
|
140
|
-
|
112
|
+
@assessment_year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year] : '2022'
|
113
|
+
@assessments =AssessmentsSetting.where(assessment: @assessment_id)
|
114
|
+
.where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
|
115
|
+
.order("created_at desc")
|
116
|
+
if @assessments.present?
|
117
|
+
# 小优化
|
118
|
+
@staff_ids = params[:q].present? && params[:q][:staff_id].present? ? [params[:q][:staff_id].to_i]:@assessments.pluck(:staff_id).uniq
|
119
|
+
p @staff_ids
|
141
120
|
progress_main
|
142
|
-
|
143
|
-
|
144
|
-
@staff_ids.each do |s|
|
145
|
-
@staff_id = s
|
146
|
-
@assessments = @assessments.where(staff_id: s)
|
147
|
-
progress_main
|
148
|
-
end
|
149
|
-
@assessments = AssessmentsSetting.where(assessment: @assessment_id)
|
150
|
-
.where("assessment_year >= ? and assessment_year <= ?","#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:59".to_date )
|
151
|
-
.order("updated_at desc")
|
121
|
+
# 注意一下
|
122
|
+
@assessments = @assessments.where(staff_id: @staff_ids)
|
152
123
|
end
|
153
124
|
end
|
154
125
|
|
155
126
|
|
156
|
-
|
157
|
-
|
158
127
|
# todo 主方法 统计用户的数据
|
159
128
|
def progress_main
|
160
|
-
if @assessments.present?
|
161
|
-
a = []
|
162
129
|
case @assessment_id
|
163
130
|
when '1' # 签单金额
|
164
131
|
busniness_jurisdiction
|
165
|
-
|
132
|
+
signed_count
|
166
133
|
when '2' # 回款金额
|
167
|
-
|
134
|
+
collection_count
|
168
135
|
when '3' # 拜访量
|
169
136
|
visits
|
170
|
-
|
171
|
-
@customers = @customers.where(id: school_ids)
|
172
|
-
busniness_visits(a) # 商机拜访量
|
173
|
-
customer_visits(a) # 客户拜访量
|
137
|
+
customer_and_busniness_visits
|
174
138
|
when '4' # 新增商机数
|
175
139
|
busniness_jurisdiction
|
176
|
-
busniness_add
|
140
|
+
busniness_add
|
177
141
|
end
|
178
|
-
update_assessments_progress(a)
|
179
|
-
else
|
180
|
-
end
|
181
142
|
end
|
182
143
|
|
183
144
|
|
184
145
|
|
185
|
-
|
186
146
|
# 签单金额
|
187
|
-
def
|
147
|
+
def signed_count
|
188
148
|
# 过滤x类商机
|
189
|
-
ids = Common.where(extras: %w[
|
190
|
-
@businesses = @businesses.joins(
|
149
|
+
ids = Common.where.not(extras: %w[x_class]).pluck(:id)
|
150
|
+
@businesses = @businesses.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id in (?) ",ids)
|
151
|
+
.where("educode_sales_follow_ups.signed_date >= ? and educode_sales_follow_ups.signed_date <= ?",
|
152
|
+
"#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:59".to_date)
|
191
153
|
# 得到最新阶段为已签单商机
|
192
154
|
s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
193
155
|
@businesses = @businesses.joins("
|
194
156
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
195
157
|
").where("educode_sales_follow_ups.stage_id IN (?)",s_stage_ids)
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
case signed_date.to_s[0..6]
|
204
|
-
when "#{@assessment_year}-01"
|
205
|
-
a[0] = a[0].to_i + @follow_ups.first.actual_amount.to_i
|
206
|
-
when "#{@assessment_year}-02"
|
207
|
-
a[1] = a[1].to_i + @follow_ups.first.actual_amount.to_i
|
208
|
-
when "#{@assessment_year}-03"
|
209
|
-
a[2] = a[2].to_i + @follow_ups.first.actual_amount.to_i
|
210
|
-
when "#{@assessment_year}-04"
|
211
|
-
a[3] = a[3].to_i + @follow_ups.first.actual_amount.to_i
|
212
|
-
when "#{@assessment_year}-05"
|
213
|
-
a[4] = a[4].to_i + @follow_ups.first.actual_amount.to_i
|
214
|
-
when "#{@assessment_year}-06"
|
215
|
-
a[5] = a[5].to_i + @follow_ups.first.actual_amount.to_i
|
216
|
-
when "#{@assessment_year}-07"
|
217
|
-
a[6] = a[6].to_i + @follow_ups.first.actual_amount.to_i
|
218
|
-
when "#{@assessment_year}-08"
|
219
|
-
a[7] = a[7].to_i + @follow_ups.first.actual_amount.to_i
|
220
|
-
when "#{@assessment_year}-09"
|
221
|
-
a[8] = a[8].to_i + @follow_ups.first.actual_amount.to_i
|
222
|
-
when "#{@assessment_year}-10"
|
223
|
-
a[9] = a[9].to_i + @follow_ups.first.actual_amount.to_i
|
224
|
-
when "#{@assessment_year}-11"
|
225
|
-
a[10] = a[10].to_i + @follow_ups.first.actual_amount.to_i
|
226
|
-
when "#{@assessment_year}-12"
|
227
|
-
a[11] = a[11].to_i + @follow_ups.first.actual_amount.to_i
|
158
|
+
@staff_ids.each do |d|
|
159
|
+
# 注意
|
160
|
+
businesses = @businesses.where(staff_id: d)
|
161
|
+
b = []
|
162
|
+
a=[]
|
163
|
+
FollowUp.joins("JOIN educode_sales_businesses ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id").where("educode_sales_businesses.id in (?)",businesses.pluck(:id)).each do |m|
|
164
|
+
b << {value: m.actual_amount.to_i, date:m.signed_date.to_s[5..6].to_i}
|
228
165
|
end
|
166
|
+
|
167
|
+
count_data(b,a) # 统计数据
|
168
|
+
update_assessments_progress(a,d) # 批量更新assessment数据 事物 出现一个commit
|
229
169
|
end
|
230
|
-
}
|
231
170
|
end
|
232
171
|
|
233
172
|
|
234
|
-
# 回款金额
|
235
|
-
def
|
173
|
+
# 回款金额 权限
|
174
|
+
def collection_count
|
236
175
|
follow_up_ids = Business.pluck(:last_follow_up_id)
|
237
176
|
if @current_admin.is_admin?
|
238
177
|
@money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids)
|
@@ -252,38 +191,21 @@ module EducodeSales
|
|
252
191
|
end
|
253
192
|
end
|
254
193
|
# todo 1 :实际回款 0:计划回款 where(clazz: 1 OR 实际回款 ) 先把staff写死
|
255
|
-
@money_plans = @money_plans.where(clazz: 1).where.not(date_at: nil
|
256
|
-
@
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
a[1] = a[1].to_i + d.amount.to_i
|
262
|
-
when "#{@assessment_year}-03"
|
263
|
-
a[2] = a[2].to_i + d.amount.to_i
|
264
|
-
when "#{@assessment_year}-04"
|
265
|
-
a[3] = a[3].to_i + d.amount.to_i
|
266
|
-
when "#{@assessment_year}-05"
|
267
|
-
a[4] = a[4].to_i + d.amount.to_i
|
268
|
-
when "#{@assessment_year}-06"
|
269
|
-
a[5] = a[5].to_i + d.amount.to_i
|
270
|
-
when "#{@assessment_year}-07"
|
271
|
-
a[6] = a[6].to_i + d.amount.to_i
|
272
|
-
when "#{@assessment_year}-08"
|
273
|
-
a[7] = a[7].to_i + d.amount.to_i
|
274
|
-
when "#{@assessment_year}-09"
|
275
|
-
a[8] = a[8].to_i + d.amount.to_i
|
276
|
-
when "#{@assessment_year}-10"
|
277
|
-
a[9] = a[9].to_i + d.amount.to_i
|
278
|
-
when "#{@assessment_year}-11"
|
279
|
-
a[10] = a[10].to_i + d.amount.to_i
|
280
|
-
when "#{@assessment_year}-12"
|
281
|
-
a[11] = a[11].to_i + d.amount.to_i
|
194
|
+
@money_plans = @money_plans.where(clazz: 1).where.not(date_at: nil)
|
195
|
+
@staff_ids.each do |d|
|
196
|
+
b = []
|
197
|
+
a = []
|
198
|
+
@money_plans.where(staff_id: d).each do |m|
|
199
|
+
b << {date:m.date_at.to_s[5..6].to_i, value:m.amount.to_i}
|
282
200
|
end
|
201
|
+
count_data(b,a)
|
202
|
+
update_assessments_progress(a, d)
|
283
203
|
end
|
284
204
|
end
|
285
205
|
|
286
|
-
|
206
|
+
|
207
|
+
|
208
|
+
# 权限获取拜访量
|
287
209
|
def visits
|
288
210
|
if @current_admin.is_admin?
|
289
211
|
@customers = School.all
|
@@ -308,120 +230,45 @@ module EducodeSales
|
|
308
230
|
@customers = @customers.where(id: ids)
|
309
231
|
end
|
310
232
|
|
311
|
-
# 客户拜访量
|
312
|
-
def customer_visits(a)
|
313
|
-
@customers.each do |d|
|
314
|
-
customer_follows = EducodeSales::CustomerFollow.where(school_id: d.id)
|
315
|
-
customer_follows.each do |f|
|
316
|
-
case f.created_at.to_time.to_s[0..6]
|
317
|
-
when "#{@assessment_year}-01"
|
318
|
-
a[0] = a[0].to_i + 1
|
319
|
-
when "#{@assessment_year}-02"
|
320
|
-
a[1] = a[1].to_i + 1
|
321
|
-
when "#{@assessment_year}-03"
|
322
|
-
a[2] = a[2].to_i + 1
|
323
|
-
when "#{@assessment_year}-04"
|
324
|
-
a[3] = a[3].to_i + 1
|
325
|
-
when "#{@assessment_year}-05"
|
326
|
-
a[4] = a[4].to_i + 1
|
327
|
-
when "#{@assessment_year}-06"
|
328
|
-
a[5] = a[5].to_i + 1
|
329
|
-
when "#{@assessment_year}-07"
|
330
|
-
a[6] = a[6].to_i + 1
|
331
|
-
when "#{@assessment_year}-08"
|
332
|
-
a[7] = a[7].to_i + 1
|
333
|
-
when "#{@assessment_year}-09"
|
334
|
-
a[8] = a[8].to_i + 1
|
335
|
-
when "#{@assessment_year}-10"
|
336
|
-
a[9] = a[9].to_i + 1
|
337
|
-
when "#{@assessment_year}-11"
|
338
|
-
a[10] = a[10].to_i + 1
|
339
|
-
when "#{@assessment_year}-12"
|
340
|
-
a[11] = a[11].to_i + 1
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
233
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
when "#{@assessment_year}-02"
|
357
|
-
a[1] = a[1].to_i + 1
|
358
|
-
when "#{@assessment_year}-03"
|
359
|
-
a[2] = a[2].to_i + 1
|
360
|
-
when "#{@assessment_year}-04"
|
361
|
-
a[3] = a[3].to_i + 1
|
362
|
-
when "#{@assessment_year}-05"
|
363
|
-
a[4] = a[4].to_i + 1
|
364
|
-
when "#{@assessment_year}-06"
|
365
|
-
a[5] = a[5].to_i + 1
|
366
|
-
when "#{@assessment_year}-07"
|
367
|
-
a[6] = a[6].to_i + 1
|
368
|
-
when "#{@assessment_year}-08"
|
369
|
-
a[7] = a[7].to_i + 1
|
370
|
-
when "#{@assessment_year}-09"
|
371
|
-
a[8] = a[8].to_i + 1
|
372
|
-
when "#{@assessment_year}-10"
|
373
|
-
a[9] = a[9].to_i + 1
|
374
|
-
when "#{@assessment_year}-11"
|
375
|
-
a[10] = a[10].to_i + 1
|
376
|
-
when "#{@assessment_year}-12"
|
377
|
-
a[11] = a[11].to_i + 1
|
378
|
-
end
|
234
|
+
# 拜访量
|
235
|
+
def customer_and_busniness_visits
|
236
|
+
@staff_ids.each do |m|
|
237
|
+
customers = @customers.where(id: EducodeSales::CustomerExtension.where(customer_staff_id: m).pluck(:school_id))
|
238
|
+
b = []
|
239
|
+
a = []
|
240
|
+
CustomerFollow.joins(:school).where(school_id: customers.pluck(:id))
|
241
|
+
.where("Educode_Sales_customer_follows.created_at >= ? and Educode_Sales_customer_follows.created_at <= ?","#{@assessment_year}-01-01 ","#{@assessment_year}-12-31 23:59:59" )
|
242
|
+
.each do |d|
|
243
|
+
b << {value: 1, date: d.created_at.to_s[5..6].to_i}
|
379
244
|
end
|
245
|
+
FollowUp.joins(:business).where("Educode_Sales_businesses.id in (?)",EducodeSales::Business.where(school_id: customers.pluck(:id)).pluck(:id))
|
246
|
+
.where("Educode_Sales_follow_ups.created_at >= ? and Educode_Sales_follow_ups.created_at <= ?","#{@assessment_year}-01-01 00:00:00", "#{@assessment_year}-12-31 23:59:59").each do |d|
|
247
|
+
b << {date: d.created_at.to_s[5..6].to_i, value: 1}
|
248
|
+
end
|
249
|
+
count_data(b,a)
|
250
|
+
assessment = @assessments.where(staff_id: m)
|
251
|
+
update_assessments_progress(a, assessment)
|
380
252
|
end
|
381
|
-
|
382
|
-
# busniness_jurisdiction
|
383
|
-
# ids = Common.where(extras: %w[a_class b_class c_class d_claass e_class o_class x_class]).pluck(:id)
|
384
|
-
# @businesses = @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)
|
385
|
-
# @businesses = @businesses.where("educode_sales_businesses.follow_ups_count > ?",'0').where(staff_id: @staff_id)
|
253
|
+
end
|
386
254
|
|
387
255
|
|
388
256
|
|
389
257
|
|
390
258
|
# 新增商机数
|
391
|
-
def busniness_add
|
392
|
-
|
393
|
-
|
394
|
-
# 2.销售人员新增的商机数量,过滤E、O、X类商机,包含:ABCD类商机; 上面有连接follow_up表
|
395
|
-
ids = Common.where(extras: %w[a_class b_class c_class d_class]).pluck(:id) # 数组[1,5,2,15]
|
259
|
+
def busniness_add
|
260
|
+
@businesses = @businesses.where("educode_sales_businesses.created_at >= ? and educode_sales_businesses.created_at <= ?", "#{@assessment_year}-01-01 00:00:00","#{@assessment_year}-12-31 23:59:59")
|
261
|
+
ids = Common.where(extras: %w[a_class b_class c_class d_class]).pluck(:id)
|
396
262
|
@businesses = @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)
|
397
|
-
@
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
a[1] = a[1].to_i + 1
|
404
|
-
when "#{@assessment_year}-03"
|
405
|
-
a[2] = a[2].to_i + 1
|
406
|
-
when "#{@assessment_year}-04"
|
407
|
-
a[3] = a[3].to_i + 1
|
408
|
-
when "#{@assessment_year}-05"
|
409
|
-
a[4] = a[4].to_i + 1
|
410
|
-
when "#{@assessment_year}-06"
|
411
|
-
a[5] = a[5].to_i + 1
|
412
|
-
when "#{@assessment_year}-07"
|
413
|
-
a[6] = a[6].to_i + 1
|
414
|
-
when "#{@assessment_year}-08"
|
415
|
-
a[7] = a[7].to_i + 1
|
416
|
-
when "#{@assessment_year}-09"
|
417
|
-
a[8] = a[8].to_i + 1
|
418
|
-
when "#{@assessment_year}-10"
|
419
|
-
a[9] = a[9].to_i + 1
|
420
|
-
when "#{@assessment_year}-11"
|
421
|
-
a[10] = a[10].to_i + 1
|
422
|
-
when "#{@assessment_year}-12"
|
423
|
-
a[11] = a[11].to_i + 1
|
263
|
+
@staff_ids.each do |d|
|
264
|
+
businesses = @businesses.where(staff_id: d)
|
265
|
+
b = []
|
266
|
+
a = []
|
267
|
+
businesses.each do |m|
|
268
|
+
b << {date: m.created_at.to_s[5..6].to_i, value: 1}
|
424
269
|
end
|
270
|
+
count_data(b,a)
|
271
|
+
update_assessments_progress(a, d)
|
425
272
|
end
|
426
273
|
end
|
427
274
|
|
@@ -430,7 +277,7 @@ module EducodeSales
|
|
430
277
|
def busniness_jurisdiction
|
431
278
|
# busniness 权限
|
432
279
|
if @current_admin.is_admin?
|
433
|
-
@businesses = Business
|
280
|
+
@businesses = Business.all
|
434
281
|
else
|
435
282
|
level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
|
436
283
|
case level
|
@@ -443,26 +290,45 @@ module EducodeSales
|
|
443
290
|
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
444
291
|
@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)
|
445
292
|
else
|
446
|
-
@businesses = Business
|
293
|
+
@businesses = Business.all
|
447
294
|
end
|
448
295
|
end
|
449
296
|
end
|
450
297
|
|
298
|
+
|
451
299
|
# 更新assessments_settings表中数据
|
452
|
-
def update_assessments_progress(a)
|
300
|
+
def update_assessments_progress(a,staff_id)
|
453
301
|
a[12] = a[0].to_i + a[1].to_i + a[2].to_i
|
454
302
|
a[13] = a[3].to_i + a[4].to_i + a[5].to_i
|
455
303
|
a[14] = a[6].to_i + a[7].to_i + a[8].to_i
|
456
304
|
a[15] = a[9].to_i + a[10].to_i + a[11].to_i
|
457
305
|
a[16] = a[12].to_i + a[13].to_i + a[14].to_i + a[15].to_i
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
306
|
+
# 开启事物 处理 批量修改数据
|
307
|
+
ActiveRecord::Base.transaction do
|
308
|
+
assessments = @assessments.where(staff_id: staff_id)
|
309
|
+
assessments.update(annual_progress: a[16], first_quarter_progress: a[12], second_quarter_progress: a[13], third_quarter_progress: a[14], fourth_quarter_progress: a[15],
|
310
|
+
january_progress: a[0], february_progress: a[1], march_progress: a[2], april_progress: a[3], may_progress: a[4], june_progress: a[5],
|
311
|
+
july_progress: a[6], august_progress: a[7], september_progress: a[8], october_progress: a[9], november_progress: a[10], december_progress: a[11])
|
312
|
+
|
462
313
|
end
|
463
|
-
|
314
|
+
|
464
315
|
end
|
465
316
|
|
317
|
+
# 将统计到的数据转入a中
|
318
|
+
def count_data(arry,a)
|
319
|
+
arry.each do |d|
|
320
|
+
if a[d[:date]-1].present?
|
321
|
+
a[d[:date]-1] = a[d[:date]-1] + d[:value]
|
322
|
+
else
|
323
|
+
a[d[:date]-1] = d[:value]
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
466
332
|
|
467
333
|
|
468
334
|
|
@@ -2,6 +2,7 @@ require_dependency "educode_sales/application_controller"
|
|
2
2
|
|
3
3
|
module EducodeSales
|
4
4
|
class BusinessesController < ApplicationController
|
5
|
+
skip_before_action :verify_authenticity_token,only: [:following]
|
5
6
|
|
6
7
|
|
7
8
|
def index
|
@@ -27,6 +28,8 @@ module EducodeSales
|
|
27
28
|
gon.menus << { title: '添加周计划', event: 'week' }
|
28
29
|
gon.menus << { title: '添加月计划', event: 'month' }
|
29
30
|
end
|
31
|
+
|
32
|
+
gon.menus << { title: '关注', event: 'following' }
|
30
33
|
gon.menus << { title: '跟进时间线', event: 'time_line' }
|
31
34
|
if can?(:show_file, EducodeSales::Business)
|
32
35
|
gon.menus << { title: '附件管理', event: 'file' }
|
@@ -222,11 +225,13 @@ module EducodeSales
|
|
222
225
|
last_follow.created_at as latest_time,
|
223
226
|
last_follow.actual_amount,
|
224
227
|
(last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
|
225
|
-
last_follow.total_amount
|
228
|
+
last_follow.total_amount
|
229
|
+
").joins("
|
226
230
|
LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
|
227
231
|
").page(params[:page]).per(params[:limit])
|
228
232
|
|
229
233
|
end
|
234
|
+
|
230
235
|
end
|
231
236
|
end
|
232
237
|
|
@@ -581,6 +586,54 @@ module EducodeSales
|
|
581
586
|
end
|
582
587
|
end
|
583
588
|
end
|
589
|
+
#关注接口
|
590
|
+
def following
|
591
|
+
if brs=follow_business(@current_admin.user_id,params[:business_id])
|
592
|
+
if brs.delete
|
593
|
+
render json: {code:200,msg:"已取消关注"}
|
594
|
+
else
|
595
|
+
render json: {code:300,msg:"操作失败"}
|
596
|
+
end
|
597
|
+
else
|
598
|
+
brs=BusinessRelationShip.new(user_id:@current_admin.user_id, business_id:params[:business_id])
|
599
|
+
if brs.save
|
600
|
+
render json: {code:200,msg:"关注成功"}
|
601
|
+
else
|
602
|
+
render json: {code:300,msg:"操作失败"}
|
603
|
+
end
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
#我已关注的商机
|
608
|
+
def following_businesses
|
609
|
+
p=[]
|
610
|
+
BusinessRelationShip.select(:business_id).where(user_id:@current_admin.user_id).to_a.each { |d| p << d.business_id}
|
611
|
+
@businesses=Business.where(id:p)
|
612
|
+
@businesses=@businesses.select("
|
613
|
+
educode_sales_businesses.*,
|
614
|
+
last_follow.invitation_at,
|
615
|
+
last_follow.reception_at,
|
616
|
+
last_follow.service_time_long,
|
617
|
+
last_follow.service_end_time,
|
618
|
+
last_follow.service_start_time,
|
619
|
+
last_follow.bidded_date,
|
620
|
+
last_follow.signed_date,
|
621
|
+
last_follow.created_at as latest_time,
|
622
|
+
last_follow.actual_amount,
|
623
|
+
(last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
|
624
|
+
last_follow.total_amount").joins("
|
625
|
+
LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
|
626
|
+
").page(params[:page]).per(params[:limit])
|
627
|
+
end
|
628
|
+
|
629
|
+
def followed
|
630
|
+
if brs=follow_business(@current_admin.user_id,params[:business_id])
|
631
|
+
render json: {msg:'确定取消关注?'}
|
632
|
+
else
|
633
|
+
render json: {msg:'确定关注?'}
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
584
637
|
|
585
638
|
private
|
586
639
|
|
@@ -595,5 +648,9 @@ module EducodeSales
|
|
595
648
|
def edu_setting name
|
596
649
|
EduSetting.get(name)
|
597
650
|
end
|
651
|
+
|
652
|
+
def follow_business(user_id,business_id)
|
653
|
+
BusinessRelationShip.where(user_id:user_id,business_id:business_id).first
|
654
|
+
end
|
598
655
|
end
|
599
656
|
end
|
@@ -68,9 +68,6 @@ module EducodeSales
|
|
68
68
|
@customers = @customers.where("schools.province = ?", "#{params[:q][:area]}")
|
69
69
|
end
|
70
70
|
if params[:q].present? && params[:q][:staff_id].present?
|
71
|
-
p "--------------------------------------------------------------------------------------"
|
72
|
-
p params[:q][:staff_id]
|
73
|
-
p "--------------------------------------------------------------------------------------"
|
74
71
|
school_ids = EducodeSales::CustomerExtension.where(customer_staff_id: params[:q][:staff_id]).pluck(:school_id)
|
75
72
|
@customers = @customers.where(id: school_ids)
|
76
73
|
end
|
@@ -83,7 +83,7 @@ module EducodeSales
|
|
83
83
|
#新增商机数 得分规则
|
84
84
|
def add_businesses_score(staff_id,start_time,end_time)
|
85
85
|
if @current_admin.is_admin?
|
86
|
-
@businesses = Business
|
86
|
+
@businesses = Business.all
|
87
87
|
else
|
88
88
|
level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
|
89
89
|
case level
|
@@ -96,7 +96,7 @@ module EducodeSales
|
|
96
96
|
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
97
97
|
@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)
|
98
98
|
else
|
99
|
-
@businesses = Business
|
99
|
+
@businesses = Business.all
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -8,6 +8,10 @@ module EducodeSales
|
|
8
8
|
has_many :sale_plans
|
9
9
|
has_many :follow_ups
|
10
10
|
|
11
|
+
#关联关注
|
12
|
+
has_many :users,:class_name => 'EducodeSales::BusinessRelationShip',foreign_key: 'business_id',:dependent => :destroy
|
13
|
+
|
14
|
+
|
11
15
|
#每次查询时 默认的查询条件
|
12
16
|
default_scope -> {where(deleted_at: nil)}
|
13
17
|
|
@@ -20,5 +24,9 @@ module EducodeSales
|
|
20
24
|
EducodeSales::Recycle.create(source: self, deleter_id: user_id)
|
21
25
|
end
|
22
26
|
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
23
31
|
end
|
24
32
|
end
|