educode_sales 0.2.9 → 0.3.3

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
  SHA1:
3
- metadata.gz: adac2dac455b86334fc478e4f84454fe0596f15b
4
- data.tar.gz: ab4d5c46df6d081c3b193f94aba90d6f644bb35e
3
+ metadata.gz: d03c13290f7199b6950c19060fb7efc58f3d5bbd
4
+ data.tar.gz: a3bc8311248e48fcfa615906d5607a8d3347755a
5
5
  SHA512:
6
- metadata.gz: d6c23010d60071f32bad83b9ae20e8ffe767e06120db34992faef60d58aca8f1f1e1b690b0421ecf54cd35fd126948c8dad429aa1e386af64aad7b8ca6522482
7
- data.tar.gz: 0a863555c19683cc7516bf77468df8cc296af577d8e7a87d5f2fc588005b2f4c59325062d617ae70af64929060cf9f1328b80a0ee70af5c196574dbd24743f84
6
+ metadata.gz: ec1f20e0b7e6d6d4ffbcc89cab5fd6815ae26c37f836f027ac8065746e21546141fe26c15cad74f403bc80402bc4bf9e315ae099969bd24a84a33d1e329828ac
7
+ data.tar.gz: 35154b0f7e422796b80e80a7952485885cb4d4cb4718e9065db900b915aee9d4df8b11d87ae9bf56f25d9b09e8c11a0cf51e473b24f4f51a27d4af83e8979416
@@ -20,7 +20,7 @@ module EducodeSales
20
20
  when '自己'
21
21
  @sale_plans = OperationPlan.where(staff_id: @current_admin.id)
22
22
  when '区域'
23
- staff_ids = Staff.joins(department: :school).where("school.province in ?", staff.areas.pluck(:name)).pluck(:id)
23
+ staff_ids = Staff.joins(department: :school).where("school.province in ?", @current_admin.areas.pluck(:name)).pluck(:id)
24
24
  @sale_plans = OperationPlan.where("staff_id in ?", staff_ids)
25
25
  else
26
26
  @sale_plans = OperationPlan
@@ -117,7 +117,16 @@ module EducodeSales
117
117
 
118
118
  def edit_week
119
119
  @teacher = Teacher.find_by(id: params[:teacher_id])
120
- @teachers = @current_admin.teachers.where(is_key: 0).pluck(:name, :id)
120
+ level = @current_admin.is_admin? ? '全部' : @current_admin.role.role_areas.find_by(clazz: '运营计划').level
121
+ if level == '自己'
122
+ @teachers = @current_admin.teachers.where(is_key: 0).pluck(:name, :id)
123
+ elsif level == '区域'
124
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
125
+ @teachers = Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where(is_key: false).where("departments.school_id in (?) OR educode_sales_teachers.staff_id = #{@current_admin.id}", school_ids)
126
+ else
127
+ @teachers = Teacher.where(is_key: 0).pluck(:name, :id)
128
+ end
129
+
121
130
  @sale_plan = OperationPlan.find(params[:id])
122
131
  if @sale_plan.weekly.present?
123
132
  week = Time.now.strftime('%W').to_i
@@ -145,7 +154,15 @@ module EducodeSales
145
154
 
146
155
  def edit_month
147
156
  @teacher = Teacher.find_by(id: params[:teacher_id])
148
- @teachers = @current_admin.teachers.where(is_key: 0).pluck(:name, :id)
157
+ level = @current_admin.is_admin? ? '全部' : @current_admin.role.role_areas.find_by(clazz: '运营计划').level
158
+ if level == '自己'
159
+ @teachers = @current_admin.teachers.where(is_key: 0).pluck(:name, :id)
160
+ elsif level == '区域'
161
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
162
+ @teachers = Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where(is_key: false).where("departments.school_id in (?) OR educode_sales_teachers.staff_id = #{@current_admin.id}", school_ids)
163
+ else
164
+ @teachers = Teacher.where(is_key: 0).pluck(:name, :id)
165
+ end
149
166
  @sale_plan = OperationPlan.find(params[:id])
150
167
  @months = [Time.now.strftime("%Y-%m"), Time.now.months_ago(1).strftime("%Y-%m")]
151
168
  @months << @sale_plan.month.strftime("%Y-%m")
@@ -23,7 +23,7 @@ module EducodeSales
23
23
  end
