educode_sales 0.9.40 → 0.9.42

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: 41be1a85301a5d440bb31501f01a0ff9db5158f0890c5096916ff238ffc34e38
4
- data.tar.gz: 81a70162b88c7d09eaf90b4181177f757d993264761d65ec376e7719307da53e
3
+ metadata.gz: d635995859ce768ee96b28509c5094efbc03e8d98ca1b6fe59e52bc4696ef41e
4
+ data.tar.gz: 8010219ab35845df3329179cf6e8f2e56e224b5d60781a2ff4b80999efcc0c1c
5
5
  SHA512:
6
- metadata.gz: 99f2999ebcb569c813f3251d060e0347a5a2e488ae1f778d4a51b594ff03416854f7ef9ae8cc0fe5a433f95417801a7549c16e56f1c8a96d0e031a6ec2b9539b
7
- data.tar.gz: 62a7671b59dbb8ffb5ad827d310ead46aecf6c5de76b6151d4d6c0c56a81c6835a490c4171d4ee55e40317af0098e30ad87ebab6e9be0be112442a0c15747ddc
6
+ metadata.gz: 3939a32d342b6ce49488569f52a67902fad404502dfae2262a1f4b37a3275ec63728e36a1d03feebba2cbf20590de4ceac237a09d5b053dc10510e5506eb20f5
7
+ data.tar.gz: 37ba20f22853d9cd00c82c5a1f472157fa37fbfe8cfac77cb868b707142ab6d36b8e93f1ecb4f9cd6dec9f478ed9b406cfb06a68115812b6e7dd0a3e67d40391
@@ -95,20 +95,42 @@ module EducodeSales
95
95
  end
96
96
  end
97
97
  format.json do
98
- if @current_admin.is_admin?
99
- @businesses = Business
98
+ if params[:q] && (params[:q][:clazz] == 'area' || params[:q][:clazz] == 'special')
99
+ if params[:q][:clazz] == 'special'
100
+ school_ids = []
101
+ # 专项商机
102
+ school_tag_ids = @current_admin.staff_school_tags.pluck(:school_tag_id)
103
+ school_ids = SchoolTagMiddle.where(school_tag_id: school_tag_ids).pluck(:school_id)
104
+ @businesses = Business.joins("JOIN departments AS dp ON educode_sales_businesses.department_id = dp.id").where("dp.school_id in (?)", school_ids)
105
+ elsif params[:q][:clazz] == 'area'
106
+ school_ids = []
107
+ # 区域管理商机
108
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
109
+ @businesses = Business.joins("JOIN departments AS dp ON educode_sales_businesses.department_id = dp.id").where("dp.school_id in (?)", school_ids)
110
+ end
100
111
  else
101
- level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
102
- case level
103
- when '自己'
104
- business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
105
- @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
106
- when '区域'
107
- school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
108
- business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
109
- @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)
110
- else
112
+ if @current_admin.is_admin?
111
113
  @businesses = Business
114
+ else
115
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
116
+ case level
117
+ when '自己'
118
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
119
+ @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
120
+ when '区域'
121
+
122
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
123
+ if can?(:special, EducodeSales::Business)
124
+ # 专项商机
125
+ school_tag_ids = @current_admin.staff_school_tags.pluck(:school_tag_id)
126
+ tag_school_ids = SchoolTagMiddle.where(school_tag_id: school_tag_ids).pluck(:school_id)
127
+ school_ids += tag_school_ids
128
+ end
129
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
130
+ @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)
131
+ else
132
+ @businesses = Business
133
+ end
112
134
  end
113
135
  end
114
136
  if params[:q].present? && params[:q][:name].present?
@@ -116,8 +138,6 @@ module EducodeSales
116
138
  end
117
139
 
118
140
  # @budget_stage_ids = Common.where(clazz: '商机阶段', name: ['初步接洽', '准备方案','已交方案', '已立项']).pluck(:id)
119
-
120
-
121
141
  if params[:q] && params[:q][:signed_date].present?
122
142
  date = params[:q][:signed_date].split(" - ")
