educode_sales 0.9.70 → 0.9.71

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.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/businesses_controller.rb +16 -2
  3. data/app/controllers/educode_sales/customers_controller.rb +45 -13
  4. data/app/controllers/educode_sales/plans_controller.rb +69 -19
  5. data/app/controllers/educode_sales/teachers_controller.rb +7 -0
  6. data/app/models/educode_sales/customer_follow.rb +1 -0
  7. data/app/models/educode_sales/sale_plan.rb +2 -0
  8. data/app/views/educode_sales/businesses/index.html.erb +37 -12
  9. data/app/views/educode_sales/customers/list.html.erb +67 -23
  10. data/app/views/educode_sales/customers/list.json.jbuilder +22 -10
  11. data/app/views/educode_sales/customers/show_customer_follow.html.erb +175 -0
  12. data/app/views/educode_sales/customers/show_customer_follow.json.jbuilder +13 -0
  13. data/app/views/educode_sales/customers/show_majors.html.erb +146 -0
  14. data/app/views/educode_sales/plans/_yearPlan.html.erb +6 -3
  15. data/app/views/educode_sales/plans/business_infos.json.jbuilder +10 -4
  16. data/app/views/educode_sales/plans/edit_bussiness_info.html.erb +13 -8
  17. data/app/views/educode_sales/plans/edit_bussiness_info_extra.html.erb +16 -73
  18. data/app/views/educode_sales/plans/edit_year_plan.html.erb +64 -5
  19. data/app/views/educode_sales/plans/new_year.html.erb +51 -3
  20. data/app/views/educode_sales/plans/plan_business_infos.json.jbuilder +7 -0
  21. data/app/views/educode_sales/plans/years_plan.json.jbuilder +43 -3
  22. data/app/views/educode_sales/teachers/_index.html.erb +15 -5
  23. data/app/views/educode_sales/teachers/index.json.jbuilder +7 -0
  24. data/config/routes.rb +3 -0
  25. data/lib/educode_sales/version.rb +1 -1
  26. metadata +9 -7
  27. data/app/assets/images/educode_sales/indexlogo.png +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 502334cc54a23143806d433d2f8049c0e9ae8961652b6af811d2225e6dfd4ece
4
- data.tar.gz: 884955d1facd79b398128fa275ca71edfc18802101c1baa1d35a7233f94c768a
3
+ metadata.gz: f06396ccf8dbcf15c84aecaa042d4c444335c9ef3a09c82d5ccced165beb429a
4
+ data.tar.gz: 1bbace4be30f8d50b507d9174b40cfec77073ff74e79188443359bdf1f146281
5
5
  SHA512:
6
- metadata.gz: 29ec5ea6847c23689ed1587710fbbde53b0bf4e71717a9c8cb232808e315fd881dfc17d3072c053d2d83329e0cfef801a31f9c5e51379eb0c7102594d456e31d
7
- data.tar.gz: 89cbc11577607d7e2bc16acb0b74044955b3b33fbefadd3fdb2352f35f3912a2ebaed880112c267bfea3a5732291b077972ea7180427b3a7427b8c9cbfa20d56
6
+ metadata.gz: 6034bfe4baf04919a142b18d57cdf9a8489fc9af2ec55597d36556a5ab69b6a9d1749d2c1271556a489f7d4907144e3c0b9db3769b7573cb967291fe3fb04b0b
7
+ data.tar.gz: 40edd2d1d9f49c081dad0251a573fadf67de0592755c54279d22518a80d2c3dea2777cb7d1daca05c7544f09a915078d79b3a63a9e94e4c2e025371f2a392e16
@@ -67,6 +67,7 @@ module EducodeSales
67
67
  # gon.menus << { title: '添加团队建议', event: 'suggest' }
68
68
  gon.menus << { title: '添加周计划', event: 'week' }
69
69
  gon.menus << { title: '添加月计划', event: 'month' }
70
+ gon.menus << { title: '添加年计划', event: 'year' }
70
71
  end
71
72
 
72
73
  gon.menus << { title: '关注', event: 'following' }
@@ -177,8 +178,21 @@ module EducodeSales
177
178
  @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
178
179
  end