24
24
 
25
25
  def destroy
26
- follow_up = @current_admin.teacher_follows.find(params[:id])
26
+ follow_up = TeacherFollow.find(params[:id])
27
27
  if follow_up.destroy
28
28
  render_success
29
29
  else
@@ -32,7 +32,7 @@ module EducodeSales
32
32
  end
33
33
 
34
34
  def update
35
- follow_up = @current_admin.teacher_follows.find(params[:id])
35
+ follow_up = TeacherFollow.find(params[:id])
36
36
  follow_up.assign_attributes(follow_up_params)
37
37
  # follow_up.profit_amount = follow_up.actual_amount * (100-follow_up.divide_rate.to_i) * 0.01 if follow_up.actual_amount
38
38
  if follow_up.save
@@ -98,13 +98,19 @@ module EducodeSales
98
98
  end
99
99
 
100
100
  if params[:activity_id].present? && params[:user_id].present?
101
+ @teacher_id = EducodeSales::Teacher.find_by(name: params[:name]).id
102
+
101
103
  # 把老师添加到活动列表,提取判断下老师列表是否存在
102
104
  find_teacher = Teacher.find_by(user_id: params[:user_id])
103
105
  if find_teacher
104
106
  teacher = find_teacher
105
107
  end
106
108
  end
107
- teacher.activity_teachers.build(activity_id: params[:activity_id])
109
+ if params[:activity_id].present?
110
+ return render json: {msg: '该教师已在活动中', success: false } if teacher.activity_teachers.find_by(activity_id: params[:activity_id]).present?
111
+ teacher.activity_teachers.build(activity_id: params[:activity_id])
112
+ end
113
+
108
114
  if teacher.save
109
115
  render_success
110
116
  else
@@ -2,5 +2,7 @@ module EducodeSales
2
2
  class ActivityTeacher < ApplicationRecord
3
3
  belongs_to :activity, counter_cache: true
4
4
  belongs_to :teacher, counter_cache: true
5
+
6
+ validates :teacher_id, uniqueness: {scope: :activity_id, message: '已存在'}
5
7
  end
6
8
  end
@@ -14,19 +14,25 @@ module EducodeSales
14
14
  validates :user_id, uniqueness: { allow_blank: true, message: '已存在老师列表'}
15
15
 
16
16
 
17
+ # def teacher_used_of_department
18
+ # if user_id.present?
19
+ # user_ids = User.joins(:user_extension).where(user_extensions: {department_id: self.department_id, identity: 0}).pluck(:id)
20
+ # course_ids = CourseMember.where(role: "CREATOR", user_id: user_ids).pluck(:course_id)
21
+ # if course_ids.present?
22
+ # course_members = CourseMember.joins(course: :practice_homework_shixuns).where(course_id: course_ids).group("course_id").having("COUNT(homework_commons_shixuns.id) > 100 AND COUNT(course_members.user_id) > 20").select("COUNT(case when course_members.role !=4 then 1 END) AS count")
23
+ # course_members.present? ? course_members[0]['count'] : 0
24
+ # else
25
+ # 0
26
+ # end
27
+ # else
28
+ # 0
29
+ # end
30
+ # end
17
31
  def teacher_used_of_department
18
- if user_id.present?
19
32
  user_ids = User.joins(:user_extension).where(user_extensions: {department_id: self.department_id, identity: 0}).pluck(:id)
20
33
  course_ids = CourseMember.where(role: "CREATOR", user_id: user_ids).pluck(:course_id)
21
- if course_ids.present?
22
- course_members = CourseMember.joins(course: :practice_homework_shixuns).where(course_id: course_ids).group("course_id").having("COUNT(homework_commons_shixuns.id) > 100 AND COUNT(course_members.user_id) > 20").select("COUNT(case when course_members.role !=4 then 1 END) AS count")
23
- course_members.present? ? course_members[0]['count'] : 0
24
- else
25
- 0
26
- end
27
- else
28
- 0
29
- end
34
+ course_members = CourseMember.joins(course: :practice_homework_shixuns).where(course_id: course_ids).group("course_id").having("COUNT(homework_commons_shixuns.id) > 100 AND COUNT(course_members.user_id) > 20").select("COUNT(case when course_members.role !=4 then 1 END) AS count")
35
+ course_members.present? ? course_members[0]['count'] : 0
30
36
  end
