You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
37 lines
1.2 KiB
6 years ago
|
class CourseMessage < ApplicationRecord
|
||
|
enum status: { UNHANDLED: 0, PASSED: 1, REJECTED: 2 }
|
||
|
belongs_to :course
|
||
|
belongs_to :user
|
||
|
|
||
|
scope :find_by_course, ->(course) { where(course_id: course.id) }
|
||
|
scope :join_course_requests, -> { where(course_message_type: "JoinCourseRequest") }
|
||
|
scope :unhandled, -> { where(status: :UNHANDLED) }
|
||
|
|
||
|
scope :unhandled_join_course_requests_by_course, ->(course) { find_by_course(course).join_course_requests.unhandled }
|
||
|
|
||
|
def pass!
|
||
|
update!(status: :PASSED)
|
||
|
send_deal_tiding
|
||
|
end
|
||
|
|
||
|
def application_user
|
||
|
User.find_by(id: course_message_id)
|
||
|
end
|
||
|
|
||
|
def reject!
|
||
|
update!(status: :REJECTED)
|
||
|
send_deal_tiding
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def send_deal_tiding
|
||
|
# 发送申请处理结果消息
|
||
|
Tiding.create!(
|
||
|
user_id: user_id, trigger_user: User.current, container_id: course_id, container_type: 'DealCourse',
|
||
|
belong_container: course, extra: content.to_i == 2 ? '7' : '9', tiding_type: 'System', status: status == :PASSED ? 1 : 2
|
||
|
)
|
||
|
# 将申请消息置为已处理
|
||
|
Tiding.where(trigger_user_id: user_id, container_id: course_id, container_type: 'JoinCourse', status: 0).update_all(status: 1)
|
||
|
end
|
||
|
end
|