2016-12-22 15:08:15 +08:00
|
|
|
#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]
|
2016-12-22 17:13:10 +08:00
|
|
|
role_str = role_ids.join(",").to_s
|
2016-12-22 15:08:15 +08:00
|
|
|
|
|
|
|
#如果已经发送过消息了,那么就要给个提示
|
|
|
|
if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :role => role_str, :status => 0).count != 0
|
|
|
|
@state = 7
|
|
|
|
else
|
|
|
|
AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_str, :status => 0)
|
|
|
|
@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
|