31
37
 
32
38
  def students_count
@@ -15,8 +15,7 @@ json.data do
15
15
  json.total_amount d.last_follow_up&.total_amount
16
16
  json.return_money d.return_money
17
17
  json.place d.last_follow_up&.place&.name
18
- json.last_follow_person d.last_follow_up.present? d.last_follow_up.staff.user.real_name : ''
19
-
18
+ json.last_follow_person d.last_follow_up.present? ? d.last_follow_up.staff.user.real_name : ''
20
19
  end
21
20
  end
22
21
  json.code 0
@@ -118,12 +118,12 @@
118
118
  },
119
119
  {
120
120
  field: 'rate',
121
- width: 100,
121
+ width: 80,
122
122
  title: '完成率',
123
123
  },
124
124
  {
125
125
  field: 'updated_at',
126
- width: 150,
126
+ width: 170,
127
127
  title: '更新时间',
128
128
  sort: true,
129
129
  },
@@ -129,12 +129,12 @@
129
129
  },
130
130
  {
131
131
  field: 'rate',
132
- width: 100,
132
+ width: 80,
133
133
  title: '完成率',
134
134
  },
135
135
  {
136
136
  field: 'updated_at',
137
- width: 150,
137
+ width: 170,
138
138
  title: '更新时间',
139
139
  sort: true,
140
140
  },
@@ -11,9 +11,7 @@
11
11
  <div class="layui-inline">
12
12
  <label class="layui-form-label">教师</label>
13
13
  <div class="layui-input-inline">
14
- <%#= select_tag "teacher_id", options_for_select(@teachers, @sale_plan.teacher_id), class: 'required' %>
15
- <%= select_tag "teacher_id", options_for_select(@teachers), class: 'required' %>
16
-
14
+ <%= select_tag "teacher_id", options_for_select(@teachers, @sale_plan.teacher_id), class: 'required' %>
17
15
  </div>
18
16
  </div>
19
17
  <div class="layui-form-item layui-form-text">
@@ -19,9 +19,7 @@
19
19
  <div class="layui-inline">
20
20
  <label class="layui-form-label">教师</label>
21
21
  <div class="layui-input-inline">
22
- <%#= select_tag "teacher_id", options_for_select(@teachers, @sale_plan.teacher_id), class: 'required' %>
23
- <%= select_tag "teacher_id", options_for_select(@teachers), class: 'required' %>
24
-
22
+ <%= select_tag "teacher_id", options_for_select(@teachers, @sale_plan.teacher_id), class: 'required' %>
25
23
  </div>
26
24
  </div>
27
25
  <div class="layui-form-item layui-form-text">
@@ -130,7 +130,7 @@
130
130
  },
131
131
  {
132
132
  title: '操作',
133
- minWidth: 150,
133
+ minWidth: 190,
134
134
  toolbar: '#currentMonthly',
135
135
  align: "center"
136
136
  }
@@ -130,7 +130,7 @@
130
130
  },
131
131
  {
132
132
  title: '操作',
133
- minWidth: 150,
133
+ minWidth: 190,
134
134
  toolbar: '#currentWeekly',
135
135
  align: "center"
136
136
  }
@@ -9,7 +9,7 @@ json.data do
9
9
  json.contact EducodeSales::Common.find_by(id: d.follow_id).name
10
10
  json.staff d.staff.user.real_name
11
11
  json.students_count d.students_count
12
- json.courses_count d.courses_count
12
+ json.courses_count Course.joins(:course_members).where(course_members: {user_id: d.teacher&.user_id}).distinct("course_id").count
13
13
  json.evaluates_count d.evaluates_count
14
14
  json.course_shixuns_count d.course_shixuns_count
15
15
  json.shixuns_count d.shixuns_count
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
 
4
4
  <head>
5
- <title><%= @title || 'Educode sales' %></title>
5
+ <title><%= @title || '头歌营销系统' %></title>
6
6
  <%= csrf_meta_tags %>
7
7
  <%= csp_meta_tag %>
8
8
  <%= favicon_link_tag "educode_sales/favicon.ico" %>
@@ -1,3 +1,3 @@
1
1
  module EducodeSales
2
- VERSION = '0.2.9'
2
+ VERSION = '0.3.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: educode_sales
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - anke1460