diff --git a/app/controllers/admins/competition_stages_controller.rb b/app/controllers/admins/competition_stages_controller.rb index 49eabe8c8..b02d5ae8c 100644 --- a/app/controllers/admins/competition_stages_controller.rb +++ b/app/controllers/admins/competition_stages_controller.rb @@ -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 diff --git a/app/controllers/admins/competitions_controller.rb b/app/controllers/admins/competitions_controller.rb index 2e2dbd4e2..ee563be1f 100644 --- a/app/controllers/admins/competitions_controller.rb +++ b/app/controllers/admins/competitions_controller.rb @@ -1,11 +1,10 @@ class Admins::CompetitionsController < Admins::BaseController - include CustomSortable before_action :find_competition, except: [:index] def index - params[:sort_by] = params[:sort_by].presence || 'created_on' - params[:sort_direction] = params[:sort_direction].presence || 'desc' - @competitions = custom_sort Competition.all, params[:sort_by], params[:sort_direction] + # params[:sort_by] = params[:sort_by].presence || 'created_at' + # params[:sort_direction] = params[:sort_direction].presence || 'desc' + @competitions = Competition.all.order("created_at desc") @params_page = params[:page] || 1 @competitions = paginate @competitions ids = @competitions.map(&:id) diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb index 3ffd4a813..6d28d6a16 100644 --- a/app/controllers/competitions/competition_teams_controller.rb +++ b/app/controllers/competitions/competition_teams_controller.rb @@ -116,13 +116,13 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController keyword = params[:keyword].to_s.strip if keyword.present? - teams = teams.joins(users: { user_extension: :school }) + teams = teams.joins(user: { user_extension: :school }) .where('competition_teams.name LIKE :keyword OR schools.name LIKE :keyword', keyword: "%#{keyword}%") end @all_count = teams.count @all_teams = paginate(teams.includes(:user, users: { user_extension: :school })) - @all_member_count = current_competition.team_members.count + @all_member_count = teams.joins(:team_members).count end def user_competition_teams diff --git a/app/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb index 2509dea13..392d539ab 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -347,8 +347,14 @@ %