dev_aliyun
daiao 5 years ago
commit 3c80214c74

@ -206,7 +206,7 @@ class CompetitionTeamsController < ApplicationController
teacher_staff = @competition.competition_staffs.where(category: 'teacher').first
if teacher_staff.blank?
@status, @message = -1, '该竞赛不能配备导师'
@status, @message = -1, '老师不能参加该竞赛'
return
end
@ -217,7 +217,10 @@ class CompetitionTeamsController < ApplicationController
team.team_members.create!(user_id: User.current.id, role: 3, competition_id: @competition.id, is_teacher: true)
else
max_member_count = @competition.competition_staffs.where('category != "teacher"').sum(:maximum)
if team.members.count + 1 > max_member_count
if max_member_count.zero?
@status, @message = -1, '学生不能参加该竞赛'
return
elsif team.members.count + 1 > max_member_count
@status, @message = -1, '该战队成员人数已满'
return
end
@ -279,7 +282,7 @@ class CompetitionTeamsController < ApplicationController
teacher_count += 1 if is_teacher
# 检查老师数量
if teacher_staff.blank? && teacher_count > 0
@status, @message = -1, '该竞赛不能配备导师'
@status, @message = -1, '老师不能参与该竞赛'
return false
elsif teacher_staff.present? && (teacher_staff.minimum > teacher_count || teacher_staff.maximum < teacher_count)
@status = -1
@ -293,7 +296,10 @@ class CompetitionTeamsController < ApplicationController
member_count = params[:member_ids].try(:size) || 0
member_count += 1 unless is_teacher
# 检查成员数据
if min_member_count > member_count || member_count > max_member_count
if member_relations.count.zero? && member_count > 0
@status, @message = -1, '学生不能参与该竞赛'
return false
elsif min_member_count > member_count || member_count > max_member_count
@status = -1
@message = min_member_count == max_member_count ? "成员数量应为#{max_member_count}" : "成员数量应为#{min_member_count}-#{max_member_count}"
return false

Loading…
Cancel
Save