From ae6fe6f9a7d582c11d2db8a20fc5c150e2cffa22 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Fri, 30 Oct 2015 15:55:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B3=E8=AF=B7=E5=8A=A0=E5=85=A5=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=EF=BC=8C=E5=85=81=E8=AE=B8=E8=BA=AB=E4=BB=BD=E8=A6=86?= =?UTF-8?q?=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- app/services/courses_service.rb | 38 ++++++++++++++++++++++------- app/views/courses/join.js.erb | 8 ++++++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 133fcd94c..d79083919 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -243,7 +243,7 @@ class UsersController < ApplicationController #status 1 同意 2 拒绝 def dealwith_apply_request @msg = CourseMessage.find(params[:msg_id]) - + #CourseMessage content存的是role 7教辅 9 教师 case params[:agree] when 'Y' apply_user = User.find(@msg.course_message_id) diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 8092bee88..74580632f 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -301,26 +301,46 @@ class CoursesService #@state == 5 您还未登录 #@state == 6 申请成功,请等待审核完毕 #@state == 7 您已经发送过申请了,请耐心等待 + #@state == 8 您已经是该课程的教师了 + #@state == 9 您已经是该课程的教辅了 #@state 其他 未知错误,请稍后再试 def join_course params,current_user course = Course.find_by_id params[:object_id] + @state = 10 if course if course_endTime_timeout? course @state = 2 else if current_user.member_of_course?(course) #如果已经是成员 + member = course.members.where("user_id=#{current_user.id} and course_id=#{course.id}")[0] + roleName = member.roles[0].name if member if params[:course_password] == course.password - #如果加入角色为学生 - if params[:role] == "10" + #如果加入角色为学生 并且当前是学生 + if params[:role] == "10" && roleName == "Student" @state = 3 - elsif current_user.allowed_to?(:as_teacher,course) - @state = 3 - 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 + #如果加入的角色为老师,并且当前已经是老师 + elsif params[:role] == "9" && roleName == "Teacher" + @state = 8 + #如果加入的角色教辅并且当前为教辅 + elsif params[:role] == "7" && roleName == "TeachingAsistant" + @state = 9 + #如果加入角色为教师或者教辅,并且当前是学生,或者是要成为教辅,当前不是教辅,或者要成为教师,当前不是教师。那么要发送请求 + 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 end else @state = 1 diff --git a/app/views/courses/join.js.erb b/app/views/courses/join.js.erb index 721367549..2b4927f48 100644 --- a/app/views/courses/join.js.erb +++ b/app/views/courses/join.js.erb @@ -24,6 +24,14 @@ hidden_join_course_form(); <% elsif @state == 7%> alert("您已经发送过申请了,请耐心等待"); hidden_join_course_form(); +<% elsif @state == 8%> +alert("您已经是该课程的教师了"); +hidden_join_course_form(); +window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" +<% elsif @state == 9%> +alert("您已经是该课程的教辅了"); +hidden_join_course_form(); +window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% else %> alert("未知错误,请稍后再试"); <% end %>