diff --git a/app/controllers/trainings_controller.rb b/app/controllers/trainings_controller.rb index 2e11eaab..c88cee80 100644 --- a/app/controllers/trainings_controller.rb +++ b/app/controllers/trainings_controller.rb @@ -13,6 +13,20 @@ class TrainingsController < ApplicationController before_filter :check_training_type, only: [:enroll] before_filter :check_current_training, only: [:show, :update, :pay, :pay_js, :update_payinfo, :result] + # TODO: 测试完成后删除 + ALLOW_OPENID_LIST = [ + 'o5fSc08-NDxC2564k9USCuiuC9cY', + 'o5fSc097mQbwhYVLK9DAIa3uz_ug', + 'o5fSc0607iR3rp4-h_VnuBTp8CiM', + 'o5fSc0-nX6bUGQNQt3FrRhUKVNIw', + 'o5fSc0607iR3rp4-h_VnuBTp8CiM' + ] + before_filter :check_openid, only: [:update_payinfo] + def check_openid + return if ALLOW_OPENID_LIST.include?(session[:wechat_open_id]) + render plain: '暂未开放' + end + layout 'base_trainings' def show @@ -23,6 +37,9 @@ class TrainingsController < ApplicationController return end + # TODO: 测试完成后删除 + @test_wxpay = ALLOW_OPENID_LIST.include?(session[:wechat_open_id]) + render 'trainingsInfo' end @@ -43,6 +60,9 @@ class TrainingsController < ApplicationController @training.training_payinfo.fee = @training.registration_fee @training.training_payinfo.pay_type = params[:pay_type].presence || 3 end + + # TODO: 测试完成后删除 + @test_wxpay = ALLOW_OPENID_LIST.include?(session[:wechat_open_id]) end def pay_callback @@ -148,9 +168,13 @@ class TrainingsController < ApplicationController training_info.save! + # TODO: 测试完成后删除 + @test_wxpay = ALLOW_OPENID_LIST.include?(session[:wechat_open_id]) + if params[:js] == 'true' && training_info.not_payed? Rails.logger.info("### start wechat pay => fee: #{training_info.fee}") - _pay_js(training_info.fee) + # TODO: 测试完成后删除 + _pay_js(@test_wxpay ? 0.01 : training_info.fee) else redirect_to result_training_path(id: friendly_id) end diff --git a/app/views/trainings/_upload_img.html.erb b/app/views/trainings/_upload_img.html.erb index 7eebaffe..7cd7056a 100644 --- a/app/views/trainings/_upload_img.html.erb +++ b/app/views/trainings/_upload_img.html.erb @@ -1,5 +1,5 @@ <% disabled ||= false %> -
" style="padding-bottom: 10px;"> +
<% if training.training_payinfo.attachment_url.present? %>
  • <%= hidden_field_tag(:friendly_id, @friendly_id) %> - + <% if @test_wxpay %> +
    + <% else %>
    - - - - - - - -
    + <% end %> +

    + + <% if @test_wxpay %> + <%= @training.training_payinfo.pay_type.to_i == 3 ? "线下支付" : "微信支付" %> + <% else %> + 线下支付 + <% end %> + +

    +
    mt5" id="payInfos">
    @@ -60,10 +65,13 @@

    备注

    +
    +
    ">

    上传转账凭证

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

    费用明细 <% if @training.training_type == 3 %> @@ -196,7 +204,7 @@ }) //立即支付 $('#payBtn').on('click', function () { - if(!checkBillInfo()){ return } + if(!checkBillInfo()){ return } var postData = $('form').serialize(); postData += '&js=true' @@ -228,7 +236,7 @@ // 使用以上方式判断前端返回,微信团队郑重提示: //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。 setTimeout(function () { - window.location.href = "/trainings/<%= @tag_id %>/result"; + window.location.href = "/trainings/<%= @friendly_id %>/result"; }, 500); } else if (res.err_msg == 'get_brand_wcpay_request:cancel') { @@ -358,14 +366,14 @@ $("#payTypeName").html($(this).html().trim()); console.log($(this).index()); if ($(this).index() == 0) { //微信支付 - $("#payInfos,#sendPhoto").addClass("none"); + $("#payInfos,.pay-image").addClass("none"); //切换显示按钮 $("#offlinePaySubmitBtn").addClass("none"); $("#paySubmitBtn").removeClass("none"); $('#pay_type').val("1"); } else { //线下支付 - $("#payInfos,#sendPhoto").removeClass("none"); + $("#payInfos,.pay-image").removeClass("none"); //切换显示按钮 $("#offlinePaySubmitBtn").removeClass("none"); $("#paySubmitBtn").addClass("none"); diff --git a/app/views/trainings/trainingsInfo.html.erb b/app/views/trainings/trainingsInfo.html.erb index 1ab35176..e71b9c07 100644 --- a/app/views/trainings/trainingsInfo.html.erb +++ b/app/views/trainings/trainingsInfo.html.erb @@ -41,8 +41,12 @@ <% if @training.training_payinfo.blank? || @training.training_payinfo.not_payed? %>

    <%= link_to '转账支付', pay_training_path(id: @friendly_id, pay_type: 3), class: 'leftbtn' %> - <%#= link_to '微信支付', pay_training_path(id: @friendly_id, pay_type: 1), class: 'rightbtn' %> - 微信支付 + + <% if @test_wxpay %> + <%= link_to '微信支付', pay_training_path(id: @friendly_id, pay_type: 1), class: 'rightbtn' %> + <% else %> + 微信支付 + <% end %>
    <% else %>
    diff --git a/public/stylesheets/educoder/trainings.css b/public/stylesheets/educoder/trainings.css index e9a73727..ad5cdcb6 100644 --- a/public/stylesheets/educoder/trainings.css +++ b/public/stylesheets/educoder/trainings.css @@ -203,7 +203,7 @@ input[type='text'].right_input{ line-height: 20px;margin-top: 3px; } .remarkAccount{ - width: 100%;resize: none;height: 80px;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;margin-bottom: 1rem; } .moneyDetail{ line-height: 20px;color: #4B4B4B;