educode_sales 0.9.68 → 0.9.70

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/educode_sales/indexlogo.png +0 -0
  3. data/app/assets/javascripts/educode_sales/extent/treeTable.js +235 -0
  4. data/app/controllers/educode_sales/customers_controller.rb +112 -0
  5. data/app/controllers/educode_sales/follow_ups_controller.rb +6 -0
  6. data/app/controllers/educode_sales/projects_controller.rb +423 -0
  7. data/app/controllers/educode_sales/roles_controller.rb +4 -1
  8. data/app/controllers/educode_sales/teachers_controller.rb +42 -14
  9. data/app/helpers/educode_sales/application_helper.rb +1 -0
  10. data/app/models/educode_sales/business.rb +21 -5
  11. data/app/models/educode_sales/business_history.rb +8 -0
  12. data/app/models/educode_sales/eco_staff.rb +6 -0
  13. data/app/models/educode_sales/permission.rb +2 -1
  14. data/app/models/educode_sales/project.rb +53 -0
  15. data/app/models/educode_sales/role_area.rb +2 -1
  16. data/app/views/educode_sales/activities/show_teachers.html.erb +1 -1
  17. data/app/views/educode_sales/businesses/index.html.erb +13 -0
  18. data/app/views/educode_sales/businesses/index.json.jbuilder +5 -1
  19. data/app/views/educode_sales/businesses/time_line.html.erb +10 -5
  20. data/app/views/educode_sales/customers/edit_major.html.erb +876 -0
  21. data/app/views/educode_sales/customers/list.html.erb +601 -0
  22. data/app/views/educode_sales/customers/list.json.jbuilder +33 -0
  23. data/app/views/educode_sales/follow_ups/index.json.jbuilder +2 -2
  24. data/app/views/educode_sales/projects/detail.html.erb +273 -0
  25. data/app/views/educode_sales/projects/edit.html.erb +246 -0
  26. data/app/views/educode_sales/projects/history.html.erb +41 -0
  27. data/app/views/educode_sales/projects/index.html.erb +718 -0
  28. data/app/views/educode_sales/projects/index.json.jbuilder +69 -0
  29. data/app/views/educode_sales/teachers/_index.html.erb +28 -1
  30. data/app/views/educode_sales/teachers/edit.html.erb +10 -3
  31. data/app/views/educode_sales/teachers/index.json.jbuilder +3 -0
  32. data/app/views/layouts/educode_sales/application.html.erb +25 -0
  33. data/config/routes.rb +12 -0
  34. data/db/migrate/20230412083510_add_p_staff_id_to_businesses.rb +20 -0
  35. data/db/migrate/20230412092000_create_business_histories.rb +10 -0
  36. data/db/migrate/20230413015619_add_permissions_to_projects.rb +11 -0
  37. data/db/migrate/20230413031029_add_pre_time_to_businesses.rb +5 -0
  38. data/db/migrate/20230414031409_add_major_educode_sales_customer_follows.rb +12 -0
  39. data/db/migrate/20230414035655_create_educode_sales_eco_staffs.rb +11 -0
  40. data/lib/educode_sales/version.rb +1 -1
  41. metadata +26 -6
