修改加入班级的提示

This commit is contained in:
yuanke 2016-07-15 09:48:10 +08:00
parent 6ab1269c01
commit b8c8b2c4ae
2 changed files with 4 additions and 40 deletions

View File

@ -211,17 +211,8 @@ class WechatsController < ActionController::Base
#取出用户角色类型
role = 10
case user.user_extensions.identity
when 0
role = "9"
when 1
role = "10"
when 2
role = "7"
end
cs = CoursesService.new
status = cs.join_course({role:role,invite_code: course.invite_code}, user)
status = cs.join_course({invite_code: course.invite_code}, user)
logger.info status
if status[:state] != 0
raise CoursesService::JoinCourseError.message(status[:state])

View File

@ -354,54 +354,27 @@ class CoursesService
roleName = member.roles[0].name if member
if params[:invite_code].present?
#如果加入角色为学生 并且当前是学生
if params[:role] == "10" && roleName == "Student"
if roleName == "Student"
@state = 3
#如果加入的角色为老师,并且当前已经是老师
elsif params[:role] == "9" && roleName == "Teacher"
elsif roleName == "Teacher"
@state = 8
#如果加入的角色教辅并且当前为教辅
elsif params[:role] == "7" && roleName == "TeachingAsistant"
elsif roleName == "TeachingAsistant"
@state = 9
elsif roleName == "Manager"
@state = 10
#如果加入角色为教师或者教辅,并且当前是学生,或者是要成为教辅,当前不是教辅,或者要成为教师,当前不是教师。那么要发送请求
elsif (params[:role] != "10" && roleName == "Student") || (params[:role] == "7" && roleName != "TeachingAsistant" ) || (params[:role] == "9" && roleName != "Teacher" )
#如果已经发送过消息了,那么就要给个提示
if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0 ").count != 0
@state = 7
else
Mailer.run.join_course_request(course, User.current, params[:role])
CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0)
@state = 6
end
#如果加入角色是学生,但是是当前课程的教师或者教辅
elsif params[:role] == "10" && roleName != "Student"
member.role_ids = [params[:role]]
member.save
StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id)
@state = 0
end
else
@state = 1
end
else
if params[:invite_code].present?
if params[:role] == "10" || params[:role] == nil
members = []
members << Member.new(:role_ids => [10], :user_id => current_user.id)
course.members << members
StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id)
@state = 0
else
#如果已经发送过消息了,那么就要给个提示
if CourseMessage.where("course_message_type = 'JoinCourseRequest' and user_id = #{course.tea_id} and content = #{params[:role]} and course_message_id = #{User.current.id} and course_id = #{course.id} and status = 0").count != 0
@state = 7
else
Mailer.run.join_course_request(course, User.current, params[:role])
CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0)
@state = 6
end
end
else
@state = 1
end