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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2972ed1989662bb4f717d0a4d84bd29f5605fa53006e744de50836bde4273d51
4
- data.tar.gz: 9c64c442924ed94d857c29c9141d22ea66714f237671d46964033e46a075fcef
3
+ metadata.gz: e9403e25df2848c96f744c79481e62ea3ebe44c6da7d265bd1e107885c13b108
4
+ data.tar.gz: 994b9567c3b88d6a804b43484447932725dcfe5d3c0f1e6113233c309a1f1f62
5
5
  SHA512:
6
- metadata.gz: 25648696a64348151f0380b1c8c160b12ed21263f06417a48aaff9529252048764edd343a78ef88e899c336bbd19cb007168d41dbbbaa7f90d2b75cff656a2aa
7
- data.tar.gz: 7e519c3723917de704f95e17d809503aab65401b56a979c48c0a45d3a88f1837b8080305af33994a410c2e10cbff1ccc2d9cdba1ac8652cfe8221ddb1ff21b18
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 = @assessments.where("assessment_year >= ? and assessment_year <= ?", "#{@year}-01-01 00:00:00".to_date, "#{@year}-12-31 23:59:00".to_date)
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
- common = Common.find_by(clazz: 'staff_type', name: '销售')
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
- where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
139
- if params[:q].present? && params[:q][:staff_id].present?
140
- @assessments = @assessments.where(staff_id: params[:q][:staff_id])
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
- else
143
- # @assessments = @assessments.where(staff_id: @staff_ids) 注意 这样写有问题
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
- signed_amount(a)
132
+ signed_count
166
133
  when '2' # 回款金额
167
- collection_amount(a)
134
+ collection_count
168
135
  when '3' # 拜访量
169
136
  visits
170
- school_ids = EducodeSales::CustomerExtension.where(customer_staff_id: @staff_id).pluck(:school_id)
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(a)
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 signed_amount(a)
147
+ def signed_count
188
148
  # 过滤x类商机
189
- ids = Common.where(extras: %w[a_class b_class c_class d_claass e_class o_class]).pluck(:id)
190
- @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)
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
- # 得到指定staff的商机------------先暂时指定
197
- @businesses = @businesses.where(staff_id: @staff_id)
198
- # businesses each操作并 获取最新根新记录
199
- @businesses.each { |d| d
200
- @follow_ups = d.follow_ups.where.not(signed_date: nil).order("signed_date desc")
201
- if @follow_ups.first.present?
202
- signed_date = @follow_ups.first.signed_date.to_time || '1000-01-01 00:00:00'.to_time
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 collection_amount(a)
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 ).where(staff_id: @staff_id)
256
- @money_plans.each do |d|
257
- case d.date_at.to_s[0..6]
258
- when "#{@assessment_year}-01"
259
- a[0] = a[0].to_i + d.amount.to_i
260
- when "#{@assessment_year}-02"
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
- def busniness_visits(a)
349
- @customers.each do |d|
350
- business_ids = EducodeSales::Business.where(school_id: d.id).ids
351
- follow_ups = EducodeSales::FollowUp.where(business_id: business_ids)
352
- follow_ups.each do |f|
353
- case f.created_at.to_time.to_s[0..6]
354
- when "#{@assessment_year}-01"
355
- a[0] = a[0].to_i + 1
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
- end
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(a)
392
- # 1.新增商机数统计在哪一个时间段?以商机的创建时间为准;先默认 过滤2022之前的 businesses -created_et deleted_at follow_ups_count
393
- @businesses = @businesses.where("educode_sales_businesses.created_at >= ? and educode_sales_businesses.created_at <= ?", "#{@assessment_year}-01-01 00:00:00".to_date,"#{@assessment_year}-12-31 23:59:59".to_date)
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
- @businesses = @businesses.where(staff_id: @staff_id)
398
- @businesses.each do |d|
399
- case d.created_at.to_time.to_s[0..6]
400
- when "#{@assessment_year}-01"
401
- a[0] = a[0].to_i + 1
402
- when "#{@assessment_year}-02"
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
- @assessments.each do |d|
459
- d.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],
460
- january_progress: a[0], february_progress: a[1], march_progress: a[2], april_progress: a[3], may_progress: a[4], june_progress: a[5],
461
- july_progress: a[6], august_progress: a[7], september_progress: a[8], october_progress: a[9], november_progress: a[10], december_progress: a[11])
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
- @assessments.order("created_at desc")
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").joins("
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
@@ -0,0 +1,6 @@
1
+ module EducodeSales
2
+ class BusinessRelationShip < ApplicationRecord
3
+ belongs_to :user
4
+ belongs_to :follow_business, :class_name => 'EducodeSales::Business',foreign_key: "business_id"
5
+ end
6
+ end