123
143
  @businesses = @businesses.joins("
@@ -178,6 +198,12 @@ module EducodeSales
178
198
  ").where("educode_sales_follow_ups.year = ?", params[:q][:business_year])
179
199
  end
180
200
 
201
+ if params[:q].present? && params[:q][:year].present?
202
+ @businesses = @businesses.joins("
203
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
204
+ ").where("educode_sales_follow_ups.year <= ?", params[:q][:year])
205
+ end
206
+
181
207
  if params[:q].present? && params[:q][:o_business_deployment].present?
182
208
  @businesses = @businesses.joins("
183
209
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
@@ -538,6 +564,12 @@ module EducodeSales
538
564
  ").where("educode_sales_follow_ups.year = ?", params[:business_year])
539
565
  end
540
566
 
567
+ if params[:year].present?
568
+ @businesses = @businesses.joins("
569
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
570
+ ").where("educode_sales_follow_ups.year <= ?", params[:year])
571
+ end
572
+
541
573
  if params[:all].present?
542
574
  @businesses = @businesses
543
575
  end
@@ -6,38 +6,39 @@ module EducodeSales
6
6
  def new_department
7
7
  render layout: false
8
8
  end
9
+
9
10
  def create_department
10
- department_name = params[:department_name].to_s.strip
11
- school = School.find(params[:school_id])
11
+ department_name = params[:department_name].to_s.strip
12
+ school = School.find(params[:school_id])
12
13
 
13
- return render_failure('部门名称重复') if school.departments.exists?(name: department_name)
14
+ return render_failure('部门名称重复') if school.departments.exists?(name: department_name)
14
15
 
15
- ActiveRecord::Base.transaction do
16
- department = school.departments.create!(name: department_name, is_auth: 1)
17
- ApplyAddDepartment.create!(school_id: school.id, status: 1, name: department.name,
18
- department_id: department.id, user_id: current_user.id)
19
- end
16
+ ActiveRecord::Base.transaction do
17
+ department = school.departments.create!(name: department_name, is_auth: 1)
18
+ ApplyAddDepartment.create!(school_id: school.id, status: 1, name: department.name,
19
+ department_id: department.id, user_id: current_user.id)
20
+ end
20
21
 
21
- render_success
22
+ render_success
22
23
  end
23
24
 
24
25
  def edit_department
25
26
  @department = Department.find(params[:id])
26
27
  render layout: false
27
28
  end
29
+
28
30
  def update_department
29
31
  department = Department.find(params[:id])
30
32
  department.update(name: params[:department_name])
31
33
  render_success
32
34
  end
33
35
 
34
-
35
36
  def index
36
37
  authorize! :read, Customer
37
38
  respond_to do |format|
38
39
  format.html do
39
40
  common = Common.find_by(clazz: 'staff_type', name: '销售')
40
- @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
41
+ @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id] }
41
42
  end
42
43
  format.json do
43
44
  if @current_admin.is_admin?
@@ -46,11 +47,11 @@ module EducodeSales
46
47
  level = @current_admin.role.role_areas.find_by(clazz: '客户管理').level
47
48
  case level
48
49
  when '自己'
49
- school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
50
+ school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
50
51
  @customers = School.where(id: school_ids)
51
52
  when '区域'
52
53
  a_school_ids = School.where(province: @current_admin.areas.pluck(:name)).ids
53
- b_school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
54
+ b_school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
54
55
  school_ids = a_school_ids + b_school_ids + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
55
56
  @customers = School.where(id: school_ids)
56
57
  else
@@ -59,7 +60,7 @@ module EducodeSales
59
60
  end
60
61
  part_a_ids = CustomerFollow.all.pluck(:school_id)
61
62
  part_b_ids = Business.where(id: EducodeSales::FollowUp.pluck(:business_id)).pluck(:school_id)
62
- ids = part_a_ids + part_b_ids + CustomerAdd.all.pluck(:school_id)
63
+ ids = part_a_ids + part_b_ids + CustomerAdd.all.pluck(:school_id)
63
64
  @customers = @customers.where(id: ids)
64
65
  if params[:q].present? && params[:q][:name].present?
65
66
  @customers = @customers.where("schools.name like ?", "%#{params[:q][:name]}%")
@@ -77,19 +78,19 @@ module EducodeSales
77
78
  property.each do |p|
78
79
  case p
79
80
  when 0
80
- school_property_ids += SchoolProperty.where( project_985: true ).ids
81
+ school_property_ids += SchoolProperty.where(project_985: true).ids
81
82
  when 1
82
- school_property_ids += SchoolProperty.where( project_211: true ).ids
83
+ school_property_ids += SchoolProperty.where(project_211: true).ids
83
84
  when 2
84
- school_property_ids += SchoolProperty.where( regular_college: true ).ids
85
+ school_property_ids += SchoolProperty.where(regular_college: true).ids
85
86
  when 3
86
- school_property_ids += SchoolProperty.where( junior_college: true ).ids
87
+ school_property_ids += SchoolProperty.where(junior_college: true).ids
87
88
  when 4
88
- school_property_ids += SchoolProperty.where( secondary_school: true ).ids
89
+ school_property_ids += SchoolProperty.where(secondary_school: true).ids
89
90
  when 5
90
- school_property_ids += SchoolProperty.where( military_school: true ).ids
91
+ school_property_ids += SchoolProperty.where(military_school: true).ids
91
92
  when 6
92
- school_property_ids += SchoolProperty.where( enterprise: true ).ids
93
+ school_property_ids += SchoolProperty.where(enterprise: true).ids
93
94
  else
94
95
  end
95
96
  end
@@ -99,7 +100,7 @@ module EducodeSales
99
100
  if params[:q].present? && params[:q][:date].present?
100
101
  ids = EducodeSales::CustomerFollow.all.pluck(:school_id)
101
102
  @customers = @customers.where(id: ids)
102
- school_ids =[]
103
+ school_ids = []
103
104
  date = params[:q][:date].split(" - ")
104
105
  @customers.each do |d|
105
106
  business_ids = EducodeSales::Business.where(school_id: d.id).ids
@@ -127,7 +128,7 @@ module EducodeSales
127
128
 
128
129
  def give
129
130
  common = Common.find_by(clazz: 'staff_type', name: '销售')
130
- @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
131
+ @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id] }
131
132
  render layout: false
132
133
  end
133
134
 
@@ -154,7 +155,6 @@ module EducodeSales
154
155
  @departments = @departments.page(params[:page]).per(params[:limit])
155
156
  end
156
157
 
157
-
158
158
  def new_follow_record
159
159
  @school = School.find(params[:id])
160
160
  render layout: false
@@ -215,17 +215,45 @@ module EducodeSales
215
215
  junior_college: params[:junior_college].present? ? 1 : 0,
216
216
  secondary_school: params[:secondary_school].present? ? 1 : 0,
217
217
  military_school: params[:military_school].present? ? 1 : 0,
218
+ other: params[:other].present? ? 1 : 0,
219
+ mid_school: params[:mid_school].present? ? 1 : 0,
220
+ ele_school: params[:ele_school].present? ? 1 : 0,
218
221
  enterprise: params[:enterprise].present? ? 1 : 0)
