From 15e50f3ee3f472afdcfd3a856f734d3ae76975d7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 13 Jun 2019 09:53:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/trainings_controller.rb | 43 ++- app/models/training.rb | 2 +- app/views/trainings/enroll.html.erb | 264 +++++++++--------- ...13013623_add_reseach_field_to_trainings.rb | 5 + 4 files changed, 168 insertions(+), 146 deletions(-) create mode 100644 db/migrate/20190613013623_add_reseach_field_to_trainings.rb diff --git a/app/controllers/trainings_controller.rb b/app/controllers/trainings_controller.rb index cfab83cb..e3a429b7 100644 --- a/app/controllers/trainings_controller.rb +++ b/app/controllers/trainings_controller.rb @@ -8,6 +8,9 @@ class TrainingsController < ApplicationController # ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}" # # before_filter :authenticate, except: [:auth, :auth_callback, :pay_callback] + # + before_filter :find_tag_id + before_filter :find_training, only: [:show, :test] before_filter :valid_training, only: [:pay, :result, :pay_js] @@ -15,18 +18,18 @@ class TrainingsController < ApplicationController layout 'base_trainings' - TAG_ID = 'bigdata_hnjcxy_2019' + # TAG_ID = 'bigdata_hnjcxy_2019' def show @training = current_training url = nil if @training && !@training.pay? - url = enroll_training_path(id: TAG_ID) + url = enroll_training_path(id: @tag_id) elsif @training && @training.pay? - url = result_training_path(id: TAG_ID) + url = result_training_path(id: @tag_id) else - url = enroll_training_path(id: TAG_ID) + url = enroll_training_path(id: @tag_id) end redirect_to url @@ -45,7 +48,7 @@ class TrainingsController < ApplicationController # 防止重复支付,对于已支付过的,不应该再到这个页来 if @training.payed? - redirect_to result_training_path(id: TAG_ID) + redirect_to result_training_path(id: @tag_id) return end @@ -100,11 +103,15 @@ class TrainingsController < ApplicationController def create @training = current_training || Training.new(params) - @training.training_type = Training::Training_Type + @training.training_type = @training_type + if @training_type == 3 + @training.research_field = params[:research_field].reject(&:blank?).uniq.join(",") + end @training.openid = session[:wechat_open_id] @training.save! - redirect_to pay_training_path(id: TAG_ID) + redirect_to enroll_training_path(id: @tag_id) + # redirect_to pay_training_path(id: @tag_id) end @@ -116,7 +123,7 @@ class TrainingsController < ApplicationController end @training.update_attributes(params) - redirect_to pay_training_path(id: TAG_ID) + redirect_to pay_training_path(id: @tag_id) end @@ -168,7 +175,7 @@ class TrainingsController < ApplicationController if params[:js] == 'true' _pay_js(training_info.fee) else - redirect_to url = result_training_path(id: TAG_ID) + redirect_to url = result_training_path(id: @tag_id) end end @@ -232,11 +239,11 @@ class TrainingsController < ApplicationController url = '' if !@training - url = training_path(id: TAG_ID) + url = training_path(id: @tag_id) elsif !@training.pay? - url = enroll_training_path(id: TAG_ID) + url = enroll_training_path(id: @tag_id) else - url = result_training_path(id: TAG_ID) + url = result_training_path(id: @tag_id) end redirect_to url @@ -262,8 +269,14 @@ class TrainingsController < ApplicationController end end + def find_tag_id + @tag_id = params[:id] + @training_type = @tag_id == "aeee0601_2019" ? 3 : @tag_id == "ceeaa06_2019" ? 4 : 0 + render_404 if @training_type == 0 + end + def find_training - if params[:id] == TAG_ID + if params[:id] == @tag_id @training = current_training else render_404 @@ -271,12 +284,12 @@ class TrainingsController < ApplicationController end def current_training - Training.where(openid: session[:wechat_open_id], training_type: Training::Training_Type).first + Training.where(openid: session[:wechat_open_id], training_type: @training_type).first end def valid_training unless current_training - redirect_to training_path(id: TAG_ID) + redirect_to training_path(id: @tag_id) end end diff --git a/app/models/training.rb b/app/models/training.rb index 4c1f182e..a5794de2 100644 --- a/app/models/training.rb +++ b/app/models/training.rb @@ -3,7 +3,7 @@ class Training < ActiveRecord::Base attr_accessible :address, :email, :name, :phone, :position, :school, :sex, :openid, :training_type, :major, :student_id - # training_type 1 2018-培训会 2 警察学院大数据培训会 + # training_type 1 2018-培训会 2 警察学院大数据培训会 3 大数据和人工智能 4 工程教育认证 has_one :training_payinfo diff --git a/app/views/trainings/enroll.html.erb b/app/views/trainings/enroll.html.erb index fc9e7234..149de110 100644 --- a/app/views/trainings/enroll.html.erb +++ b/app/views/trainings/enroll.html.erb @@ -1,19 +1,19 @@ <% if false %> -
-

湖南警察学院大数据培训缴费

- <%= form_for @training do |f| %> -

基本信息

-
  • - 姓名 - -
  • -
  • - 性别 - - - -
  • +
    +

    湖南警察学院大数据培训缴费

    + <%= form_for @training do |f| %> +

    基本信息

    +
  • + 姓名 + +
  • +
  • + 性别 + + + +
  • 专业
  • - - - -
  • - 手机号码 - -
  • - -

    - 下一步 - <% end %> -
    +

    + 下一步 + <% end %> +
    -
    -
  • -
  • -
    - + <% end %>

    信息技术新工科产学研联盟师资培训班

    <%= form_for @training do |f| %> -

    基本信息

    -
  • - 姓名 - -
  • -
  • - 性别 - - - -
  • -
  • - 单位 - -
  • -
  • - 职称 - -
  • +

    基本信息

    +
  • + 姓名 + +
  • +
  • + 性别 + + + +
  • +
  • + 单位 + +
  • +
  • + 职称 + +
  • + + <% if @training_type == 3 %>

    您的授课/研究领域(最少选1项)

  • 机器学习/深度学习 - +
  • 计算机结构与组成 - +
  • 计算机系统 - +
  • 计算机软件技术和应用 - +
  • 计算机理论 - +
  • 计算机应用与学科交叉 - +
  • 其他 - +
  • -

    通讯地址

    -
  • - - - - - - -
  • -
  • - 手机号码 - -
  • -
  • - Email - -
  • -

    - 完成 + <% end %> + +

    通讯地址

    +
  • + + + + + + +
  • +
  • + 手机号码 + +
  • +
  • + Email + +
  • +

    + 完成 <% end %>
    @@ -238,9 +242,9 @@ $(down).find("#sexl").html($(this).html()); hideNav(downNav); - if ($(this).html()=='男'){ + if ($(this).html() == '男') { $('#sex').val("1"); - } else { + } else { $('#sex').val("2"); } }) diff --git a/db/migrate/20190613013623_add_reseach_field_to_trainings.rb b/db/migrate/20190613013623_add_reseach_field_to_trainings.rb new file mode 100644 index 00000000..5354d13a --- /dev/null +++ b/db/migrate/20190613013623_add_reseach_field_to_trainings.rb @@ -0,0 +1,5 @@ +class AddReseachFieldToTrainings < ActiveRecord::Migration + def change + add_column :trainings, :research_field, :string + end +end