@@ -0,0 +1,423 @@
1
+ require_dependency "educode_sales/application_controller"
2
+
3
+ module EducodeSales
4
+ class ProjectsController < ApplicationController
5
+
6
+ before_action :find_project, only: [:edit, :destroy, :detail, :history, :update, :recycle]
7
+
8
+ def index
9
+ authorize! :contract_business, Business
10
+ respond_to do |format|
11
+ format.html do
12
+ common = Common.find_by(clazz: 'staff_type', name: '销售')
13
+ @staffs = Staff.joins(:user).where(job_type: common.id).where.not(role_id: 11).map { |d| [d.user.real_name, d.id] }
14
+ gon.staffs = Staff.joins(:user).where(job_type: common.id).where.not(role_id: 11).map { |d| { name: d.user.real_name, value: d.id } }
15
+ @more = true
16
+ gon.menus = []
17
+ gon.export_menus = []
18
+ gon.place = params[:place_id].present? ? [{ value: params[:place_id], name: EducodeSales::Place.find(params[:place_id]).name }] : []
19
+
20
+ bussiness_type = []
21
+ if params[:type]
22
+ # 项目类型
23
+ bussiness_type = EducodeSales::Business.include_types(params[:type]) || []
24
+ end
25
+
26
+ business_step = []
27
+ if params[:step]
28
+ # 项目阶段
29
+ business_step = EducodeSales::Business.include_steps(params[:step]) || []
30
+ end
31
+
32
+ if params[:business_year].present? && params[:business_year] != '全部'
33
+ gon.business_year = params[:business_year]
34
+ end
35
+
36
+ if params[:bidded_date_year].present? && params[:bidded_date_year] != '全部'
37
+ if params[:step] == '应收款'
38
+ gon.bidded_date = "2015-01-01" + " - " + Time.new(params[:bidded_date_year]).end_of_year.strftime("%Y-%m-%d")
39
+ else
40
+ gon.bidded_date = Time.new(params[:bidded_date_year]).strftime("%Y-%m-%d") + " - " + Time.new(params[:bidded_date_year]).end_of_year.strftime("%Y-%m-%d")
41
+ end
42
+ end
43
+
44
+ if params[:signed_date_year].present? && params[:signed_date_year] != '全部'
45
+ gon.signed_date = Time.new(params[:signed_date_year]).strftime("%Y-%m-%d") + " - " + Time.new(params[:signed_date_year]).end_of_year.strftime("%Y-%m-%d")
46
+ end
47
+
48
+ if params[:date_at].present? && params[:date_at] != '全部'
49
+ # 回款时间
50
+ gon.date_at = Time.new(params[:date_at]).strftime("%Y-%m-%d") + " - " + Time.new(params[:date_at]).end_of_year.strftime("%Y-%m-%d")
51
+ end
52
+
53
+ gon.business_type = Common.where(clazz: 'business_type').map do |d|
54
+ { value: d.id, name: d.name, selected: bussiness_type.include?(d.extras) }
55
+ end
56
+
57
+ gon.business_step = Common.where(clazz: 'business_step', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).order("position").map do |d|
58
+ { value: d.id, name: d.name, selected: business_step.include?(d.name) }
59
+ end
60
+
61
+ filter = Filter.find_or_create_by(staff_id: @current_admin.id, clazz: "businesses_list")
62
+ if filter.extras.present?
63
+ if filter.extras['area'].nil?
64
+ filter.extras['area'] = 1
65
+ filter.extras['property'] = 1
66
+ filter.extras['sale_way'] = 1
67
+ end
68
+ filter.save
69
+ gon.filter = filter.extras
70
+ else
71
+ gon.filter = { 'area': 1, 'property': 1, 'sale_way': 1 }
72
+ end
73
+ end
74
+ format.json do
75
+ if @current_admin.is_admin?
76
+ @businesses = Business
77
+ else
78
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
79
+ case level
80
+ when '自己'
81
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
82
+ @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
83
+ when '区域'
84
+ # 查看区域商机,需要排除掉其它人员手上的监管学校
85
+ other_staff_school_id = EducodeSales::StaffSchool.where.not(staff_id: @current_admin.id).where("school_id IN (SELECT school_id FROM educode_sales_staff_schools WHERE staff_id = #{@current_admin.id}) IS NOT TRUE").distinct.pluck :school_id
86
+
87
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id) - other_staff_school_id
88
+ if can?(:special, EducodeSales::Business)
89
+ # 专项商机
90
+ school_tag_ids = @current_admin.staff_school_tags.pluck(:school_tag_id)
91
+ tag_school_ids = SchoolTagMiddle.where(school_tag_id: school_tag_ids).pluck(:school_id)
92
+ school_ids += tag_school_ids
93
+ end
94
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
95
+ @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)
96
+ else
97
+ @businesses = Business
98
+ end
99
+ end
100
+ @businesses =
101
+ if params[:is_deleted].to_s.present?
102
+ @businesses.where.not(p_deleted_at: nil)
103
+ else
104
+ @businesses.where(p_deleted_at: nil)
105
+ end
106
+
107
+ @is_deleted = params[:is_deleted].to_s.present?
108
+ gon.is_deleted = @is_deleted ? 1 : 0
109
+ if params[:q].present? && params[:q][:name].present?
110
+ @year = params[:q][:name].split("-")[1].present? ? params[:q][:name].split("-")[1] : ''
111
+ end
112
+ # @budget_stage_ids = Common.where(clazz: '商机阶段', name: ['初步接洽', '准备方案','已交方案', '已立项']).pluck(:id)
113
+ if params[:q] && params[:q][:signed_date].present?
114
+ date = params[:q][:signed_date].split(" - ")
115
+ @businesses = @businesses.joins("
116
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
117
+ ").where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ?", date[0], date[1])
118
+ end
119
+
120
+ if params[:q] && params[:q][:date_at].present?
121
+ date = params[:q][:date_at].split(" - ")
122
+ x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
123
+ @businesses = @businesses.joins(follow_ups: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x_id).where.not("educode_sales_money_plans.clazz!= 1").where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", date[0] + " 00:00:00", date[1] + " 23:59:59").distinct
124
+ end
125
+
126
+ if params[:q] && params[:q][:bidded_date].present?
127
+ date = params[:q][:bidded_date].split(" - ")
128
+ @businesses = @businesses.joins("
129
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
130
+ ").where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ?", date[0], date[1])
131
+ end
132
+
133
+ if params[:q].present? && params[:q][:all].present?
134
+ @businesses = @businesses
135
+ end
136
+
137
+ if params[:q].present? && params[:q][:name].present?
138
+ @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
139
+ end
140
+ if params[:q].present? && params[:q][:p_stage].present?
141
+ @businesses = @businesses.where(p_stage: "#{params[:q][:p_stage].to_s.strip}")
142
+ end
143
+ if params[:q].present? && params[:q][:p_staff_id].present?
144
+ @businesses = @businesses.where(p_staff_id: params[:q][:p_staff_id])
145
+ end
146
+ if params[:q].present? && params[:q][:p_sale_staff_id].present?
147
+ @businesses = @businesses.where(p_sale_staff_id: params[:q][:p_sale_staff_id])
148
+ end
149
+ if params[:q].present? && params[:q][:p_special].present?
150
+ @businesses = @businesses.where(p_special: "#{params[:q][:p_special]}")
151
+ end
152
+ if params[:q].present? && params[:q][:p_difficulty].present?
153
+ @businesses = @businesses.where(p_difficulty: "#{params[:q][:p_difficulty]}")
154
+ end
155
+
156
+ # bidded_date = d.last_follow_up&.bidded_date
157
+ # stage = d.last_follow_up&.stage&.name
158
+ # (d.p_pre_money_time.present? && Time.now > d.p_pre_money_time && d.p_actual_money_time.blank?) ||
159
+ # (d.p_pre_accept_time.present? && Time.now > d.p_pre_accept_time && d.p_accept_time.blank?) ? "逾期" : "正常"
160
+ # SELECT * FROM users WHERE NOW() > DATE_ADD(bidded_date, INTERVAL 1 MONTH)
161
+
162
+ if params[:q].present? && params[:q][:p_state].present?
163
+ p_state = params[:q][:p_state].to_i
164
+ # 逾期id
165
+ late_ids = Business.joins("JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id JOIN educode_sales_commons on educode_sales_commons.id = educode_sales_follow_ups.stage_id")
166
+ .where("educode_sales_follow_ups.bidded_date is not null")
167
+ .where("NOW() > DATE_ADD(educode_sales_follow_ups.bidded_date, INTERVAL 1 MONTH)")
168
+ .where("educode_sales_businesses.p_stage is null")
169
+ .where("educode_sales_commons.name = '已中标'")
170
+ .or(Business.joins("JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id JOIN educode_sales_commons on educode_sales_commons.id = educode_sales_follow_ups.stage_id")
171
+ .where("NOW() > educode_sales_businesses.p_pre_money_time")
172
+ .where("educode_sales_businesses.p_pre_money_time is not null")
173
+ .where("educode_sales_businesses.p_actual_money_time is null")
174
+ ).or(Business.joins("JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id JOIN educode_sales_commons on educode_sales_commons.id = educode_sales_follow_ups.stage_id")
175
+ .where("NOW() > educode_sales_businesses.p_pre_accept_time")
176
+ .where("educode_sales_businesses.p_pre_accept_time is not null")
177
+ .where("educode_sales_businesses.p_accept_time is null")).ids
178
+ if p_state == 0 # 正常
179
+ @businesses = @businesses.where.not(id: late_ids)
180
+ else
181
+ # 逾期
182
+ @businesses = @businesses.where(id: late_ids)
183
+ end
184
+ end
185
+ if params[:q].present? && params[:q][:department].present?
186
+ departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:department]}%").pluck(:id)
187
+ @businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
188
+ end
189
+ if params[:q].present? && params[:q][:staff_id].present?
190
+ 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
191
+ part_b_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is not null").joins("
192
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
193
+ ").where("educode_sales_follow_ups.staff_id = ?", params[:q][:staff_id]).ids
194
+ business_ids = part_a_ids + part_b_ids
195
+ if params[:q][:clazz] == 'delete_list'
196
+ @businesses = EducodeSales::Business.unscoped.where(id: business_ids)
197
+ else
198
+ @businesses = EducodeSales::Business.where(id: business_ids)
199
+ end
200
+ end
201
+ if params[:q].present? && params[:q][:business_type].present?
202
+ @businesses = @businesses.where("educode_sales_businesses.clazz_id in (?)", params[:q][:business_type].split(",").map(&:to_i))
203
+ end
204
+ contract_ids = Common.where(clazz: '商机阶段', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).pluck(:id)
205
+ @businesses = @businesses.joins("
206
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
207
+ ").where("educode_sales_follow_ups.stage_id in (?)", contract_ids)
208
+ if params[:q].present? && params[:q][:business_step].present?
209
+ @businesses = @businesses.joins("
210
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
211
+ ").where("educode_sales_follow_ups.stage_id in (?)", params[:q][:business_step].split(",").map(&:to_i))
212
+ end
213
+ if params[:q].present? && params[:q][:place_id].present?
214
+ @businesses = @businesses.joins("
215
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
216
+ ").where("educode_sales_follow_ups.place_id = ?", params[:q][:place_id])
217
+ end
218
+ if params[:q].present? && params[:q][:business_year].present?
219
+ @businesses = @businesses.joins("
220
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
221
+ ").where("educode_sales_follow_ups.year = ?", params[:q][:business_year])
222
+ end
223
+
224
+ if params[:q].present? && params[:q][:year].present?
225
+ @businesses = @businesses.joins("
226
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
227
+ ").where("educode_sales_follow_ups.year <= ?", params[:q][:year])
228
+ end
229
+
230
+ if params[:q].present? && params[:q][:o_business_deployment].present?
231
+ @businesses = @businesses.joins("
232
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
233
+ ").where("educode_sales_follow_ups.o_business_deployment = ?", params[:q][:o_business_deployment])
234
+ end
235
+
236
+ if params[:q].present? && params[:q][:area].present?
237
+ p = EducodeSales::Common.find(params[:q][:area]).name
238
+ if @current_admin.is_admin?
239
+ @businesses = @businesses.joins("
240
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
241
+ JOIN schools ON departments.school_id = schools.id
242
+ ").where("province = ?", p)
243
+ else
244
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
245
+ if level == "区域"
246
+ @businesses = @businesses.joins("
247
+ JOIN schools ON departments.school_id = schools.id
248
+ ").where("province = ?", p)
249
+ else
250
+ @businesses = @businesses.joins("
251
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
252
+ JOIN schools ON departments.school_id = schools.id
253
+ ").where("province = ?", p)
254
+ end
255
+ end
256
+ end
257
+
258
+ if params[:q].present? && params[:q][:date].present?
259
+ date = params[:q][:date].split(" - ")
260
+ @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
261
+ end
262
+ if params[:q].present? && params[:q][:search_p_actual_money_time].present?
263
+ date = params[:q][:search_p_actual_money_time].split(" - ")
264
+ @businesses = @businesses.where("educode_sales_businesses.p_actual_money_time > ? AND educode_sales_businesses.p_actual_money_time < ?", date[0], date[1] + '23:59:59')
265
+ end
266
+
267
+ if params[:q].present? && params[:q][:invitation_at].present?
268
+ date = params[:q][:invitation_at].split(" - ")
269
+ @businesses = @businesses.joins("
270
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
271
+ ").where("educode_sales_follow_ups.invitation_at > ? AND educode_sales_follow_ups.invitation_at < ?", date[0] + '00:00:00', date[1] + '23:59:59')
272
+ end
273
+
274
+ # 根据编号获取商机
275
+ if params[:q].present? && params[:q][:number].present?
276
+ @businesses = @businesses.where("number like :data", data: "%#{params[:q][:number].strip}%")
277
+ end
278
+
279
+ if params[:q].present? && params[:q][:clazz].present?
280
+ # 我的关注
281
+ if params[:q][:clazz] == 'followes'
282
+ my_ids = BusinessRelationShip.where(user_id: @current_admin.user_id).pluck(:business_id)
283
+ @businesses = @businesses.where(id: my_ids)
284
+ elsif params[:q][:clazz] == 'me'
285
+ ids = AssignFollowUp.joins("JOIN educode_sales_follow_ups ON educode_sales_follow_ups.id = educode_sales_assign_follow_ups.follow_up_id").where(staff_id: @current_admin.id).pluck(:business_id)
286
+ @businesses = @businesses.where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", ids, @current_admin.id)
287
+ end
288
+ end
289
+
290
+ # 商机变化
291
+ if params[:q][:clazz_changes].present?
292
+ clazz_changes = EducodeSales::BusinessClazzChange.clazz_changes_value[params[:q][:clazz_changes].to_s]
293
+ @businesses = @businesses.joins("JOIN educode_sales_business_clazz_changes ON educode_sales_business_clazz_changes.business_id = educode_sales_businesses.id").where("educode_sales_business_clazz_changes.clazz_changed in (?)", clazz_changes)
294
+ end
295
+
296
+ if params[:sort].present? && params[:sort][:field]
297
+ if params[:sort][:field] == "service_end_time"
298
+ @businesses = @businesses.order("service_time_long #{params[:sort][:order]}")
299
+ else
300
+ @businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
301
+ end
302
+ else
303
+ @businesses = @businesses.order("educode_sales_businesses.created_at desc")
304
+ end
305
+
306
+ @business_count = @businesses.distinct.count
307
+ # mysql -select
308
+ @businesses = @businesses.select("
309
+ distinct
310
+ educode_sales_businesses.*,
311
+ last_follow.invitation_at,
312
+ last_follow.budget_amount,
313
+ last_follow.o_business_deployment,
314
+ last_follow.service_time_long,
315
+ last_follow.service_end_time,
316
+ last_follow.service_start_time,
317
+ last_follow.reception_at,
318
+ last_follow.bidded_date,
319
+ last_follow.signed_date,
320
+ last_follow.year,
321
+ last_follow.created_at as latest_time,
322
+ last_follow.actual_amount,
323
+ last_follow.divide_rate,
324
+ last_follow.divide_amount,
325
+ (last_follow.total_amount - last_follow.actual_amount) as divide_money,
326
+ (last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
327
+ last_follow.total_amount,
328
+ total_follow_ups.follow_ups_counts
329
+ ").joins("
330
+ 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
331
+ LEFT JOIN (
332
+ SELECT COUNT(*) AS follow_ups_counts, educode_sales_follow_ups.business_id
333
+ FROM educode_sales_follow_ups
334
+ WHERE educode_sales_follow_ups.deleted_at IS NULL
335
+ GROUP BY educode_sales_follow_ups.business_id
336
+ ) AS total_follow_ups ON educode_sales_businesses.id = total_follow_ups.business_id
337
+ ").includes(:users, last_follow_up: [:clazz, :assign_follow_ups]).page(params[:page]).per(params[:limit])
338
+
339
+ end
340
+
341
+ end
342
+ end
343
+
344
+ def detail
345
+ staffs = Staff.where.not(role_id: 11).includes(:user)
346
+ gon.staffs = staffs.map { |d| { name: d.user.real_name, value: d.id } }
347
+ gon.staff_value = @project.p_staff_id ? [{ name: @project.p_staff&.user&.real_name, value: @project.p_staff_id }] : []
348
+ gon.sale_staff_value = @project.p_sale_staff_id ? [{ name: @project.p_sale_staff&.user&.real_name, value: @project.p_sale_staff_id }] : []
349
+ render layout: false
350
+ end
351
+
352
+ def history
353
+ render layout: false
354
+ end
355
+
356
+ def update
357
+ @project.assign_attributes(project_params)
358
+ check_changes
359
+ @project.save
360
+ render_success
361
+ end
362
+
363
+ def destroy
364
+ @project.p_soft_destroy(current_user.id)
365
+ render_success
366
+ end
367
+
368
+ def edit
369
+ staffs = Staff.where.not(role_id: 11).includes(:user)
370
+ gon.staffs = staffs.map { |d| { name: d.user.real_name, value: d.id } }
371
+ gon.staff_value = @project.p_staff_id ? [{ name: @project.p_staff&.user&.real_name, value: @project.p_staff_id }] : []
372
+ gon.sale_staff_value = @project.p_sale_staff_id ? [{ name: @project.p_sale_staff&.user&.real_name, value: @project.p_sale_staff_id }] : []
373
+ render layout: false
374
+ end
375
+
376
+ def recycle
377
+ @project.p_recycle
378
+ render_success
379
+ end
380
+
381
+ private
382
+
383
+ def project_params
384
+ permit =
385
+ %i[p_stage p_difficulty p_special
386
+ p_status p_staff_id p_sale_staff_id
387
+ p_course_time p_platform_time p_deploy_time
388
+ p_accept_time p_pre_money_time p_actual_money_time
389
+ p_money p_content p_pre_accept_time]
390
+
391
+ params.permit(permit)
392
+
393
+ end
394
+
395
+ def find_project
396
+ @project = Business.find(params[:id])
397
+ end
398
+
399
+ def check_changes
400
+ unless @project.new_record?
401
+ history = []
402
+ except_attr = %i[id staff_id department_id name created_at updated_at follow_ups_count last_follow_up_id return_money source deleted_at school_id number clazz_id delete_reason auth_desc state_id p_deleted_at p_deleter_id]
403
+ arr = @project.attributes.except(except_attr).keys
404
+ arr.each do |attr|
405
+ if @project.send("#{attr}_changed?")
406
+ old_value, new_value = @project.send("#{attr}_was"), @project.send(attr)
407
+ res = Project.save_history(attr, old_value, new_value)
408
+ history << res if res
409
+ end
410
+ end
411
+ @project.business_histories.create(content: history, staff: current_user) if history.present?
412
+ end
413
+ end
414
+
415
+ def edu_setting name
416
+ EduSetting.get(name)
417
+ end
418
+
419
+ def follow_business(user_id, business_id)
420
+ BusinessRelationShip.where(user_id: user_id, business_id: business_id).first
421
+ end
422
+ end
423
+ end
@@ -16,7 +16,7 @@ module EducodeSales
16
16
 
17
17
  def create
18
18
  role = Role.new(name: params[:name])
19
- role.role_areas.build([{ clazz: 'Business' }, { clazz: 'SalePlan' }, { clazz: 'Teacher' }, { clazz: 'Operation' }, { clazz: 'Customer' }, { clazz: 'MoneyPlan' }, { clazz: 'AssessmentsSetting' }, { clazz: 'Idea' }])
19
+ role.role_areas.build([{ clazz: 'Business' }, { clazz: 'SalePlan' }, { clazz: 'Teacher' }, { clazz: 'Operation' }, { clazz: 'Customer' }, { clazz: 'MoneyPlan' }, { clazz: 'AssessmentsSetting' }, { clazz: 'Idea' }, { clazz: 'Project' }])
20
20
  if role.save
21
21
  render_success
22
22
  else
@@ -90,6 +90,9 @@ module EducodeSales
90
90
  r = role.role_areas.find_or_initialize_by(clazz: 'Idea')
91
91
  r.level = params[:idea]
92
92
  r.save
93
+ r = role.role_areas.find_or_initialize_by(clazz: 'Project')
94
+ r.level = params[:project]
95
+ r.save
93
96
  render_success
94
97
  end
95
98
 
@@ -24,12 +24,12 @@ module EducodeSales
24
24
  common = Common.find_by(clazz: 'staff_type', name: '运营')
25
25
  role = EducodeSales::Role.find_by(name: '生态经理')
26
26
  if role
27
- @staff_manage = Staff.joins(:user).where(role_id: role.id).map { |d| [d.user.real_name, d.id]}
27
+ @staff_manage = Staff.includes(:user).where(role_id: role.id).map { |d| [d.user.real_name, d.id]}
28
28
  else
29
29
  @staff_manage = Staff.none
30
30
  end
31
-
32
- @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
31
+ @follow_upers = Staff.includes(:user).map { |d| [d.user.real_name, d.id]}
32
+ @staffs = Staff.includes(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
33
33
  @more = can?(:create, EducodeSales::OperationPlan) || can?(:update, EducodeSales::Teacher) || can?(:destroy, EducodeSales::Teacher)
34
34
  gon.menus = []
35
35
  if can?(:create, EducodeSales::OperationPlan)
@@ -70,6 +70,8 @@ module EducodeSales
70
70
  end
71
71
  end
72
72
 
73
+ @teachers = @teachers.includes(department: [:department_majors, :school])
74
+
73
75
  if @current_admin.job_type == Common.find_by(clazz: 'staff_type', name: '销售').id
74
76
  public_teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id)
75
77
  @teachers = @teachers.where.not(id: public_teacher_ids)
@@ -83,6 +85,9 @@ module EducodeSales
83
85
  if params[:q].present? && params[:q][:name].present?
84
86
  @teachers = @teachers.where("educode_sales_teachers.name like ?", "%#{params[:q][:name]}%")
85
87
  end
88
+ if params[:q].present? && params[:q][:realname].present?
89
+ @teachers = @teachers.where("educode_sales_teachers.realname like ?", "%#{params[:q][:realname]}%")
90
+ end
86
91
  if params[:q].present? && params[:q][:professional_title].present?
87
92
  @teachers = @teachers.where("educode_sales_teachers.professional_title = ?", "#{params[:q][:professional_title]}")
88
93
  end
@@ -131,16 +136,39 @@ module EducodeSales
131
136
  @teachers = @teachers.where("educode_sales_teachers.created_at > ? AND educode_sales_teachers.created_at < ?", date[0], date[1])
132
137
  end
133
138
 
134
- @teachers = @teachers.select("
135
- educode_sales_teachers.*,
136
- users.created_on,
137
- last_follow.created_at as latest_time,
138
- users.grade,
139
- users.experience,
140
- users.last_login_on").joins("
141
- LEFT JOIN users ON educode_sales_teachers.user_id = users.id
142
- LEFT JOIN educode_sales_teacher_follows AS last_follow ON last_follow.teacher_id = educode_sales_teachers.id AND last_follow.deleted_at IS NULL
143
- ")
139
+ if params[:q].present? && params[:q][:staff_manage].present?
140
+ staff = Staff.find(params[:q][:staff_manage])
141
+ school_ids = School.where(province: staff.areas.pluck(:name)).pluck(:id)
142
+ teacher_ids = EducodeSales::Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where("departments.school_id in (?)", school_ids).pluck(:id)
143
+ @teachers = @teachers.where(id: teacher_ids)
144
+ end
145
+
146
+
147
+
148
+ if params[:q].present? && params[:q][:staff_id].present?
149
+ @teachers = @teachers.select("
150
+ educode_sales_teachers.*,
151
+ users.created_on,
152
+ last_follow.created_at as latest_time,
153
+ users.grade,
154
+ users.experience,
155
+ users.last_login_on").joins("
156
+ JOIN educode_sales_teacher_follows AS last_follow ON last_follow.id = educode_sales_teachers.follow_up_id AND last_follow.deleted_at IS NULL
157
+ LEFT JOIN users ON educode_sales_teachers.user_id = users.id
158
+ ")
159
+ @teachers = @teachers.where("last_follow.staff_id = ?", params[:q][:staff_id].to_i)
160
+ else
161
+ @teachers = @teachers.select("
162
+ educode_sales_teachers.*,
163
+ users.created_on,
164
+ last_follow.created_at as latest_time,
165
+ users.grade,
166
+ users.experience,
167
+ users.last_login_on").joins("
168
+ LEFT JOIN users ON educode_sales_teachers.user_id = users.id
169
+ LEFT JOIN educode_sales_teacher_follows AS last_follow ON last_follow.id = educode_sales_teachers.follow_up_id AND last_follow.deleted_at IS NULL
170
+ ")
171
+ end
144
172
  if params[:sort].present? && params[:sort][:field]
145
173
  @teachers = @teachers.order("#{params[:sort][:field]} #{params[:sort][:order]}")
146
174
  else
@@ -368,7 +396,7 @@ module EducodeSales
368
396
 
369
397
  private
370
398
  def teacher_params
371
- params.permit(:name, :professional_title, :job, :source_id, :wechat, :mobile)
399
+ params.permit(:name, :professional_title, :job, :source_id, :wechat, :mobile, :realname)
372
400
  end
373
401
 
374
402
  def load_teacher
@@ -19,6 +19,7 @@ module EducodeSales
19
19
  File.join("images/avatars", ["#{source&.class}", "#{source&.id}"]) + "?t=#{ctime}"
20
20
  end
21
21
  elsif source.class.to_s == 'User'
22
+
22
23
  str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g"
23
24
  File.join(relative_path, "#{source.class}", str)
24
25
  elsif source.class.to_s == 'Subject'
@@ -1,25 +1,34 @@
1
1
  module EducodeSales
2
2
  class Business < ApplicationRecord
3
3
 
4
- validates_uniqueness_of :number ,allow_nil: true
4
+ validates_uniqueness_of :number, allow_nil: true
5
5
 
6
6
  belongs_to :clazz, class_name: 'Common'
7
7
  belongs_to :staff
8
8
  belongs_to :department
9
9
  belongs_to :last_follow_up, class_name: 'FollowUp', optional: true # 允许last_follow_up_id字段中的数为nil
10
10
 
11
+ belongs_to :p_staff, class_name: 'Staff', optional: true
12
+ belongs_to :p_sale_staff, class_name: 'Staff', optional: true
13
+ belongs_to :p_deleter, class_name: 'Staff', optional: true
14
+
11
15
  has_many :sale_plans
12
16
  has_many :follow_ups
13
17
  has_many :business_clazz_changes
14
18
  has_many :business_levels, dependent: :destroy
15
19
  has_many :business_watches, dependent: :destroy
20
+ has_many :business_histories, dependent: :destroy
16
21
 
17
- #关联关注
18
- has_many :users,:class_name => 'EducodeSales::BusinessRelationShip',foreign_key: 'business_id',:dependent => :destroy
22
+ # 关联关注
23
+ has_many :users, :class_name => 'EducodeSales::BusinessRelationShip', foreign_key: 'business_id', :dependent => :destroy
19
24
 
20
- #每次查询时 默认的查询条件
21
- default_scope -> {where(deleted_at: nil)}
25
+ # 每次查询时 默认的查询条件
26
+ default_scope -> { where(deleted_at: nil) }
22
27
 
28
+ enum p_stage: %w[合同阶段 验收阶段 回款阶段]
29
+ enum p_difficulty: %w[困难 适中 容易]
30
+ enum p_special: %w[是 否]
31
+ enum p_status: %w[未完成 已完成]
23
32
 
24
33
  def soft_destroy(user_id)
25
34
  self.update(deleted_at: Time.now, state_id: 2)
@@ -30,6 +39,13 @@ module EducodeSales
30
39
  EducodeSales::Recycle.create(source: self, deleter_id: user_id)
31
40
  end
32
41
 
42
+ def p_soft_destroy(staff_id)
43
+ self.update(p_deleted_at: Time.now, p_deleter_id: staff_id)
44
+ end
45
+
46
+ def p_recycle
47
+ self.update(p_deleted_at: nil, p_deleter_id: nil)
48
+ end
33
49
 
34
50
  def self.include_types(type)
35
51
  {
@@ -0,0 +1,8 @@
1
+ module EducodeSales
2
+ class BusinessHistory < ApplicationRecord
3
+ belongs_to :business
4
+ belongs_to :staff
5
+
6
+ serialize :content, Array
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module EducodeSales
2
+ class EcoStaff < ApplicationRecord
3
+ belongs_to :staff
4
+ belongs_to :sourcable, :polymorphic => true
5
+ end
6
+ end
@@ -14,7 +14,8 @@ module EducodeSales
14
14
  '客户管理': 'customer',
15
15
  '回款管理': 'money_plan',
16
16
  '绩效考核': 'assessments_setting',
17
- '方案管理': 'idea'
17
+ '方案管理': 'idea',
18
+ '项目管理': 'project'
18
19
  }
19
20
  end
20
21
  end