Class: EducodeSales::FollowUpsController
Instance Method Summary
collapse
#authenticate_admin, #authenticate_request, #current_user, #render_failure, #render_success
Instance Method Details
#add_keys ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'app/controllers/educode_sales/follow_ups_controller.rb', line 101
def add_keys
follow_up = FollowUp.find(params[:id])
if params[:name].blank?
return render_failure '请从平台里选择教师'
end
names = params[:name].split("-")
if names[0] == 't'
teacher = Teacher.find(names[1])
key_peprson = KeyPerson.new(teacher_params)
key_peprson.teacher = teacher
else
user = User.find(names[1])
teacher = Teacher.new(staff: @current_admin,
professional_title: params[:professional_title],
job: params[:job],
user_id: user.id,
is_key: true,
department_id: user.department_id,
name: user.real_name
)
teacher.save
key_peprson = KeyPerson.new(teacher_params)
key_peprson.teacher = teacher
end
follow_up.key_person << key_peprson
if follow_up.save!
render_success
else
render_failure follow_up
end
rescue ActiveRecord::RecordInvalid => e
if e.message.include?("Teacher已经被使用") || e.message.include?('Key person是无效的')
render_failure '该老师已在关键人列表中'
else
render_failure e.message
end
end
|
#add_money ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/educode_sales/follow_ups_controller.rb', line 70
def add_money
follow_up = FollowUp.find(params[:id])
money_plan = follow_up.money_plans.build(date_at: params[:date_at], amount: params[:amount], clazz: params[:clazz])
money_plan.staff = @current_admin
if money_plan.save
render_success
else
render_failure money_plan
end
end
|
#create ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/controllers/educode_sales/follow_ups_controller.rb', line 6
def create
load_business
follow_up = @business.follow_ups.build(follow_up_params)
follow_up.staff = @current_admin
follow_up.profit_amount = follow_up.actual_amount * (100-follow_up.divide_rate.to_i) * 0.01 if follow_up.actual_amount
if follow_up.save
if @business.last_follow_up.present?
@business.last_follow_up.key_person.each do |d|
key_person = d.dup
key_person.follow_up_id = follow_up.id
key_person.save
end
@business.last_follow_up.money_plans.each do |d|
money = d.dup
money.staff = @current_admin
money.follow_up_id = follow_up.id
money.save
end
end
@business.update(last_follow_up_id: follow_up.id)
render_success
else
render_failure follow_up
end
end
|
#delete_money ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'app/controllers/educode_sales/follow_ups_controller.rb', line 91
def delete_money
follow_up = FollowUp.find_by(id: params[:id])
money_plan = follow_up.money_plans.find(params[:plan_id])
if money_plan.destroy
render_success
else
render_failure money_plan
end
end
|
#destroy ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/educode_sales/follow_ups_controller.rb', line 32
def destroy
follow_up = FollowUp.find(params[:id])
business = follow_up.business
if follow_up.destroy
if follow_up.id == business.last_follow_up_id
business.update(last_follow_up: business.follow_ups.last, return_money: MoneyPlan.where(clazz: '已完成', follow_up_id: business.follow_ups.last&.id).sum(:amount))
end
render_success
else
render_failure follow_up
end
end
|
#money_plans ⇒ Object
65
66
67
68
|
# File 'app/controllers/educode_sales/follow_ups_controller.rb', line 65
def money_plans
follow_up = FollowUp.find_by(id: params[:id])
@money_plans = follow_up.money_plans.page(params[:page]).per(params[:limit])
end
|
#teachers ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'app/controllers/educode_sales/follow_ups_controller.rb', line 56
def teachers
follow_up = FollowUp.find_by(id: params[:id])
if follow_up.present?
@teachers = follow_up.key_person.includes(:teacher).page(params[:page]).per(params[:limit])
else
@teachers = FollowUp.none
end
end
|
#update ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'app/controllers/educode_sales/follow_ups_controller.rb', line 45
def update
follow_up = FollowUp.find(params[:id])
follow_up.assign_attributes(follow_up_params)
follow_up.profit_amount = follow_up.actual_amount * (100-follow_up.divide_rate.to_i) * 0.01 if follow_up.actual_amount
if follow_up.save
render_success
else
render_failure follow_up
end
end
|
#update_money ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'app/controllers/educode_sales/follow_ups_controller.rb', line 81
def update_money
follow_up = FollowUp.find_by(id: params[:id])
money_plan = follow_up.money_plans.find(params[:plan_id])
if money_plan.update(date_at: params[:date_at], amount: params[:amount], clazz: params[:clazz])
render_success
else
render_failure money_plan
end
end
|