179
180
  if params[:q].present? && params[:q][:department].present?
180
- departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:department]}%").pluck(:id)
181
- @businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
181
+ if params[:q][:department].include?("---")
182
+ # 从客户管理进来按部门显示商机
183
+ school_name, department = params[:q][:department].split("---")
184
+ if department
185
+ departments_ids = Department.joins(:school).where("schools.name = ? AND departments.name = ?", school_name, department).pluck(:id)
186
+ @businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
187
+ else
188
+ school = School.find_by(name: school_name)
189
+ @businesses = @businesses.where("educode_sales_businesses.school_id = ?", school&.id)
190
+ end
191
+ else
192
+ departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:department]}%").pluck(:id)
193
+ @businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
194
+ end
195
+
182
196
  end
183
197
  if params[:q].present? && params[:q][:staff_id].present?
184
198
  part_a_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is null AND educode_sales_businesses.staff_id = ?",params[:q][:staff_id]).ids
@@ -27,6 +27,11 @@ module EducodeSales
27
27
  render layout: false
28
28
  end
29
29
 
30
+ def show_majors
31
+ @department = Department.find(params[:id])
32
+ render layout: false
33
+ end
34
+
30
35
  def update_department
31
36
  department = Department.find(params[:id])
32
37
  department.update(name: params[:department_name])
@@ -165,36 +170,41 @@ module EducodeSales
165
170
  gon.school_tags = SchoolTag.where(for_missions: true).map { |d| {value: d.id, name: d.name } }
166
171
  end
167
172
  format.json do
173
+ @customers = School.from("(
174
+ SELECT schools.id, departments.id AS department_id, COUNT(department_majors.id) AS major_count
175
+ FROM schools
176
+ LEFT JOIN departments ON schools.id = departments.school_id
177
+ LEFT JOIN department_majors ON department_majors.department_id = departments.id
178
+ GROUP BY schools.id, departments.id
179
+ ) AS s")
168
180
  if @current_admin.is_admin?
169
- @customers = School.all
181
+ # @customers = School.all
170
182
  else
171
183
  level = @current_admin.role.role_areas.find_by(clazz: '客户管理').level
172
184
  case level
173
185
  when '自己'
174
186
  school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
175
- @customers = School.where(id: school_ids)
187
+ @customers = @customers.where(id: school_ids)
176
188
  when '区域'
177
189
  a_school_ids = School.where(province: @current_admin.areas.pluck(:name)).ids
178
190
  b_school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
179
191
  school_ids = a_school_ids + b_school_ids + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
180
- @customers = School.where(id: school_ids)
192
+ @customers = @customers.where(id: school_ids)
181
193
  else
182
- @customers = School.all
194
+ # @customers = School.all
183
195
  end
184
196
  end
185
197
 
