diff --git a/app/controllers/trainings_controller.rb b/app/controllers/trainings_controller.rb index 948d97be..2a9ed1c2 100644 --- a/app/controllers/trainings_controller.rb +++ b/app/controllers/trainings_controller.rb @@ -4,68 +4,38 @@ class TrainingsController < ApplicationController wechat_responder skip_before_filter :check_if_login_required - skip_before_filter :verify_signature, only: [:show, :create, :update, :test, :enroll] + skip_before_filter :verify_signature, except: [:auth, :auth_callback, :pay_callback] ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}" before_filter :authenticate, except: [:auth, :auth_callback, :pay_callback] - before_filter :find_tag_id, except: [:auth, :auth_callback, :pay_callback] - - before_filter :find_training, only: [:show, :test] - - before_filter :valid_training, only: [:pay, :result, :pay_js] + before_filter :check_training_type, only: [:enroll] + before_filter :check_current_training, only: [:show, :update, :pay, :pay_js, :update_payinfo, :result] layout 'base_trainings' - - # TAG_ID = 'bigdata_hnjcxy_2019' - def show @training = current_training - - url = nil - if @training && !@training.pay? - url = enroll_training_path(id: @tag_id) - elsif @training && @training.pay? - url = result_training_path(id: @tag_id) - else - url = enroll_training_path(id: @tag_id) - end - - redirect_to url end def enroll @training = current_training || Training.new - - if @training && @training.pay? - redirect_to result_training_path(id: @tag_id) - return - end - - Rails.logger.info("##########training_type:#{@training_type}") - @training_title = @training_type == 3 ? "信息技术新工科产学研联盟师资培训班" : "工程教育认证" - Rails.logger.info("##########training_title:#{@training_title}") end def pay @training = current_training - if @training.blank? - redirect_to enroll_training_path(id: @tag_id) - return - end - # 防止重复支付,对于已支付过的,不应该再到这个页来 if @training.payed? - redirect_to result_training_path(id: @tag_id) + redirect_to result_training_path(id: friendly_id) return end if @training.training_payinfo.blank? @training.build_training_payinfo @training.training_payinfo.fee = @training.registration_fee + @training.training_payinfo.pay_type = params[:pay_type].presence || 3 end end @@ -113,36 +83,24 @@ class TrainingsController < ApplicationController end def create - @training = current_training || Training.new(params) + @training = Training.new @training.training_type = @training_type - if @training_type == 3 - @training.research_field = params[:research_field].select(&:present?).uniq.join(",") - end @training.openid = session[:wechat_open_id] - @training.save! - flash[:message] = '提交成功' + save_training - redirect_to pay_training_path(id: @tag_id) - end + flash[:message] = '报名成功' + redirect_to training_path(id: friendly_id) + end def update @training = current_training - if @training.blank? - redirect_to enroll_training_path(id: @tag_id) - return - end + save_training - @training.assign_attributes(params) - if @training.training_type == 3 - @training.research_field = params[:research_field].select(&:present?).uniq.join(",") - end - @training.save! - - flash[:message] = '提交成功' + flash[:message] = '保存成功' - redirect_to pay_training_path(id: @tag_id) + redirect_to training_path(id: friendly_id) end @@ -152,48 +110,45 @@ class TrainingsController < ApplicationController # 采用ajax调用方式,返回支付参数 def update_payinfo @training = current_training - if @training.blank? - redirect_to enroll_training_path(id: @tag_id) - return - end + training_info = @training.training_payinfo || @training.build_training_payinfo + training_info.assign_attributes(params) - attachment = nil - if params[:image] - attachment = Attachment.create!(file: params[:image], author: User.first) + # 已支付不能修改人数 + if training_info.not_payed? + training_info.num = params[:enlistNum].to_i < 1 ? 1 : params[:enlistNum].to_i + training_info.fee = @training.registration_fee(training_info.num) end - #修改以前的订单信息 - training_info = @training.training_payinfo - if training_info.present? - training_info.update_attributes(params) - else - training_info = TrainingPayinfo.new(params) - end - - training_info.num = params[:enlistNum].to_i < 1 ? 1 : params[:enlistNum].to_i + ActiveRecord::Base.transaction do + if training_info.pay_type.to_i == TrainingPayinfo::PayType_bank + attachment = nil + attachment = Attachment.create!(file: params[:image], author: User.first) if params[:image] - training_info.fee = @training.registration_fee(training_info.num) - - training_info.attachment = attachment if attachment.present? + if attachment.blank? + flash[:message] = '请先上传支付凭证' + render 'pay' + return + end - if training_info.pay_type.to_i == TrainingPayinfo::PayType_Wechat - training_info.status = TrainingPayinfo::Status_None - elsif params[:offline_later_pay].to_s == 'true' - # 线下支付-稍后支付 - training_info.status = TrainingPayinfo::Status_None - else - training_info.status = TrainingPayinfo::Status_Wait - end + training_info.attachment = attachment + end - training_info.training_id = @training.id + if training_info.not_payed? + if training_info.pay_type.to_i == TrainingPayinfo::PayType_Wechat + training_info.status = TrainingPayinfo::Status_None + else + training_info.status = TrainingPayinfo::Status_Wait + end + end - training_info.save! + training_info.save! - if params[:js] == 'true' - Rails.logger.info("### start wechat pay => fee: #{training_info.fee}") - _pay_js(0.01 || training_info.fee) - else - redirect_to url = result_training_path(id: @tag_id) + if params[:js] == 'true' + Rails.logger.info("### start wechat pay => fee: #{training_info.fee}") + _pay_js(training_info.fee) + else + redirect_to result_training_path(id: friendly_id) + end end end @@ -268,29 +223,54 @@ class TrainingsController < ApplicationController end end - def find_tag_id - @tag_id = params[:tag_id] || params[:id] - Rails.logger.info("##########TAG_ID:#{@tag_id}") - @training_type = @tag_id == "aeee0601_2019" ? 3 : @tag_id == "ceeaa06_2019" ? 4 : 0 - render_404 if @training_type == 0 - end + def save_training + @training.assign_attributes(params) + @training.training_type = training_type - def find_training - if params[:id] == @tag_id - @training = current_training - else - render_404 + if @training.training_type == 3 + @training.research_field = params[:research_field].select(&:present?).uniq.join(",") end + + @training.save! + end + + def friendly_id + @friendly_id ||= params[:friendly_id].presence || params[:id] + end + + def training_type + @training_type ||= + case friendly_id + when 'aeee0601_2019' then 3 + when 'ceeaa06_2019' then 4 + end end def current_training - Rails.logger.info("##########openid:#{session[:wechat_open_id]}, training_type: #{@training_type}") - @_current_training ||= Training.where(openid: session[:wechat_open_id], training_type: @training_type).first + @_current_training ||= begin + Rails.logger.info("##########openid:#{session[:wechat_open_id]}, friendly_id: #{friendly_id}") + + return if training_type.blank? + + Training.where(openid: session[:wechat_open_id], training_type: training_type).first + end + end + + def check_training_type + return if training_type.present? + + render_404 end - def valid_training - unless current_training - redirect_to training_path(id: @tag_id) + def check_current_training + if current_training.blank? + if training_type.blank? + render_404 + return + end + + redirect_to enroll_training_path(id: friendly_id) + return end end diff --git a/app/models/training_payinfo.rb b/app/models/training_payinfo.rb index 71f1c793..fbb7e9dc 100644 --- a/app/models/training_payinfo.rb +++ b/app/models/training_payinfo.rb @@ -42,6 +42,9 @@ class TrainingPayinfo < ActiveRecord::Base pay_type.to_i == PayType_Wechat && status != Status_Payed end + def not_payed? + status.nil? || status == Status_None + end def payed? status == Status_Payed diff --git a/app/views/layouts/base_trainings.html.erb b/app/views/layouts/base_trainings.html.erb index 4f7f4774..51115cb1 100644 --- a/app/views/layouts/base_trainings.html.erb +++ b/app/views/layouts/base_trainings.html.erb @@ -2,13 +2,16 @@ - <%= if params[:controller] == "trainings" && params[:action] == "enroll" - "报名" - elsif params[:controller] == "trainings" && params[:action] == "pay" - "费用支付" - elsif params[:controller] == "trainings" && params[:action] == "result" - "支付状态" - end %> + + <%= + case "#{params[:controller]}-#{params[:action]}" + when 'trainings-show' then '报名信息' + when 'trainings-enroll' then '报名' + when 'trainings-pay' then '费用支付和发票信息' + when 'trainings-result' then '支付信息' + end + %> + diff --git a/app/views/trainings/_upload_img.html.erb b/app/views/trainings/_upload_img.html.erb index 3b7ae82d..7eebaffe 100644 --- a/app/views/trainings/_upload_img.html.erb +++ b/app/views/trainings/_upload_img.html.erb @@ -1,3 +1,4 @@ +<% disabled ||= false %>
" style="padding-bottom: 10px;">
<% if training.training_payinfo.attachment_url.present? %> @@ -6,8 +7,10 @@ <% else %>
  • <% end %> -
    - -
    + <% unless disabled %> +
    + +
    + <% end %>
    \ No newline at end of file diff --git a/app/views/trainings/enroll.html.erb b/app/views/trainings/enroll.html.erb index 84a88510..f5ee6867 100644 --- a/app/views/trainings/enroll.html.erb +++ b/app/views/trainings/enroll.html.erb @@ -124,9 +124,9 @@ <% end %>
    -

    <%= @training_title %>

    +

    <%= @training_type == 3 ? '信息技术新工科产学研联盟师资培训班' : '工程教育认证' %>

    <%= form_for @training do |f| %> - <%= hidden_field_tag(:tag_id, @tag_id) %> + <%= hidden_field_tag(:friendly_id, @friendly_id) %>

    基本信息

  • @@ -187,7 +187,7 @@

    - 提交 + <%= @training.new_record? ? '我要报名' : '保存' %> <% end %>
  • @@ -211,11 +211,6 @@ $('#sex').val("2"); } }); - - var message = "<%= flash[:message] %>"; - if (message && message.length > 0) { - alert(message); - } }) //下一步 diff --git a/app/views/trainings/pay.html.erb b/app/views/trainings/pay.html.erb index 2c384e27..4cebcc83 100644 --- a/app/views/trainings/pay.html.erb +++ b/app/views/trainings/pay.html.erb @@ -1,17 +1,15 @@
    - <%= hidden_field_tag(:tag_id, params[:id]) %> - <%= hidden_field_tag(:offline_later_pay, 'false') %> + <%= hidden_field_tag(:friendly_id, @friendly_id) %>
    -

    - + + - 线下支付 - -

    -

    微信支付将于6月18日开通

    + + +
    @@ -34,7 +32,7 @@
    -

    完成线下支付后,请将支付截图粘贴到备注中,以便财务审核

    +

    完成银行转账后,请上传转账凭证,由会务组审核

    @@ -46,12 +44,13 @@

    发票内容 + value="<%= @training.training_payinfo.try(:invoice_content).presence || '会议注册费' %>"/>

    备注

    - + +

    上传转账凭证

    <%= render :partial => 'upload_img', :locals => {:training => @training} %>
    @@ -61,7 +60,7 @@ (3人及以上8折优惠) <% end %>

    -

    含会议注册费、场地费、培训费、教材资料费、餐费、专家差旅费等

    +

    含会务费、培训费、教材资料费、餐费、专家差旅费等

    @@ -80,12 +79,12 @@

    " id="offlinePaySubmitBtn"> - 稍后支付 - 立即支付 + 返回 + 完成转账
    " id="paySubmitBtn"> - 返回 + 返回 立即支付
    @@ -234,13 +233,13 @@ //线下支付提交 $('#submitFormBtn').on('click', function () { - if(!checkBillInfo()){ return } - $('form').submit(); - }); - $('#laterSubmitFormBtn').on('click', function () { - if(!checkBillInfo()){ return } + if(!checkBillInfo()){ return; } - $('#offline_later_pay').val('true'); + var image = $("input[name='image']").val() + if (!image || image.length < 0) { + alert('请先上传支付凭证'); + return; + } $('form').submit(); }); diff --git a/app/views/trainings/result.html.erb b/app/views/trainings/result.html.erb index ca1228b3..c397ce31 100644 --- a/app/views/trainings/result.html.erb +++ b/app/views/trainings/result.html.erb @@ -86,35 +86,28 @@
    -

    -

    <%= @training.training_payinfo.info %>

    + <% if @training.training_payinfo.info.present? %> +

    +

    <%= @training.training_payinfo.info %>

    + <% end %> <% if @training.training_payinfo.attachment_id.to_i > 0 || @training.training_payinfo.pay_type != TrainingPayinfo::PayType_Wechat %> +

    - <%= render :partial => 'upload_img', :locals => {:training => @training} %> + <%= render partial: 'upload_img', locals: { training: @training, disabled: true } %> <% end %> -


    - - - <% if @training.payed? %> - 完成 - <% else %> - <% if @training.training_payinfo.wechat_wait_pay? %> -
    - <%= link_to "返回", pay_training_path(id: @tag_id), class: 'leftbtn' %> - 立即支付 -
    - <% elsif !@training.payed? %> - <%= link_to "返回", pay_training_path(id: @tag_id), class: 'returnBtn' %> - <% end %> - <% end %> + +
    + <% if @training.training_payinfo.wechat_wait_pay? %> + <%= link_to "返回", training_path(id: @friendly_id), class: 'leftbtn' %> + 立即支付 + <% else%> + <%= link_to "返回", pay_training_path(id: @friendly_id), class: 'rightbtn', style: 'width: 100%' %> + <% end %> +
    diff --git a/public/stylesheets/educoder/trainings.css b/public/stylesheets/educoder/trainings.css index 44df1617..91e3e4a9 100644 --- a/public/stylesheets/educoder/trainings.css +++ b/public/stylesheets/educoder/trainings.css @@ -175,7 +175,7 @@ input[type='text'].right_input{ float: right;color: #333; } .bottomBtn{ - position: fixed;bottom: 0px;left: 0px;width: 100%;height: 44px;line-height: 44px;font-size: 1.6rem;text-align: center; + position: fixed;bottom: 0px;left: 0px;width: 100%;height: 44px;line-height: 44px;font-size: 1.6rem;text-align: center;z-index: 20; } .bottomBtn .leftbtn{ width: 50%;float: left;background-color: #fff;color: #676767; @@ -203,7 +203,7 @@ input[type='text'].right_input{ line-height: 20px;margin-top: 3px; } .remarkAccount{ - width: 100%;resize: none;height: 80px;margin-bottom:14px;border: 1px solid #eee;padding: 5px;box-sizing: border-box; + width: 100%;resize: none;height: 80px;border: 1px solid #eee;padding: 5px;box-sizing: border-box; } .moneyDetail{ line-height: 20px;color: #4B4B4B;