219
222
  @school.attributes = school_params
220
223
  @school.school_property = property
221
224
  @school.save!
225
+
226
+ #先删除全部的标签,再添加标签
227
+ missions_school_tags = SchoolTag.where(for_missions: true)
228
+ SchoolTagMiddle.where(school_id: @school.id, school_tag_id: missions_school_tags.ids).destroy_all
229
+ #保存学校标签
230
+
231
+ keys = %w[regular_college junior_college secondary_school military_school other mid_school ele_school enterprise]
232
+ names = {
233
+ "regular_college" => "本科院校",
234
+ "junior_college" => "高职院校",
235
+ "secondary_school" => "中职院校",
236
+ "military_school" => "军事院校",
237
+ "other" => "其他",
238
+ "mid_school" => "中学",
239
+ "ele_school" => "小学",
240
+ "enterprise" => "企业"
241
+ }
242
+ property.attributes.each do |key, value|
243
+ next unless key.in?(keys)
244
+ next unless value.to_s == "true"
245
+ school_tag = SchoolTag.find_by_name(names[key])
246
+ if school_tag.present?
247
+ SchoolTagMiddle.create(school_id: @school.id, school_tag_id: school_tag.id)
248
+ end
249
+ end
250
+
222
251
  end
223
252
  render_success
224
253
  end
225
254
 
226
255
  private
227
256
 
228
-
229
257
  def school_property_params
230
258
  params.permit(:project_985, :project_211, :regular_college, :junior_college, :secondary_school, :military_school, :enterprise)
231
259
  end
@@ -88,7 +88,7 @@ module EducodeSales
88
88
  follow_up.clazz_changed = last_follow_up.clazz_id != follow_up.clazz_id
89
89
  if follow_up.clazz_changed
90
90
  clazz_changes = "#{last_follow_up.clazz.extras.split('_')[0]}-#{follow_up.clazz.extras.split('_')[0]}"
91
- business_clazz_change = @business.business_clazz_changes.find_or_initialize_by clazz_changed: clazz_changes
91
+ business_clazz_change = EducodeSales::BusinessClazzChange.find_or_initialize_by(business_id: @business.id, clazz_changed: clazz_changes)
92
92
  business_clazz_change.save unless business_clazz_change.persisted?
93
93
  end
94
94
  end
@@ -38,7 +38,7 @@ module EducodeSales
38
38
  year_over_time = "#{@year}-12-31 23:59:59"
39
39
 
40
40
  @sale_trend = SaleTrend.find_or_create_by(year: @year)
41
- @business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ? AND educode_sales_follow_ups.clazz_id != ?", x, o).where("educode_sales_follow_ups.year = ?", @year).sum(:total_amount).round(2)
41
+ @business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ? AND educode_sales_follow_ups.clazz_id != ?", x, o).where("educode_sales_follow_ups.year <= ?", @year).sum(:total_amount).round(2)
42
42
  stage_ids = Common.where(clazz: '商机阶段', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).pluck(:id)
43
43
 
44
44
  # 中标总金额, 已回款总金额
@@ -61,9 +61,9 @@ module EducodeSales
61
61
  @receivable_amount = @receivable_amount.present? && @receivable_amount[0]['num'] ? @receivable_amount[0]['num'].round(2) : 0
62
62
 
63
63
  a = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name).pluck(:id)
64
- @a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).where("educode_sales_follow_ups.year = ?", @year).sum(:total_amount).round(2)
64
+ @a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).where("educode_sales_follow_ups.year <= ?", @year).sum(:total_amount).round(2)
65
65
  b = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name).pluck(:id)
66
- @b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).where("educode_sales_follow_ups.year = ?", @year).sum(:total_amount).round(2)
66
+ @b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).where("educode_sales_follow_ups.year <= ?", @year).sum(:total_amount).round(2)
67
67
  end
68
68
 
69
69
  end
@@ -45,6 +45,7 @@ module EducodeSales
45
45
 
46
46
  def edit
47
47
  @staff = Staff.find(params[:id])
48
+ @permissions = @staff.permissions.pluck(:id)
48
49
  gon.area_ids = @staff.area_ids
49
50
  gon.areas = Common.where(clazz: 'area').map { |d| { value: d.id, title: d.name } } #.unshift({value: -1, title: '全国'})
50
51
  gon.school_ids = @staff.staff_schools.ids
@@ -52,6 +53,8 @@ module EducodeSales
52
53
  # gon.school_ids = School.all.ids
53
54
  # gon.schools = School.all.first(100).map { |d| { value: d.id, title: d.name } } #.unshift({value: -1, title: '全国'})
54
55
  @staff_types = Common.where(clazz: 'staff_type').pluck(:name, :id)
56
+ tag_ids = @staff.staff_school_tags.pluck(:school_tag_id)
57
+ gon.school_properties = SchoolTag.where(for_missions: true).map { |d| { value: d.id, name: d.name, selected: tag_ids.include?(d.id) } }
55
58
  render layout: false
56
59
  end
57
60
 
@@ -65,8 +68,8 @@ module EducodeSales
65
68
  impressionist(staff, params)
66
69
  staff.update(deleted_at: Time.now, expired_at: Time.now.days_ago(1))
67
70
  render_success
68
- # rescue ActiveRecord::DeleteRestrictionError => e
69
- # render_failure '该用户已有数据产生,暂不能删除'
71
+ # rescue ActiveRecord::DeleteRestrictionError => e
72
+ # render_failure '该用户已有数据产生,暂不能删除'
70
73
  end
