diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index e3b81d6d5..e566a8f46 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -326,45 +326,49 @@ class CoursesService #如果加入的角色教辅并且当前为教辅 elsif params[:role] == "7" && 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 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 #如果加入角色是学生,但是是当前课程的教师或者教辅 elsif params[:role] == "10" && roleName != "Student" member.role_ids = [params[:role]] member.save StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) @state = 0 - elsif roleName == "Manager" - @state = 10 - #如果加入角色为教师或者教辅,并且当前是学生,或者是要成为教辅,当前不是教辅,或者要成为教师,当前不是教师。那么要发送请求 - elsif (params[:role] != "10" && roleName == "Student") || (params[:role] == "7" && roleName != "TeachingAsistant" ) || (params[:role] == "9" && roleName != "Teacher" ) - 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 else @state = 1 end else - if params[:course_password] == course.password - 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 => params[:object_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 + if params[:course_password] == course.password + 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 => params[:object_id]) + @state = 0 else - @state = 1 + #如果已经发送过消息了,那么就要给个提示 + 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 end end else