Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_auth
杨树林 5 years ago
commit ee1514b79c

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

@ -1,11 +1,10 @@
class Admins::CompetitionsController < Admins::BaseController class Admins::CompetitionsController < Admins::BaseController
include CustomSortable
before_action :find_competition, except: [:index] before_action :find_competition, except: [:index]
def index def index
params[:sort_by] = params[:sort_by].presence || 'created_on' # params[:sort_by] = params[:sort_by].presence || 'created_at'
params[:sort_direction] = params[:sort_direction].presence || 'desc' # params[:sort_direction] = params[:sort_direction].presence || 'desc'
@competitions = custom_sort Competition.all, params[:sort_by], params[:sort_direction] @competitions = Competition.all.order("created_at desc")
@params_page = params[:page] || 1 @params_page = params[:page] || 1
@competitions = paginate @competitions @competitions = paginate @competitions
ids = @competitions.map(&:id) ids = @competitions.map(&:id)

@ -116,13 +116,13 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
keyword = params[:keyword].to_s.strip keyword = params[:keyword].to_s.strip
if keyword.present? 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}%") .where('competition_teams.name LIKE :keyword OR schools.name LIKE :keyword', keyword: "%#{keyword}%")
end end
@all_count = teams.count @all_count = teams.count
@all_teams = paginate(teams.includes(:user, users: { user_extension: :school })) @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 end
def user_competition_teams def user_competition_teams

@ -347,8 +347,14 @@
</div><span class=" mt-2">%</span> </div><span class=" mt-2">%</span>
<div class="flex-1"> <div class="flex-1">
<a href="javascript:void(0)"class="btn btn-outline-primary export-action ml20 add-task-sub">新增子阶段</a> <a href="javascript:void(0)"class="btn btn-outline-primary export-action ml20 add-task-sub">新增子阶段</a>
<a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">发送短信提醒</a> <% if stage.max_end_time > Time.now %>
<a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">计算成绩</a> <%= agree_link '发送短信提醒', send_message_admins_competition_competition_stage_path(@competition, stage, element: ".send-message-#{stage.id}"),
class: 'btn btn-outline-primary ml20', 'data-confirm': '确认执行发送短信操作?' %>
<% end %>
<% if stage.max_end_time < Time.now %>
<%= agree_link '计算成绩', calculate_stage_score_admins_competition_competition_stage_path(@competition, stage, element: ".calculate-score-#{stage.id}"),
class: 'btn btn-outline-primary ml20', 'data-confirm': '确认执行计算成绩操作?' %>
<% end %>
</div> </div>
<%= delete_link '删除', admins_competition_competition_stage_path(competition_id: @competition.id, id: stage.id), class: 'btn btn-default delete-stage ml20' %> <%= delete_link '删除', admins_competition_competition_stage_path(competition_id: @competition.id, id: stage.id), class: 'btn btn-default delete-stage ml20' %>
<a href="javascript:void(0)" class="btn btn-outline-primary export-action update-stage ml20">保存</a> <a href="javascript:void(0)" class="btn btn-outline-primary export-action update-stage ml20">保存</a>

@ -1034,10 +1034,9 @@ Rails.application.routes.draw do
end end
resources :competition_stages, only: [:create, :update, :destroy] do resources :competition_stages, only: [:create, :update, :destroy] do
collection do member do
post :create_stage_section post :send_message
post :update_stage_section post :calculate_stage_score
delete :destroy_stage_section
end end
end end
end end

Loading…
Cancel
Save