71
74
 
72
75
  def disable
@@ -82,18 +85,37 @@ module EducodeSales
82
85
  staff.assign_attributes(role_id: params[:role_id], job_type: params[:job_type], enabled_at: params[:enabled_at])
83
86
  staff.expired_at = staff.enabled_at.months_since(params[:month].to_i)
84
87
  commons = []
85
- params[:area_ids].each do |d|
88
+ params[:area_ids].to_s.split(",").each do |d|
86
89
  commons << Common.find(d)
87
90
  end
88
91
  staff.areas = commons
89
92
  if params[:school_ids].present?
90
- staff.staff_schools.destroy_all
91
- params[:school_ids].each do |d|
92
- staff.staff_schools.create(school_id: d)
93
+ schools = []
94
+ params[:school_ids].to_s.split(",").each do |d|
95
+ schools << EducodeSales::StaffSchool.find_or_initialize_by(staff_id: staff.id, school_id: d)
93
96
  end
97
+ staff.staff_schools = schools
94
98
  else
95
99
  staff.staff_schools.destroy_all
96
100
  end
101
+ tags = []
102
+ params[:school_tag_ids].to_s.split(",").each do |tag_id|
103
+ tags << EducodeSales::StaffSchoolTag.find_or_initialize_by(staff_id: staff.id, school_tag_id: tag_id)
104
+ end
105
+ #人员额外权限
106
+ permissions = []
107
+ if params[:permission].present?
108
+ params[:permission].each do |d|
109
+ d[1].each do |c|
110
+ permissions << Permission.find_by(subject: d[0], action: c[1])
111
+ end
112
+ end
113
+ end
114
+ staff.staff_permissions.delete_all
115
+ permissions.each do |permission|
116
+ staff.staff_permissions.create(staff_id:staff.id, permission_id:permission.id)
117
+ end
118
+ staff.staff_school_tags = tags
97
119
  params[:current_admin] = @current_admin.id
98
120
  impressionist(staff, params)
99
121
  if staff.save
@@ -106,14 +128,13 @@ module EducodeSales
106
128
  def follow_up_schools
107
129
  staff = Staff.find(params[:id])
108
130
  @schools = EducodeSales::Teacher.joins(:follow_up, :department).where("educode_sales_teacher_follows.staff_id = #{staff.id}").group("departments.school_id").select("departments.school_id, max(educode_sales_teacher_follows.updated_at) AS updated_at") + EducodeSales::Business.joins(:follow_ups, :department).where("educode_sales_follow_ups.staff_id = #{staff.id}").group("departments.school_id").select("departments.school_id, max(educode_sales_follow_ups.updated_at) AS updated_at")
109
- @count = EducodeSales::Business.joins(:follow_ups, :department).where("educode_sales_follow_ups.staff_id = #{staff.id}").group("departments.school_id").count
131
+ @count = EducodeSales::Business.joins(:follow_ups, :department).where("educode_sales_follow_ups.staff_id = #{staff.id}").group("departments.school_id").count
110
132
  end
111
133
 
112
134
  def follow_up_departments
113
135
  staff = Staff.find(params[:id])
114
- @schools = (EducodeSales::Business.joins(:follow_ups, [department: :school]).where("educode_sales_follow_ups.staff_id = #{staff.id}").select("departments.id, departments.name, schools.name AS school, educode_sales_follow_ups.updated_at") + EducodeSales::Teacher.joins(:follow_up, [department: :school]).where("educode_sales_teacher_follows.staff_id = #{staff.id}").select("departments.id, departments.name, schools.name AS school, educode_sales_teacher_follows.updated_at")).uniq{|s| s.id}
136
+ @schools = (EducodeSales::Business.joins(:follow_ups, [department: :school]).where("educode_sales_follow_ups.staff_id = #{staff.id}").select("departments.id, departments.name, schools.name AS school, educode_sales_follow_ups.updated_at") + EducodeSales::Teacher.joins(:follow_up, [department: :school]).where("educode_sales_teacher_follows.staff_id = #{staff.id}").select("departments.id, departments.name, schools.name AS school, educode_sales_teacher_follows.updated_at")).uniq { |s| s.id }
115
137
  end
116
138
 
117
-
118
139
  end
119
140
  end
@@ -9,7 +9,7 @@
9
9
  if staff.is_admin
10
10
  can :manage, :all
11
11
  else
12
- staff.role.permissions.each do |ps|
12
+ staff.all_permissions.each do |ps|
13
13
  can ps.action.to_sym, "EducodeSales::#{ps.subject}".constantize
14
14
  # level = @current_admin.role.role_areas.find_by(clazz: 'name')&.level
15
15
  # if level == '自己'
@@ -1,7 +1,7 @@
1
1
  module EducodeSales
2
2
  class BusinessClazzChange < ApplicationRecord
3
3
  belongs_to :business
4
- validates :clazz_changed, uniqueness: { message: '已存在' }
4
+ validates :clazz_changed, uniqueness: {scope: :business_id, message: '已存在' }
5
5
 
6
6
 
7
7
 
@@ -5,6 +5,10 @@ module EducodeSales
5
5
 
6
6
  is_impressionable
7
7
 
8
+
9
+ has_many :staff_permissions, dependent: :destroy
10
+ has_many :permissions, through: :staff_permissions
11
+
8
12
  has_many :follow_ups, dependent: :destroy
9
13
  has_many :operation_plans, dependent: :destroy
10
14
  has_many :operation_reports, dependent: :destroy
@@ -19,6 +23,8 @@ module EducodeSales
19
23
 
