|
|
|
@ -14,58 +14,33 @@ class Admins::CompetitionStagesController < Admins::BaseController
|
|
|
|
|
current_stage.destroy!
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_stage_section
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
new_section = CompetitionStageSection.create!(competition_id: current_stage.competition_id, competition_stage_id: current_stage.id,
|
|
|
|
|
start_time: params[:new_start_time], end_time: params[:new_end_time],
|
|
|
|
|
entry: params[:entry], mission_count: params[:mission_count], score_source: params[:score_source])
|
|
|
|
|
unless params[:shixun_identifiers].blank?
|
|
|
|
|
params[:shixun_identifiers].each do |identifier|
|
|
|
|
|
new_section.competition_entries << CompetitionEntry.new(competition_stage_id: current_stage.id, shixun_identifier: identifier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
render_ok
|
|
|
|
|
def calculate_stage_score
|
|
|
|
|
if current_stage.max_end_time && current_stage.max_end_time < Time.now
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
render_error("#{current_stage.name}还未结束")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_stage_section
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
section = current_stage.competition_stage_sections.find_by!(id: params[:section_id])
|
|
|
|
|
if section.present?
|
|
|
|
|
section_entries = section.competition_entries
|
|
|
|
|
if !params[:shixun_identifiers]
|
|
|
|
|
section_entries.destroy_all
|
|
|
|
|
else
|
|
|
|
|
if params[:shixun_identifiers].length < section_entries.size
|
|
|
|
|
section_entries[params[:shixun_identifiers].length, section_entries.size - 1].each(&:destroy)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
params[:shixun_identifiers].each_with_index do |identifier, index|
|
|
|
|
|
entry = section_entries[index]
|
|
|
|
|
if entry.present?
|
|
|
|
|
entry.update_attributes!(shixun_identifier: identifier)
|
|
|
|
|
else
|
|
|
|
|
section.competition_entries << CompetitionEntry.new(competition_stage_id: current_stage.id, shixun_identifier: identifier)
|
|
|
|
|
end
|
|
|
|
|
def send_message
|
|
|
|
|
if current_stage.max_end_time && current_stage.max_end_time > Time.now
|
|
|
|
|
User.where(id: TeamMember.where(competition_team_id: current_competition.competition_teams.pluck(:id)).pluck(:user_id).uniq).each do |user|
|
|
|
|
|
name = current_competition.name + "#{current_competition.sub_title}(#{stage.name})"
|
|
|
|
|
begin
|
|
|
|
|
if user.phone.present?
|
|
|
|
|
Educoder::Sms.send(mobile: user.phone.to_s, code: '1', send_type:'competition_start', user_name:user.show_name,
|
|
|
|
|
name:name, result:section.start_time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
|
|
end
|
|
|
|
|
rescue => e
|
|
|
|
|
logger_error(e)
|
|
|
|
|
render_error("发送验证码出错")
|
|
|
|
|
end
|
|
|
|
|
section.update_attributes!(start_time: params[:new_start_time], end_time: params[:new_end_time],
|
|
|
|
|
entry: params[:entry], mission_count: params[:mission_count], score_source: params[:score_source])
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
render_error("#{current_stage.name}已结束")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy_stage_section
|
|
|
|
|
section = current_stage.competition_stage_sections.find_by!(id: params[:section_id])
|
|
|
|
|
section.destroy!
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def calculate_stage_score
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def current_competition
|
|
|
|
|