186
198
  @customers = @customers.select("
187
199
  schools.*,
188
- departments.id AS department_id,
189
- departments.name AS department_name,
190
- department_majors.name AS major,
191
- department_majors.id AS major_id
192
- ")
193
-
194
- @customers = @customers.joins("
195
- LEFT JOIN departments ON schools.id = departments.school_id
196
- LEFT JOIN department_majors ON department_majors.department_id = departments.id
200
+ s.major_count,
201
+ s.department_id,
202
+ departments.name AS department_name
203
+ ").joins("
204
+ JOIN schools ON s.id = schools.id
205
+ LEFT JOIN departments ON s.department_id = departments.id
197
206
  ")
207
+
198
208
  part_a_ids = CustomerFollow.all.pluck(:school_id)
199
209
  part_b_ids = Business.where(id: EducodeSales::FollowUp.pluck(:business_id)).pluck(:school_id)
200
210
  ids = part_a_ids + part_b_ids + CustomerAdd.all.pluck(:school_id)
@@ -290,6 +300,28 @@ module EducodeSales
290
300
  end
291
301
  end
292
302
 
303
+ def show_customer_follow
304
+ respond_to do |format|
305
+ format.html do
306
+ @school_name = School.find(params[:id]).name
307
+ @area = School.find(params[:id]).province
308
+ @staff = EducodeSales::CustomerExtension.where(school_id: params[:id]).map { |d| d.customer_staff&.user&.real_name}.join("、")
309
+ render layout: false
310
+ end
311
+ format.json do
312
+ if params[:department_id].present?
313
+ @follow_ups = EducodeSales::CustomerFollow.where(department_id: params[:department_id])
314
+ else
315
+ @follow_ups = EducodeSales::CustomerFollow.where(school_id: params[:id])
316
+ end
317
+
318
+ @latest = @follow_ups.order(created_at: :desc).first
319
+ @follow_ups = @follow_ups.order("created_at desc")
320
+ @follow_ups = @follow_ups.page(params[:page]).per(params[:limit])
321
+ end
322
+ end
323
+ end
324
+
293
325
  def show_department
294
326
  @departments = School.find(params[:id]).departments
295
327
  @departments = @departments.order("created_at desc")
@@ -82,7 +82,7 @@ module EducodeSales
82
82
 
83
83
  def create_business_info
84
84
  business = Business.find_by(id: params[:business_id])
85
- info = @current_admin.business_infos.build(year: params[:year], business_id: business.id, clazz: params[:clazz])
85
+ info = @current_admin.business_infos.find_or_initialize_by(year: params[:year], business_id: business.id, clazz: params[:clazz])
86
86
  if info.save
87
87
  render_success
88
88
  else
@@ -104,7 +104,7 @@ module EducodeSales
104
104
  end
105
105
  business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
106
106
  @businesses = Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
107
- @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
107
+ @businesses = @businesses.map { |b| [b.name + "(#{b.department&.school&.name} #{b.department&.name})" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
108
108
  render layout: false
109
109
  end
110
110
 
@@ -132,18 +132,36 @@ module EducodeSales
132
132
  @business = Business.find_by(id: params[:business_id])
133
133
  business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
134
134
  @businesses =Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
135
- @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
135
+ @businesses = @businesses.map { |b| [b.name + "(#{b.department&.school&.name} #{b.department&.name})" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
136
136
  render layout: false
137
137
  end
138
138
 
139
139
  def new_year
140
+ @business = Business.find_by(id: params[:business_id])
140
141
  business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
141
142
  @businesses =Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
142
- @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
143
+ @businesses = @businesses.map { |b| [ b.name + "(#{b.department&.school&.name} #{b.department&.name})" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
143
144
  @clazz = EducodeSales::SalePlan::CLAZZ_NAME
144
145
  render layout: false
145
146
  end
146
147
 
148
+ # 暂时不用
149
+ def staff_businesses
150
+ if params[:q].present?
151
+ business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
152
+ @businesses = Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id)
153
+ if params[:q].present?
154
+ @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q]}%")
155
+ else
156
+ @businesses = @businesses.limit(10)
157
+ end
158
+ @businesses = @businesses.order(created_at: :desc)
159
+
160
+ @businesses = @businesses.map { |b| {name: b.name + "(#{b.department&.school&.name} #{b.department&.name})" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), value: b.id} }
161
+ render json: { data: @businesses, code: 0, msg: "success" }
162
+ end
163
+ end
164
+
147
165
  def new_monthly
148
166
  d = @current_admin
149
167
  area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
@@ -232,6 +250,7 @@ module EducodeSales
232
250
  EducodeSales::Recycle.create(source: d, deleter_id: @current_admin.id)
233
251
  end
234
252
  sale_plans.update_all(deleted_at: Time.now)
253
+ sale_plans.business_infos.delete_all
235
254
  render_success
236
255
  else
237
256
  sale_plan = SalePlan.find(params[:id])
@@ -282,30 +301,46 @@ module EducodeSales
282
301
  end
283
302
 
284
303
  def years_plan
304
+ @sale_plans = SalePlan.from("(
305
+ SELECT SUM(last_follow.budget_amount) AS budget_amounts, educode_sales_sale_plans.*, ss.annual,
306
+ SUM(IF(educode_sales_sale_plans.clazz = 1 AND educode_sales_business_infos.plan_sign_on IS NOT NULL, last_follow.budget_amount, 0)) AS clazz_1,
307
+ SUM(IF(educode_sales_sale_plans.clazz = 18 and plan_bid_on IS NOT NULL, last_follow.budget_amount, 0)) AS clazz_18,
308
+
309
+ (SUM(IF(educode_sales_sale_plans.clazz = 2 AND prepayment_plan_on IS NOT NULL AND check_fee_plan_on IS NOT NULL AND qa_plan_on IS NOT NULL, prepayment_amount, 0)) +
310
+ SUM(IF(educode_sales_sale_plans.clazz = 2 AND prepayment_plan_on IS NOT NULL AND check_fee_plan_on IS NOT NULL AND qa_plan_on IS NOT NULL, check_fee, 0)) +
311
+ SUM(IF(educode_sales_sale_plans.clazz = 2 AND prepayment_plan_on IS NOT NULL AND check_fee_plan_on IS NOT NULL AND qa_plan_on IS NOT NULL, qa_amount, 0)) ) AS clazz_2,
312
+ SUM(IF(educode_sales_sale_plans.clazz = 7, last_follow.budget_amount, 0)) AS clazz_7,
313
+
314
+ SUM(IF(last_follow.bidded_date IS NOT NULL, last_follow.actual_amount, 0)) AS finish_bid,
315
+ SUM(IF(last_follow.signed_date IS NOT NULL, last_follow.actual_amount, 0)) AS finish_sign,
316
+ SUM(educode_sales_businesses.return_money) AS finish_return_money
317
+
318
+ FROM educode_sales_sale_plans
319
+ JOIN educode_sales_businesses ON educode_sales_businesses.id = educode_sales_sale_plans.business_id
320
+ LEFT JOIN educode_sales_business_infos ON educode_sales_business_infos.sale_plan_id = educode_sales_sale_plans.id
321
+ LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id AND last_follow.deleted_at IS NULL
322
+ LEFT JOIN educode_sales_assessments_settings AS ss ON ss.staff_id = educode_sales_sale_plans.staff_id
323
+ AND YEAR(ss.assessment_year) = educode_sales_sale_plans.year AND ss.assessment = educode_sales_sale_plans.clazz
324
+ WHERE educode_sales_sale_plans.deleted_at IS NULL
325
+ GROUP BY educode_sales_sale_plans.staff_id, educode_sales_sale_plans.clazz, educode_sales_sale_plans.year
326
+ ) AS educode_sales_sale_plans
327
+ ")
285
328
  if @current_admin.is_admin?
286
- @sale_plans = SalePlan
329
+ # @sale_plans = SalePlan
287
330
  else
288
331
  level = @current_admin.role.role_areas.find_by(clazz: '销售计划').level
289
332
  case level
290
333
  when '自己'
291
- @sale_plans = SalePlan.where(staff_id: @current_admin.id)
334
+ @sale_plans = @sale_plans.where(staff_id: @current_admin.id)
292
335
  when '区域'
293
336
  staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
294
337
  business_ids = Business.where(school_id: StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)).pluck(:id)
295
- @sale_plans = SalePlan.where("educode_sales_sale_plans.staff_id in (?) OR educode_sales_sale_plans.staff_id = ? OR educode_sales_sale_plans.business_id in (?)", staff_ids, @current_admin.id,business_ids)
338
+ @sale_plans = @sale_plans.where("educode_sales_sale_plans.staff_id in (?) OR educode_sales_sale_plans.staff_id = ? OR educode_sales_sale_plans.business_id in (?)", staff_ids, @current_admin.id,business_ids)
296
339
  else
297
- @sale_plans = SalePlan
340
+ # @sale_plans = SalePlan
298
341
  end
299
342
  end
300
343
  @sale_plans = @sale_plans.where.not(year: nil)
301
- @sale_plans = @sale_plans.select("SUM(last_follow.budget_amount) AS budget_amounts, educode_sales_sale_plans.*, ss.annual")
302
- @sale_plans = @sale_plans.joins("
303
- JOIN educode_sales_businesses ON educode_sales_businesses.id = educode_sales_sale_plans.business_id
304
- LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id AND last_follow.deleted_at IS NULL
305
- LEFT JOIN educode_sales_assessments_settings AS ss ON ss.staff_id = educode_sales_sale_plans.staff_id
306
- AND YEAR(ss.assessment_year) = educode_sales_sale_plans.year AND ss.assessment = educode_sales_sale_plans.clazz")
307
-
308
- @sale_plans = @sale_plans.group("educode_sales_sale_plans.staff_id, clazz, year")
309
344
 
310
345
  @sale_plans = @sale_plans.where(deleted_at: nil)
311
346
 
@@ -345,12 +380,26 @@ module EducodeSales
345
380
  end
346
381
 
347
382
  def edit_bussiness_info_extra
348
- @business_info = @current_admin.business_infos.find(params[:id])
383
+ @business_info = EducodeSales::BusinessInfo.find(params[:id])
349
384
  render layout: false
350
385
  end
351
386
 
352
387
  def plan_business_infos
353
- @data = @current_admin.business_infos.where(year: params[:year])
388
+ if params[:q] && params[:q][:year_search].present?
389
+ @data = EducodeSales::BusinessInfo.where(year: params[:q][:year_search], staff_id: params[:staff_id])
390
+ else
391
+ @data = EducodeSales::BusinessInfo.where(year: params[:year], staff_id: params[:staff_id])
392
+ end
393
+
394
+ @data = @data.where.not(sale_plan_id: nil)
395
+
396
+ if params[:q] && params[:q][:clazz].present?
397
+ @data = @data.where(clazz: params[:q][:clazz])
398
+ end
399
+
400
+ if params[:q] && params[:q][:department].present?
401
+ @data = @data.joins(business: [department: :school]).where("schools.name like ?", "%#{params[:q][:department]}%")
402
+ end
354
403
 
355
404
  if params[:sort].present? && params[:sort][:field]
356
405
  @data = @data.order("#{params[:sort][:field]} #{params[:sort][:order]}")
@@ -370,7 +419,7 @@ module EducodeSales
370
419
  end
371
420
 
372
421
  def update_business_info_extra
373
- business_info = @current_admin.business_infos.find(params[:id])
422
+ business_info = EducodeSales::BusinessInfo.find(params[:id])
374
423
  if business_info.update(update_business_info_extra_params)
375
424
  render_success
376
425
  else
@@ -392,6 +441,7 @@ module EducodeSales
392
441
  end
393
442
 
394
443
  def edit_year_plan
444
+ @clazz = EducodeSales::SalePlan::CLAZZ_NAME
395
445
  render layout: false
396
446
  end
397
447
 
@@ -28,6 +28,7 @@ module EducodeSales
28
28
  else
29
29
  @staff_manage = Staff.none
30
30
  end
31
+
31
32
  @follow_upers = Staff.includes(:user).map { |d| [d.user.real_name, d.id]}
32
33
  @staffs = Staff.includes(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
33
34
  @more = can?(:create, EducodeSales::OperationPlan) || can?(:update, EducodeSales::Teacher) || can?(:destroy, EducodeSales::Teacher)
@@ -45,10 +46,16 @@ module EducodeSales
45
46
  end
46
47
  format.json do
47
48
  @staff_manages = {}
49
+ @sales_manages = {}
48
50
  role = EducodeSales::Role.find_by(name: '生态经理')
49
51
  EducodeSales::Common.joins(market_areas: :staff).includes(market_areas: :staff).where(clazz: '区域').where("educode_sales_staffs.role_id = #{role.id}").each do |d|
50
52
  @staff_manages[d.name] = d.market_areas.map { |d| d.staff&.user&.real_name }.uniq.compact
51
53
  end if role
54
+
55
+ sales_common = EducodeSales::Common.find_by(clazz: 'staff_type', name: '销售')
56
+ EducodeSales::Common.joins(market_areas: :staff).includes(market_areas: :staff).where(clazz: '区域').where("educode_sales_staffs.job_type = ?", sales_common.id).each do |d|
57
+ @sales_manages[d.name] = d.market_areas.map { |d| d.staff&.user&.real_name }.uniq.compact
58
+ end
52
59
 
53
60
  if @current_admin.is_admin?
54
61
  @teachers = Teacher
@@ -2,5 +2,6 @@ module EducodeSales
2
2
  class CustomerFollow < ApplicationRecord
3
3
  belongs_to :staff
4
4
  belongs_to :school
5
+ belongs_to :department, optional: true
5
6
  end
6
7
  end
@@ -5,6 +5,8 @@ module EducodeSales
5
5
  belongs_to :staff
6
6
  validates :business_id, presence: true
7
7
 
8
+ has_many :business_infos
9
+
8
10
  # validates :month, presence: true
9
11
 
10
12
  CLAZZ_NAME = {'商机目标' => 7, '中标目标' => 18, '签单目标' => 1, '回款目标' => 2}
@@ -390,12 +390,6 @@
390
390
  fixed: 'left',
391
391
  hide: gon.filter.name
392
392
  },
393
- {
394
- field: 'area',
395
- width: 100,
396
- title: '地域',
397
- hide: gon.filter.area
398
- },
399
393
  {
400
394
  field: 'school',
401
395
  width: 150,
@@ -403,12 +397,6 @@
403
397
  templet: '#school_name',
404
398
  hide: gon.filter.school
405
399
  },
406
- {
407
- field: 'property',
408
- width: 150,
409
- title: '客户类型',
410
- hide: gon.filter.property
411
- },
412
400
  {
413
401
  field: 'department',
414
402
  width: 150,
@@ -421,6 +409,18 @@
421
409
  width: 160,
422
410
  title: '专业',
423
411
  },
412
+ {
413
+ field: 'area',
414
+ width: 100,
415
+ title: '地域',
416
+ hide: gon.filter.area
417
+ },
418
+ {
419
+ field: 'property',
420
+ width: 150,
421
+ title: '客户类型',
422
+ hide: gon.filter.property
423
+ },
424
424
  {
425
425
  field: 'follow_ups_count',
426
426
  title: '跟进',
@@ -705,6 +705,9 @@
705
705
  case 'month':
706
706
  month(id);
707
707
  break;
708
+ case 'year':
709
+ year(id);
710
+ break;
708
711
  case 'edit':
709
712
  edit(id);
710
713
  break;
@@ -737,6 +740,9 @@
737
740
  case 'month':
738
741
  month(id);
739
742
  break;
743
+ case 'year':
744
+ year(id);
745
+ break;
740
746
  case 'edit':
741
747
  edit(id);
742
748
  break;
@@ -861,6 +867,25 @@
861
867
  layer.full(sindex);
862
868
  });
863
869
  }
870
+
871
+ function year(id) {
872
+ var content = miniPage.getHrefContent('/missions/plans/new_year?business_id=' + id);
873
+ var openWH = miniPage.getOpenWidthHeight();
874
+
875
+ yindex = layer.open({
876
+ title: '添加年计划',
877
+ type: 1,
878
+ shade: 0.2,
879
+ maxmin: true,
880
+ shadeClose: true,
881
+ area: [openWH[0] + 'px', openWH[1] + 'px'],
882
+ offset: [openWH[2] + 'px', openWH[3] + 'px'],
883
+ content: content
884
+ });
885
+ $(window).on("resize", function () {
886
+ layer.full(sindex);
887
+ });
888
+ }
864
889
  function following(id) {
865
890
  $.ajax({
866
891
  type: "get",
@@ -72,13 +72,20 @@
72
72
  <% end %>
73
73
  </script>
74
74
  <script type="text/html" id="business">
75
- <a href="/missions/businesses?school={{d.name}}" class="layui-table-link">{{ d.business }}</a>
75
+ <a href="/missions/businesses?school={{d.unit}}" class="layui-table-link">{{ d.business }}</a>
76
76
  </script>
77
77
  <script type="text/html" id="name">
78
78
  <a href="<%= base_url %>/colleges/{{d.id}}/statistics" class="layui-table-link" target="_blank">{{ d.name }}</a>
79
79
  </script>
80
80
  <script type="text/html" id="department">
81
- <a href="javascript:void(0);" lay-event="department" class="layui-table-link">{{ d.department }}</a>
81
+ <a href="javascript:void(0);" lay-event="department" class="layui-table-link">{{ d.department || '--' }}</a>
82
+ </script>
83
+ <script type="text/html" id="major">
84
+ {{# if (d.department_id) { }}
85
+ <a href="javascript:void(0);" lay-event="major" class="layui-table-link">{{ d.major_count }}</a>
86
+ {{# } else { }}
87
+ {{ d.major_count }}
88
+ {{# }}}
82
89
  </script>
83
90
  <script type="text/html" id="follow">
84
91
  <a href="javascript:void(0);" lay-event="follow" class="layui-table-link">{{ d.follow }}</a>
@@ -145,22 +152,24 @@
145
152
  field: 'department',
146
153
  width: 160,
147
154
  title: '部门',
155
+ templet: "#department"
148
156
  },
149
157
  {
150
- field: 'major',
158
+ field: 'major_count',
151
159
  width: 160,
152
160
  title: '专业',
161
+ templet: "#major"
153
162
  },
154
- // {
155
- // field: 'teacher_counts',
156
- // width: 100,
157
- // title: '教师数',
158
- // },
159
- // {
160
- // field: 'student_counts',
161
- // width: 100,
162
- // title: '学生数',
163
- // },
163
+ {
164
+ field: 'teacher_counts',
165
+ width: 100,
166
+ title: '教师数',
167
+ },
168
+ {
169
+ field: 'student_counts',
170
+ width: 100,
171
+ title: '学生数',
172
+ },
164
173
 
165
174
  {
166
175
  field: 'area',
@@ -192,7 +201,7 @@
192
201
  },
193
202
  {
194
203
  field: 'staff',
195
- width: 100,
204
+ width: 150,
196
205
  title: '负责人',
197
206
  },
198
207
  {
@@ -399,7 +408,6 @@
399
408
  table.on('tool(customers_table)', function (obj) {
400
409
  var data = obj.data;
401
410
  id = data.id;
402
- console.log(data)
403
411
  department_id = data.department_id;
404
412
  major_id = data.major_id;
405
413
  if (obj.event === 'edit') { // 监听添加操作
@@ -476,8 +484,6 @@
476
484
  offset: [openWH[2] + 'px', openWH[3] + 'px'],
477
485
  content: content,
478
486
  success: function (layero, index) {
479
- // 重新渲染弹层中的下拉选择框select
480
- // form.render('select');
481
487
  }
482
488
  });
483
489
  $(window).on("resize", function () {
@@ -497,8 +503,7 @@
497
503
  offset: [openWH[2] + 'px', openWH[3] + 'px'],
498
504
  content: content,
499
505
  success: function (layero, index) {
500
- // 重新渲染弹层中的下拉选择框select
501
- form.render('select');
506
+ form.render('select');
502
507
  }
503
508
  });
504
509
  $(window).on("resize", function () {
@@ -517,15 +522,56 @@
517
522
  offset: [openWH[2] + 'px', openWH[3] + 'px'],
518
523
  content: content,
519
524
  success: function (layero, index) {
520
- // 重新渲染弹层中的下拉选择框select
521
525
  form.render('select');
522
526
  }
523
527
  });
524
528
  $(window).on("resize", function () {
525
529
  layer.full(index);
526
530
  });
527
- } else if (obj.event === 'follow' || obj.event === 'name' || obj.event === 'department') {
531
+ } else if (obj.event === 'follow' || obj.event === 'name') {
532
+ id = data.id
533
+ department_id = data.department_id;
534
+ time = data.last_follow_time || ''
535
+ content = miniPage.getHrefContent('/missions/customers/show_customer_follow?id=' + data.id + "&department_id=" + data.department_id);
536
+ openWH = miniPage.getOpenWidthHeight();
537
+ index = layer.open({
538
+ title: '客户列表/' + data.name,
539
+ type: 1,
540
+ shade: 0.2,
541
+ maxmin: true,
542
+ shadeClose: true,
543
+ area: [openWH[0] + 'px', openWH[1] + 'px'],
544
+ offset: [openWH[2] + 'px', openWH[3] + 'px'],
545
+ content: content,
546
+ success: function (layero, index) {
547
+ }
548
+ });
549
+ $(window).on("resize", function () {
550
+ layer.full(index);
551
+ });
552
+ } else if (obj.event == 'major') {
553
+ department_id = obj.data.department_id;
554
+ content = miniPage.getHrefContent('/missions/customers/show_majors?id='+ department_id);
555
+ openWH = miniPage.getOpenWidthHeight();
556
+ edit_index1 = layer.open({
557
+ title: '专业',
558
+ type: 1,
559
+ shade: 0.2,
560
+ maxmin: true,
561
+ shadeClose: true,
562
+ area: [openWH[0] + 'px', openWH[1] + 'px'],
563
+ offset: [openWH[2] + 'px', openWH[3] + 'px'],
564
+ content: content,
565
+ success: function (layero, index) {
566
+ form.render('select');
567
+ }
568
+ });
569
+ $(window).on("resize", function () {
570
+ layer.full(index);
571
+ });
572
+ } else if (obj.event == 'department') {
528
573
  id = data.id
574
+ department_id = data.department_id;
529
575
  time = data.last_follow_time || ''
530
576
  content = miniPage.getHrefContent('/missions/customers/show_follow?id=' + data.id);
531
577
  openWH = miniPage.getOpenWidthHeight();
@@ -539,8 +585,6 @@
539
585
  offset: [openWH[2] + 'px', openWH[3] + 'px'],
540
586
  content: content,
541
587
  success: function (layero, index) {
542
- // 重新渲染弹层中的下拉选择框select
543
- // form.render('select');
544
588
  }
545
589
  });
546
590
  $(window).on("resize", function () {
@@ -1,9 +1,15 @@
1
1
  x = EducodeSales::Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
2
2
  json.data do
3
3
  json.array! @customers do |d|
4
- business_ids = EducodeSales::Business.where(school_id: d.id).ids
4
+ if d['department_id']
5
+ business_ids = EducodeSales::Business.where(department_id: d['department_id']).ids
6
+ customer_follows = EducodeSales::CustomerFollow.where(department_id: d['department_id'])
7
+ else
8
+ business_ids = EducodeSales::Business.where(school_id: d.id).ids
9
+ customer_follows = EducodeSales::CustomerFollow.where(school_id: d.id)
10
+ end
5
11
  follow_ups = EducodeSales::FollowUp.where(business_id: business_ids)
6
- customer_follows = EducodeSales::CustomerFollow.where(school_id: d.id)
12
+
7
13
  a_last_follow_time = follow_ups.last&.created_at&.to_s
8
14
  b_last_follow_time = customer_follows.last&.created_at&.to_s
9
15
  if a_last_follow_time.present? && b_last_follow_time.present?
@@ -15,15 +21,21 @@ json.data do
15
21
  json.name d.name
16
22
  json.area d.province
17
23
  json.property d.school_tags.where(for_missions: true).pluck(:name).join("、")
18
- json.business EducodeSales::Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_businesses.school_id = ?", d.id).size
19
- json.follow follow_ups.size + customer_follows.size
20
- json.staff EducodeSales::CustomerExtension.find_by(school_id: d.id)&.customer_staff&.user&.real_name
24
+ if d['department_id']
25
+ json.business EducodeSales::Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_businesses.department_id = ?", d['department_id']).size
26
+ else
27
+ json.business EducodeSales::Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_businesses.school_id = ?", d.id).size
28
+ end
29
+ json.unit "#{d.name}---#{d['department_name']}"
30
+
31
+ # json.follow follow_ups.size + customer_follows.size
32
+ json.follow customer_follows.size
33
+ json.staff EducodeSales::CustomerExtension.where(school_id: d.id).map { |d| d.customer_staff&.user&.real_name }.join("、")
21
34
  json.department d['department_name'] || ''
22
- json.major d['major'] || ''
23
- json.major_id d.major_id || ''
24
- json.department_id d.department_id || ''
25
- # json.teacher_counts UserExtension.where(department_id: d.department_id, identity: 'teacher').size
26
- #json.student_counts UserExtension.where(department_id: d.department_id, identity: 'student').size
35
+ json.major_count d['major_count']
36
+ json.department_id d['department_id'] || ''
37
+ json.teacher_counts UserExtension.where(department_id: d.department_id, identity: 'teacher').size
38
+ json.student_counts UserExtension.where(department_id: d.department_id, identity: 'student').size
27
39
  end
28
40
  end
29
41