20
24
  has_many :login_histories, dependent: :destroy
21
25
 
26
+ has_many :staff_school_tags, dependent: :destroy
27
+
22
28
  has_many :market_areas, dependent: :destroy
23
29
  has_many :areas, through: :market_areas
24
30
  validates :user_id, uniqueness: { message: '已存在' }
@@ -29,6 +35,11 @@ module EducodeSales
29
35
  "login_user_#{self.id}"
30
36
  end
31
37
 
38
+ def all_permissions
39
+ ids = Array(self.role&.permissions&.ids) + self.permissions.ids
40
+ Permission.where(id: ids)
41
+ end
42
+
32
43
  def check_login_status(request)
33
44
  unless Rails.cache.data.get(self.last_login_key)
34
45
  # 第二天还在线访问,记用户登录一次
@@ -0,0 +1,6 @@
1
+ module EducodeSales
2
+ class StaffPermission < ApplicationRecord
3
+ belongs_to :staff
4
+ belongs_to :permission
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module EducodeSales
2
+ class StaffSchoolTag < ApplicationRecord
3
+ belongs_to :staff
4
+ belongs_to :school_tag
5
+ end
6
+ end
@@ -151,6 +151,12 @@
151
151
  <% end %>
152
152
  <button class="layui-btn layui-btn-primary layui-border-green layui-btn-sm pull-right at-btn" lay-event="followes"> 我的关注</button>
153
153
  <button class="layui-btn layui-btn-primary layui-border-green layui-btn-sm pull-right my-btn" lay-event="mine"> 我的商机</button>
154
+ <% if can?(:special, EducodeSales::Business) %>
155
+ <button class="layui-btn layui-btn-primary layui-border-green layui-btn-sm pull-right s-btn" lay-event="special">专项管理商机</button>
156
+ <% end %>
157
+ <% if can?(:area_manage, EducodeSales::Business) %>
158
+ <button class="layui-btn layui-btn-primary layui-border-green layui-btn-sm pull-right area-btn" lay-event="area">区域管理商机</button>
159
+ <% end %>
154
160
  <button class="layui-btn layui-btn-primary layui-border-green layui-btn-sm pull-right all-btn" lay-event="all"> 全部商机</button>
155
161
  </div>
156
162
  </script>
@@ -330,6 +336,9 @@
330
336
  data.business_type = business_type_list.getValue('valueStr')
331
337
  data.business_step = business_step_list.getValue('valueStr');
332
338
  data.staff_id = staff_list.getValue('valueStr');
339
+ <% if params[:year].present? %>
340
+ data.year = "<%= params[:year] %>";
341
+ <% end %>
333
342
 
334
343
  table = layui.table;
