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.
66 lines
2.6 KiB
66 lines
2.6 KiB
#coding=utf-8
|
|
class ContestsService
|
|
include ApplicationHelper
|
|
include ContestsHelper
|
|
include ApiHelper
|
|
include ActionView::Helpers::DateHelper
|
|
|
|
#多个角色加入竞赛
|
|
def join_contest_roles params,current_user
|
|
contest = Contest.find_by_invite_code(params[:invite_code]) if params[:invite_code]
|
|
go_contestgroup_flag = 0
|
|
contest_id = 0
|
|
|
|
@state = 10
|
|
if contest
|
|
if contest[:is_delete] == 1
|
|
@state = 11
|
|
elsif contest[:invite_code_halt] == 1
|
|
@state = 14
|
|
else
|
|
if current_user.member_of_contest?(contest) #如果已经是成员
|
|
@state = 3
|
|
else
|
|
if params[:invite_code].present?
|
|
role_ids = params[:role]
|
|
|
|
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
|
|
end
|
|
else
|
|
@state = 1
|
|
end
|
|
end
|
|
end
|
|
else
|
|
@state = 4
|
|
end
|
|
{:state => @state, :contest => contest, :go_contestgroup_flag => go_contestgroup_flag, :contest_id => contest_id}
|
|
end
|
|
end |