From 7ceca2da755d6905928b6df3acde693c69ded1f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Fri, 25 Oct 2019 21:50:03 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=AB=9E=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/competition/Registration.js | 58 +++++++++++++++---- public/react/src/modules/tpm/TPMIndexHOC.js | 2 + 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/public/react/src/modules/competition/Registration.js b/public/react/src/modules/competition/Registration.js index 758feddb8..6e14ab1d6 100644 --- a/public/react/src/modules/competition/Registration.js +++ b/public/react/src/modules/competition/Registration.js @@ -88,6 +88,7 @@ class Registration extends React.Component { // this.Getdata(keyword, page, per_page, this.props.isAdmin()); // this.GetenrollmentAPI(); } + //取模式 this.Getdataheader(); } @@ -100,6 +101,7 @@ class Registration extends React.Component { ////console.log(this.props.user.admin); const {keyword, page, per_page} = this.state; this.Getdata(keyword, page, per_page, this.props.user.admin); + //取报名配置 this.GetenrollmentAPI(); } @@ -144,6 +146,7 @@ class Registration extends React.Component { }) try { + //获取学生是否被限制多次报名 if (result.data.member_staff) { this.setState({ mutiple_limited: result.data.member_staff.mutiple_limited, @@ -157,6 +160,7 @@ class Registration extends React.Component { } try { + //获取老师是否被限制多次报名 if (result.data.teacher_staff) { this.setState({ teamutiple_limited: result.data.teacher_staff.mutiple_limited @@ -167,6 +171,7 @@ class Registration extends React.Component { } + //是否是个人赛做处理 if (result.data.personal === true) { if (result.data.enroll_ended === true) { this.setState({ @@ -211,15 +216,28 @@ class Registration extends React.Component { // 没有创建数据的 if (admin === true) { //管理员 - this.setState({ - type: 4, - count: result.data.count, - data: result.data.my_teams, - competition_teams: result.data.competition_teams, - personal: result.data.personal, - competition_name: result.data.competition_name, - members_count: result.data.members_count - }) + try { + this.setState({ + type: result.data.competition_teams.length === 0 ? 1 : 4, + count: result.data.count, + data: result.data.my_teams, + competition_teams: result.data.competition_teams, + personal: result.data.personal, + competition_name: result.data.competition_name, + members_count: result.data.members_count + }) + } catch (e) { + this.setState({ + type: 4, + count: result.data.count, + data: result.data.my_teams, + competition_teams: result.data.competition_teams, + personal: result.data.personal, + competition_name: result.data.competition_name, + members_count: result.data.members_count + }) + } + } else { //普通账号 this.setState({ @@ -463,6 +481,17 @@ class Registration extends React.Component { * 加入战队 * */ Jointheteam = () => { + if (this.props.checkIfLogin() === false) { + this.props.showLoginDialog() + return + } + if (this.props.checkIfProfileCompleted() === false) { + this.props.showProfileCompleteDialog() + return + } + + + if (this.props.user.is_teacher === true) { try { if (this.state.teamutiple_limited === true) { @@ -544,7 +573,16 @@ class Registration extends React.Component { * 创建战队 **/ Createateam = () => { - // + if (this.props.checkIfLogin() === false) { + this.props.showLoginDialog() + return + } + if (this.props.checkIfProfileCompleted() === false) { + this.props.showProfileCompleteDialog() + return + } + + if (this.props.user.is_teacher === true) { try { diff --git a/public/react/src/modules/tpm/TPMIndexHOC.js b/public/react/src/modules/tpm/TPMIndexHOC.js index 3ee678a9a..ee42ace21 100644 --- a/public/react/src/modules/tpm/TPMIndexHOC.js +++ b/public/react/src/modules/tpm/TPMIndexHOC.js @@ -516,6 +516,7 @@ export function TPMIndexHOC(WrappedComponent) { isloginCancel:"iscancel" }) } + //验证登录是否成功方法 checkIfLogin = () => { return this.state.current_user && this.state.current_user.login != '' } @@ -531,6 +532,7 @@ export function TPMIndexHOC(WrappedComponent) { AccountProfiletype: true }) } + //验证是否完善资料 checkIfProfileCompleted = () => { return this.state.current_user && this.state.current_user.profile_completed } From 79f1ac92c409a0abe42d8bc6e77f6e15bc6e1d4b Mon Sep 17 00:00:00 2001 From: p31729568 <winse.wang@foxmail.com> Date: Sat, 26 Oct 2019 08:46:17 +0800 Subject: [PATCH 2/5] competition: team search api --- app/controllers/competitions/competition_teams_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 9a8d63cbecd58cde5ef57fea416f754f2f62bbcb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 26 Oct 2019 09:01:32 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/competition_stages_controller.rb | 61 ++++++------------- .../admins/competitions_controller.rb | 7 +-- .../competition_settings/index.html.erb | 10 ++- config/routes.rb | 7 +-- 4 files changed, 32 insertions(+), 53 deletions(-) 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/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb index f2ed61622..3813641f7 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -347,8 +347,14 @@ </div><span class=" mt-2">%</span> <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">发送短信提醒</a> - <a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">计算成绩</a> + <% if stage.max_end_time > Time.now %> + <%= 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> <%= 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> diff --git a/config/routes.rb b/config/routes.rb index 10bcb0f74..43ec58fba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1034,10 +1034,9 @@ Rails.application.routes.draw do end resources :competition_stages, only: [:create, :update, :destroy] do - collection do - post :create_stage_section - post :update_stage_section - delete :destroy_stage_section + member do + post :send_message + post :calculate_stage_score end end end From 057f7fe2a83476dcdc3819b9580bb5b2dce4744b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Sat, 26 Oct 2019 09:03:29 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=AB=9E=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react/src/modules/competition/Registration.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/public/react/src/modules/competition/Registration.js b/public/react/src/modules/competition/Registration.js index 6e14ab1d6..f66a89662 100644 --- a/public/react/src/modules/competition/Registration.js +++ b/public/react/src/modules/competition/Registration.js @@ -485,11 +485,6 @@ class Registration extends React.Component { this.props.showLoginDialog() return } - if (this.props.checkIfProfileCompleted() === false) { - this.props.showProfileCompleteDialog() - return - } - if (this.props.user.is_teacher === true) { @@ -577,10 +572,6 @@ class Registration extends React.Component { this.props.showLoginDialog() return } - if (this.props.checkIfProfileCompleted() === false) { - this.props.showProfileCompleteDialog() - return - } @@ -772,6 +763,12 @@ class Registration extends React.Component { // /competitions/:identifier/competition_teams.json Personalregistration = () => { let {teacher_staff, member_staff, data, enroll_ended, enrolled} = this.state; + + if (this.props.checkIfLogin() === false) { + this.props.showLoginDialog(); + return + } + if (enroll_ended === true) { //已截止 this.props.showNotification(`报名已截止`); From e89761a3e1f28a94e37bb512667b67e87c8c0103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Sat, 26 Oct 2019 09:25:34 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E7=AB=9E=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/competition/competmodal/PersonalModalteam.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/public/react/src/modules/competition/competmodal/PersonalModalteam.js b/public/react/src/modules/competition/competmodal/PersonalModalteam.js index c077e1829..a1be91217 100644 --- a/public/react/src/modules/competition/competmodal/PersonalModalteam.js +++ b/public/react/src/modules/competition/competmodal/PersonalModalteam.js @@ -39,6 +39,15 @@ class PersonalModalteam extends Component { }).then((result) => { if (result) { if (result.data) { + try { + if (result.data.status === 0) { + this.props.showNotification(`报名成功,预祝您夺得桂冠`); + } + } catch (e) { + + } + + this.props.Tmoconfirm(true) } }