50 lines
1.7 KiB
Ruby
50 lines
1.7 KiB
Ruby
#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 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
|
|
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 |