335
344
  var cols_table = [
@@ -723,6 +732,9 @@
723
732
  data.business_type = business_type.toString();
724
733
  data.business_step = business_step.toString();
725
734
  data.staff_id = staff_list.getValue('valueStr');
735
+ <% if params[:year].present? %>
736
+ data.year = "<%= params[:year] %>";
737
+ <% end %>
726
738
  layer.load(0, {});
727
739
  request.authPost("/missions/businesses/get_export_data", {
728
740
  name: data.name,
@@ -739,10 +751,10 @@
739
751
  date_at: data.date_at,
740
752
  bidded_date: data.bidded_date,
741
753
  business_year: data.business_year,
754
+ year: data.year,
742
755
  mine: search['clazz'] == 'me' ? true : '',
743
756
  is_follow: search['clazz'] == 'followes' ? true : '',
744
757
  }, function (res) {
745
- console.log(res.data);
746
758
  data = res.data
747
759
  table.exportFile(business_table.config.id,data, type);
748
760
  layer.closeAll('loading');
@@ -937,6 +949,9 @@
937
949
  data.field.staff_id = staff_list.getValue('valueStr');
938
950
  data.field.business_type = business_type.toString();
939
951
  data.field.business_step = business_step.toString();
952
+ <% if params[:year].present? %>
953
+ data.field.year = "<%= params[:year] %>";
954
+ <% end %>
940
955
  if (search['clazz']) {
941
956
  data.field['clazz'] = search['clazz']
942
957
  }
@@ -961,6 +976,10 @@
961
976
  $(".my-btn").addClass("selected-btn");
962
977
  } else if (search['clazz'] == 'followes') {
963
978
  $(".at-btn").addClass("selected-btn");
979
+ } else if (search['clazz'] == 'special') {
980
+ $(".s-btn").addClass("selected-btn");
981
+ } else if (search['clazz'] == 'area') {
982
+ $(".area-btn").addClass("selected-btn");
964
983
  } else {
965
984
  $(".all-btn").addClass("selected-btn");
966
985
  }
@@ -1083,6 +1102,40 @@
1083
1102
  $(".my-btn").addClass("selected-btn");
1084
1103
  return false;
1085
1104
  }
1105
+ else if (obj.event === 'special') {
1106
+ search = {"clazz": "special"}
1107
+ business_type_list.setValue([])
1108
+ table.reload('businesses_table', {
1109
+ url: '/missions/businesses',
1110
+ page: {
1111
+ curr: 1
1112
+ },
1113
+ where: {q: search, sort: sort}
1114
+ }, 'data');
1115
+ form.val('search_form', {
1116
+ name: '', department: '', staff_id: '', business_type: '', business_step: '',
1117
+ place_id: '', date: '', area: ''
1118
+ })
1119
+ $(".s-btn").addClass("selected-btn");
1120
+ return false;
1121
+ }
1122
+ else if (obj.event === 'area') {
1123
+ search = {"clazz": "area"}
1124
+ business_type_list.setValue([])
1125
+ table.reload('businesses_table', {
1126
+ url: '/missions/businesses',
1127
+ page: {
1128
+ curr: 1
1129
+ },
1130
+ where: {q: search, sort: sort}
1131
+ }, 'data');
1132
+ form.val('search_form', {
1133
+ name: '', department: '', staff_id: '', business_type: '', business_step: '',
1134
+ place_id: '', date: '', area: ''
1135
+ })
1136
+ $(".area-btn").addClass("selected-btn");
1137
+ return false;
1138
+ }
1086
1139
  else if (obj.event === 'delete') {
1087
1140
  var checkStatus = table.checkStatus('currentTableId'),
1088
1141
  data = checkStatus.data;
@@ -32,21 +32,30 @@
32
32
  <div class="layui-form-item">
33
33
  <label class="layui-form-label required">学校性质:</label>
34
34
  <div class="layui-input-block">
35
- <input type="checkbox" name="project_985" lay-skin="primary" value="1" <%= 'checked' if @school_property&.project_985 %> title="985工程">
36
- <input type="checkbox" name="project_211" lay-skin="primary" value="1" <%= 'checked' if @school_property&.project_211 %> title="211工程" >
37
35
  <input type="checkbox" name="regular_college" lay-skin="primary" value="1" <%= 'checked' if @school_property&.regular_college %> title="本科院校">
36
+ <input type="checkbox" name="military_school" lay-skin="primary" value="1" <%= 'checked' if @school_property&.military_school %> title="军事院校">
37
+ <input type="checkbox" name="junior_college" lay-skin="primary" value="1" <%= 'checked' if @school_property&.junior_college %> title="高职院校">
38
+
38
39
  </div>
39
40
  </div>
40
41
  <div class="layui-form-item">
41
42
  <div class="layui-input-block">
42
- <input type="checkbox" name="junior_college" lay-skin="primary" value="1" <%= 'checked' if @school_property&.junior_college %> title="大专院校">
43
- <input type="checkbox" name="secondary_school" lay-skin="primary" value="1" <%= 'checked' if @school_property&.secondary_school %> title="中专院校" >
44
- <input type="checkbox" name="military_school" lay-skin="primary" value="1" <%= 'checked' if @school_property&.military_school %> title="军事院校">
43
+ <input type="checkbox" name="secondary_school" lay-skin="primary" value="1" <%= 'checked' if @school_property&.secondary_school %> title="中职院校" >
44
+ <input type="checkbox" name="mid_school" lay-skin="primary" value="1" <%= 'checked' if @school_property&.mid_school %> title="中学" >
45
+ <input type="checkbox" name="ele_school" lay-skin="primary" value="1" <%= 'checked' if @school_property&.ele_school %> title="小学" >
46
+
45
47
  </div>
46
48
  </div>
47
49
  <div class="layui-form-item">
48
50
  <div class="layui-input-block">
49
51
  <input type="checkbox" name="enterprise" lay-skin="primary" value="1" <%= 'checked' if @school_property&.enterprise %> title="企业">
52
+ <input type="checkbox" name="other" lay-skin="primary" value="1" <%= 'checked' if @school_property&.other %> title="其他">
53
+ </div>
54
+ </div>
55
+ <div class="layui-form-item" style="display: none;">
56
+ <div class="layui-input-block">
57
+ <input type="checkbox" style="display: none;" name="project_985" lay-skin="primary" value="1" <%= 'checked' if @school_property&.project_985 %> title="985工程">
58
+ <input type="checkbox" style="display: none;" name="project_211" lay-skin="primary" value="1" <%= 'checked' if @school_property&.project_211 %> title="211工程" >
50
59
  </div>
51
60
  </div>
52
61
  <div class="layui-inline" style="padding-left: 120px">
@@ -98,7 +98,7 @@
98
98
  <div class="panel layui-bg-number">
99
99
  <div class="panel-body">
100
100
  <div class="panel-title">
101
- <h5>现有商机<a href="/missions/businesses?name=(销售态势-<%=@year %>-现有商机)&type=1&business_year=<%= @year %>" style="color: #0000FF;float: right">查看商机</a></h5>
101
+ <h5>现有商机<a href="/missions/businesses?name=(销售态势-<%=@year %>-现有商机)&type=1&year=<%= @year %>" style="color: #0000FF;float: right">查看商机</a></h5>
102
102
  </div>
103
103
  <div class="panel-content y-t-10">
104
104
  <h1 class="no-margins"><%= @business_amount.round(2) %>万</h1>
@@ -150,7 +150,7 @@
150
150
  <div class="panel layui-bg-number">
151
151
  <div class="panel-body">
152
152
  <div class="panel-title">
153
- <h5>A类商机<a href="/missions/businesses?type=a&business_year=<%= @year %>" style="color: #0000FF;float: right">查看商机</a></h5>
153
+ <h5>A类商机<a href="/missions/businesses?type=a&year=<%= @year %>" style="color: #0000FF;float: right">查看商机</a></h5>
154
154
  </div>
155
155
  <div class="panel-content y-t-10">
156
156
  <h1 class="no-margins"><%= @a_amount %>万</h1>
@@ -201,7 +201,7 @@
201
201
  <div class="panel layui-bg-number">
202
202
  <div class="panel-body">
203
203
  <div class="panel-title">
204
- <h5>B类商机<a href="/missions/businesses?type=b&business_year=<%= @year %>" style="color: #0000FF;float: right">查看商机</a></h5>
204
+ <h5>B类商机<a href="/missions/businesses?type=b&year=<%= @year %>" style="color: #0000FF;float: right">查看商机</a></h5>
205
205
  </div>
206
206
  <div class="panel-content y-t-10">
207
207
  <h1 class="no-margins"><%= @b_amount %>万</h1>
@@ -1,6 +1,6 @@
1
1
  <%= Gon::Base.render_data %>
2
2
  <div class="layuimini-main" style="height: 100%;">
3
- <div class="layui-form layuimini-form">
3
+ <form class="layui-form " action="">
4
4
  <h4>编辑人员</h4>
5
5
  <div class="layui-form-item">
6
6
  <label class="layui-form-label required">姓名</label>
@@ -35,7 +35,15 @@
35
35
  <div class="layui-input-inline" style="">
36
36
  <div id="edit_assign_follow" style="width: 1140px;"></div>
37
37
  </div>
38
+ </div>
39
+ <% if can?(:special, EducodeSales::Business) %>
40
+ <div class="layui-form-item">
41
+ <label class="layui-form-label">专项客户类型</label>
42
+ <div class="layui-input-inline">
43
+ <div id="school_properties" style="width: 600px;"></div>
38
44
  </div>
45
+ </div>
46
+ <% end %>
39
47
  <div class="layui-form-item">
40
48
  <label class="layui-form-label required">生效日期</label>
41
49
  <div class="layui-input-block">
@@ -51,13 +59,37 @@
51
59
  @staff.month), { 'lay-filter': 'month' } %>
52
60
  </div>
53
61
  </div>
54
-
55
- <hr>
56
62
  <div class="layui-form-item">
63
+ <label class="layui-form-label required">额外权限:</label>
64
+ </div>
65
+
66
+ <!-- <form class="layui-form " action="">-->
67
+ <% id = 0 %>
68
+ <% EducodeSales::Permission.all.order(position: :asc).group_by{ |d| d.clazz}.each do |k, d| %>
69
+ <div class="layui-form-item">
70
+ <label class="layui-form-label"><%= k %></label>
71
+ <div class="layui-input-block">
72
+ <% d.each do |p| %>
73
+ <% id += 1 %>
74
+ <%= check_box_tag "permission[#{p.subject}][]", p.action, @permissions.include?(p.id), {title: p.name, id: "#{id}_" } %>
75
+ <% end %>
76
+ </div>
77
+ </div>
78
+ <% end %>
79
+
80
+ <!-- <div class="m-t-20">-->
81
+ <!-- <div class="layui-input-block">-->
82
+ <!-- <button type="submit" class="layui-btn" lay-submit="" lay-filter="role">提交</button>-->
83
+ <!-- </div>-->
84
+ <!-- </div>-->
85
+ <!-- </form>-->
86
+ <div class="m-t-20">
57
87
  <div class="layui-input-block">
58
- <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确定保存</button>
88
+ <button type="submit" class="layui-btn" lay-submit="" lay-filter="role">提交</button>
59
89
  </div>
60
90
  </div>
91
+ </form>
92
+
61
93
  </div>
62
94
  </div>
63
95
  <script type="text/html" id="edit_currentTableBar">
@@ -78,7 +110,13 @@
78
110
  laydate.render({
79
111
  elem: '#day'
80
112
  });
81
-
113
+ if (document.getElementById("school_properties")) {
114
+ var school_properties_list = xmSelect.render({
115
+ el: '#school_properties',
116
+ data: gon.school_properties,
117
+ filterable: true,
118
+ })
119
+ }
82
120
 
83
121
  var parentIndex = layer.index;
84
122
  transfer.render({
@@ -127,7 +165,7 @@
127
165
  sales_list.setValue(gon.schools)
128
166
 
129
167
  //监听提交
130
- form.on('submit(saveBtn)', function (data) {
168
+ form.on('submit(role)', function (data) {
131
169
  var area_ids = []
132
170
  layui.each(transfer.getData('area_list'), function (i, v) {
133
171
  area_ids.push(v.value)
@@ -136,21 +174,69 @@
136
174
  sales_list.getValue().forEach(function(d) {
137
175
  schools.push(d.value);
138
176
  })
139
- data.field['school_ids'] = schools;
140
- data.field['area_ids'] = area_ids;
141
- request.authPut("missions/staffs/" + parent.staff_id, data.field, function (res) {
142
- console.log(res.success == false)
143
- if (res.success == false) {
144
- layer.alert(res.msg)
145
- } else {
146
- layer.close(parent.index);
147
- parent.layer.close(parent.layer.getFrameIndex(window.name))
148
- parent.table.reload('staff_filter')
177
+ var tag_ids = [];
178
+ if (document.getElementById("school_properties")) {
179
+ school_properties_list.getValue().forEach(function(d) {
180
+ tag_ids.push(d.value);
181
+ })
182
+ }
183
+ data.field['school_ids'] = schools.join(",");
184
+ data.field['area_ids'] = area_ids.join(",");
185
+ data.field['school_tag_ids'] = tag_ids.join(",");
186
+ // request.authPut("missions/staffs/" + parent.staff_id, data.field, function (res) {
187
+ // console.log(res.success == false)
188
+ // if (res.success == false) {
189
+ // layer.alert(res.msg)
190
+ // } else {
191
+ // layer.close(parent.index);
192
+ // parent.layer.close(parent.layer.getFrameIndex(window.name))
193
+ // parent.table.reload('staff_filter')
194
+ // }
195
+ // })
196
+ Rails.ajax({
197
+ url: '/missions/staffs/'+ parent.staff_id,
198
+ type: 'PUT',
199
+ headers: {
200
+ 'Content-Type': 'application/json',
201
+ 'X-CSRF-Token': $('meta[name=csrf-token]').attr('content')
202
+ },
203
+ data: $.param(data.field, true),
204
+ success: function (res) {
205
+ if (res.success == false) {
206
+ layer.alert(res.msg)
207
+ } else {
208
+ layer.close(parent.index);
209
+ parent.layer.close(parent.layer.getFrameIndex(window.name))
210
+ parent.table.reload('staff_filter')
211
+ }
149
212
  }
150
213
  })
151
214
  return false;
152
215
  });
153
216
 
217
+ // form.render();
218
+ // form.on('submit(role)', function (data) {
219
+ // Rails.ajax({
220
+ // url: '/missions/roles/'+ parent.role_id,
221
+ // type: 'PUT',
222
+ // headers: {
223
+ // 'Content-Type': 'application/json',
224
+ // 'X-CSRF-Token': $('meta[name=csrf-token]').attr('content')
225
+ // },
226
+ // data: $.param(data.field, true),
227
+ // success: function (res) {
228
+ // if (res.success == false) {
229
+ // layer.alert(res.msg)
230
+ // } else {
231
+ // layer.close(parent.index);
232
+ // parent.layer.close(parent.layer.getFrameIndex(window.name))
233
+ // parent.table.reload('role')
234
+ // }
235
+ // }
236
+ // })
237
+ // return false;
238
+ // })
239
+
154
240
 
155
241
  });
156
242
  </script>
@@ -30,6 +30,9 @@ class CreateEducodeSalesRolePermissions < ActiveRecord::Migration[5.2]
30
30
  EducodeSales::Permission.create(name: '删除跟进记录(本人创建)', subject: 'Business', action: 'self_delete_follow', clazz: 'business', position: '10')
31
31
 
32
32
  EducodeSales::Permission.create(name: '合并商机', subject: 'Business', action: 'merge_business', clazz: 'business', position: '12')
33
+ EducodeSales::Permission.create(name: '专项管理商机', subject: 'Business', action: 'special', clazz: 'business', position: '13')
34
+ EducodeSales::Permission.create(name: '区域管理商机', subject: 'Business', action: 'area_manage', clazz: 'business', position: '14')
35
+
33
36
  #回款管理权限
34
37
  EducodeSales::Permission.create(name: '查看回款列表', subject: 'MoneyPlan', action: 'read', clazz: 'money_plan', position: '15')
35
38
 
@@ -0,0 +1,10 @@
1
+ class CreateEducodeSalesStaffSchoolTags < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :educode_sales_staff_school_tags do |t|
4
+ t.references :staff
5
+ t.references :school_tag
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateEducodeSalesStaffPermissions < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :educode_sales_staff_permissions do |t|
4
+ t.references :staff
5
+ t.references :permission
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module EducodeSales
2
- VERSION = '0.9.40'
2
+ VERSION = '0.9.42'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: educode_sales
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.40
4
+ version: 0.9.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - anke1460
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-02 00:00:00.000000000 Z
11
+ date: 2023-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -105,6 +105,7 @@ files:
105
105
  - app/assets/images/educode_sales/icon-login.png
106
106
  - app/assets/images/educode_sales/icon.png
107
107
  - app/assets/images/educode_sales/indexLogo.png
108
+ - app/assets/images/educode_sales/indexlogo.png
108
109
  - app/assets/images/educode_sales/loading-0.gif
109
110
  - app/assets/images/educode_sales/loading-1.gif
110
111
  - app/assets/images/educode_sales/loading-2.gif
@@ -220,7 +221,9 @@ files:
220
221
  - app/models/educode_sales/sale_report.rb
221
222
  - app/models/educode_sales/sale_trend.rb
222
223
  - app/models/educode_sales/staff.rb
224
+ - app/models/educode_sales/staff_permission.rb
223
225
  - app/models/educode_sales/staff_school.rb
226
+ - app/models/educode_sales/staff_school_tag.rb
224
227
  - app/models/educode_sales/teacher.rb
225
228
  - app/models/educode_sales/teacher_assign_follow.rb
226
229
  - app/models/educode_sales/teacher_follow.rb
@@ -489,6 +492,8 @@ files:
489
492
  - db/migrate/20221107122147_change_divide_rate_follow_ups.rb
490
493
  - db/migrate/20230115080730_add_origin_business_id_to_follow_ups.rb
491
494
  - db/migrate/20230117144025_create_educode_sales_business_clazz_changes.rb
495
+ - db/migrate/20230206080303_create_educode_sales_staff_school_tags.rb
496
+ - db/migrate/20230209102302_create_educode_sales_staff_permissions.rb
492
497
  - lib/educode_sales.rb
493
498
  - lib/educode_sales/engine.rb
494
499
  - lib/educode_sales/version.rb
@@ -497,7 +502,7 @@ homepage: https://www.educoder.net
497
502
  licenses:
498
503
  - MIT
499
504
  metadata: {}
500
- post_install_message:
505
+ post_install_message:
501
506
  rdoc_options: []
502
507
  require_paths:
503
508
  - lib
@@ -512,8 +517,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
512
517
  - !ruby/object:Gem::Version
513
518
  version: '0'
514
519
  requirements: []
515
- rubygems_version: 3.0.0
516
- signing_key:
520
+ rubygems_version: 3.0.9
521
+ signing_key:
517
522
  specification_version: 4
518
523
  summary: Summary of EducodeSales.
519
524
  test_files: []