From 77c25db2337b191d3adc1b3e59072099994d5fe1 Mon Sep 17 00:00:00 2001 From: cxt Date: Mon, 13 Mar 2017 10:22:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E8=80=85=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=EF=BC=8C=E6=97=A0=E9=9C=80=E8=BA=AB=E4=BB=BD=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=EF=BC=8C=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=BB=99=E7=AB=9E=E8=B5=9B=E6=89=80=E6=9C=89=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E5=8D=B3=E5=8F=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/contests_service.rb | 38 +++++++++++++------ .../layouts/_show_messages_list.html.erb | 5 ++- .../users/_user_message_contest.html.erb | 28 +++++++++++++- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/app/services/contests_service.rb b/app/services/contests_service.rb index b4bb1acde..143be7282 100644 --- a/app/services/contests_service.rb +++ b/app/services/contests_service.rb @@ -24,18 +24,34 @@ class ContestsService if params[:invite_code].present? role_ids = params[:role] - #如果已经发送过消息了,那么就要给个提示 - if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :status => 0).count != 0 - @state = 7 - else - if role_ids.size == 1 - AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_ids[0], :status => 0) - else - role_ids.each do |role_id| - AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_id, :status => 0) - end + if role_ids.include?("15") + member = ContestMember.new(:user_id => current_user.id) + contest.contest_members << member + contest_member_roles = member.contest_member_roles + contest_member_roles << ContestMemberRole.new(:role_id => 15) + ContestantForContest.create(:student_id => current_user.id, :contest_id => contest.id) + + # 给管理员发消息 + admins = contest_managers contest + admins.each do |member| + course_join = ContestMessage.new(:user_id =>member.user_id, :contest_message_id=>current_user.id,:contest_id => contest.id,:contest_message_type=>"JoinContest", :content => role_ids, :viewed => false, :status => 2) + course_join.save + end + @state = 0 + else + #如果已经发送过消息了,那么就要给个提示 + if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :status => 0).count != 0 + @state = 7 + else + if role_ids.size == 1 + AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_ids[0], :status => 0) + else + role_ids.each do |role_id| + AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_id, :status => 0) + end + end + @state = 6 end - @state = 6 end else @state = 1 diff --git a/app/views/layouts/_show_messages_list.html.erb b/app/views/layouts/_show_messages_list.html.erb index 962a68774..3a4472815 100644 --- a/app/views/layouts/_show_messages_list.html.erb +++ b/app/views/layouts/_show_messages_list.html.erb @@ -139,7 +139,10 @@
  • <%=User.find(ma.contest_message_id).show_name %> 将您加入了竞赛:<%= ma.contest.name%>
  • <% elsif ma.contest_message_type == "JoinContest" and ma.status == 1 %>
  • ">系统提示 您增加了新的竞赛成员:<%= User.find(ma.contest_message_id).login+"("+User.find(ma.contest_message_id).show_name+")"%>
  • - <% elsif ma.contest_message_type == "JoinContest" and ma.status == 1 %> + <% elsif ma.contest_message_type == "JoinContest" and ma.status == 2 %> + <% user = User.find(ma.contest_message_id) %> +
  • <%=user.show_name %> <%= user.user_extensions.school_id.blank? || user.user_extensions.school.nil? ? '' : '来自'+user.user_extensions.school.name+',' %>以'参赛者'的身份加入了竞赛:<%= ma.contest.name%>
  • + <% elsif ma.contest_message_type == "RemoveFromContest" %>
  • <%=User.find(ma.contest_message_id).show_name %> 将您移出了竞赛:<%= ma.contest.name%>
  • <% end %> <% elsif ma.class == AppliedMessage %> diff --git a/app/views/users/_user_message_contest.html.erb b/app/views/users/_user_message_contest.html.erb index ad5656cc8..2aaf72f65 100644 --- a/app/views/users/_user_message_contest.html.erb +++ b/app/views/users/_user_message_contest.html.erb @@ -46,7 +46,7 @@
  • <%= time_tag(ma.created_at).html_safe %>
  • - + <% elsif ma.contest_message_type == "JoinContest" and ma.status == 0 %> - + <% elsif ma.contest_message_type == "JoinContest" and ma.status == 1 %> + + <% elsif ma.contest_message_type == "JoinContest" and ma.status == 2 %> + + <% elsif ma.contest_message_type == "RemoveFromContest" %>