Merge branch 'dev_trainings' into develop

dev_bj
p31729568 6 years ago
commit efe1991773

@ -13,16 +13,6 @@ class TrainingsController < ApplicationController
before_filter :check_training_type, only: [:enroll] before_filter :check_training_type, only: [:enroll]
before_filter :check_current_training, only: [:show, :update, :pay, :pay_js, :update_payinfo, :result] before_filter :check_current_training, only: [:show, :update, :pay, :pay_js, :update_payinfo, :result]
# TODO: 测试完成后删除
ALLOW_OPENID_LIST = [
'oSrqE52fgGMooW3B1K4mZ0Le5G9I'
]
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' layout 'base_trainings'
def show def show
@ -33,18 +23,22 @@ class TrainingsController < ApplicationController
return return
end end
# TODO: 测试完成后删除
@test_wxpay = ALLOW_OPENID_LIST.include?(session[:wechat_open_id])
render 'trainingsInfo' render 'trainingsInfo'
end end
def enroll def enroll
@training = current_training || Training.new @training = current_training || Training.new
if @training.training_payinfo.present? && params[:disable_redirect].blank? if params[:disable_redirect].blank?
redirect_to result_training_path(id: friendly_id) if @training.training_payinfo.present?
return redirect_to result_training_path(id: friendly_id)
return
end
unless @training.new_record?
redirect_to training_path(id: friendly_id)
return
end
end end
end end
@ -56,9 +50,6 @@ class TrainingsController < ApplicationController
@training.training_payinfo.fee = @training.registration_fee @training.training_payinfo.fee = @training.registration_fee
@training.training_payinfo.pay_type = params[:pay_type].presence || 3 @training.training_payinfo.pay_type = params[:pay_type].presence || 3
end end
# TODO: 测试完成后删除
@test_wxpay = ALLOW_OPENID_LIST.include?(session[:wechat_open_id])
end end
def pay_callback def pay_callback
@ -164,13 +155,8 @@ class TrainingsController < ApplicationController
training_info.save! training_info.save!
# TODO: 测试完成后删除
@test_wxpay = ALLOW_OPENID_LIST.include?(session[:wechat_open_id])
if params[:js] == 'true' && training_info.not_payed? 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 else
redirect_to result_training_path(id: friendly_id) redirect_to result_training_path(id: friendly_id)
end end
@ -199,6 +185,7 @@ class TrainingsController < ApplicationController
#js获取支付参数 #js获取支付参数
def _pay_js(fee) def _pay_js(fee)
Rails.logger.info("### start wechat pay => fee: #{fee}")
@training = current_training @training = current_training
js_function_call do js_function_call do
out_trade_no = Wechat.pay.gen_trade_no out_trade_no = Wechat.pay.gen_trade_no

@ -38,7 +38,7 @@ class Training < ActiveRecord::Base
# 三人以上 8折 # 三人以上 8折
num >= 3 ? 3000.0 * 0.8 * num : 3000.0 * num num >= 3 ? 3000.0 * 0.8 * num : 3000.0 * num
when 4 then when 4 then
1200.0 * num 700.0 * num
else else
raise ArgumentError raise ArgumentError
end end

@ -2,18 +2,10 @@
<div style="padding-top: 10px"> <div style="padding-top: 10px">
<%= hidden_field_tag(:friendly_id, @friendly_id) %> <%= hidden_field_tag(:friendly_id, @friendly_id) %>
<% if @test_wxpay %> <div class="showPanel" id="payTypeLine" <%= @training.training_payinfo.not_payed? ? 'NavShow' : '' %>>
<div class="showPanel" id="payTypeLine" NavShow>
<% else %>
<div class="showPanel" id="payTypeLine">
<% end %>
<p class="clearfix pr"> <p class="clearfix pr">
<label>支付方式</label> <label>支付方式</label>
<% if @test_wxpay %> <span class="mr5" style="margin-right: 24px;" id="payTypeName"><%= @training.training_payinfo.pay_type.to_i == 3 ? "线下支付" : "微信支付" %></span>
<span class="mr5" style="margin-right: 24px;" id="payTypeName"><%= @training.training_payinfo.pay_type.to_i == 3 ? "线下支付" : "微信支付" %></span>
<% else %>
<span class="mr5" style="margin-right: 24px;">线下支付</span>
<% end %>
<i class="iconfont icon-gengduo1 rightArrow" style="color: #323232;right: 4px"></i> <i class="iconfont icon-gengduo1 rightArrow" style="color: #323232;right: 4px"></i>
</p> </p>
<div class="<%= @training.training_payinfo.pay_type.to_i == 3 ? "" : "none" %> mt5" id="payInfos"> <div class="<%= @training.training_payinfo.pay_type.to_i == 3 ? "" : "none" %> mt5" id="payInfos">
@ -107,7 +99,11 @@
<div class="bottomBtn <%= @training.training_payinfo.pay_type.to_i == 1 ? "" : "none" %>" id="paySubmitBtn"> <div class="bottomBtn <%= @training.training_payinfo.pay_type.to_i == 1 ? "" : "none" %>" id="paySubmitBtn">
<a href="<%= training_path(id: @friendly_id, disable_redirect: true) %>" class="leftbtn">返回</a> <a href="<%= training_path(id: @friendly_id, disable_redirect: true) %>" class="leftbtn">返回</a>
<a href="javascript:void(0)" class="rightbtn" id="payBtn">立即支付</a> <% if @training.training_payinfo.not_payed? %>
<a href="javascript:void(0)" class="rightbtn" id="payBtn">立即支付</a>
<% else %>
<a href="javascript:void(0)" class="rightbtn" id="submitWxpayFormBtn">提交</a>
<% end %>
</div> </div>
</div> </div>
@ -266,6 +262,12 @@
$('form').submit(); $('form').submit();
}); });
// 微信支付后修改内容提交
$("#submitWxpayFormBtn").on('click', function () {
if(!checkBillInfo()){ return; }
$('form').submit();
});
//上传头像 //上传头像
InitPhoto(); InitPhoto();

@ -121,7 +121,7 @@
// eruda.init(); // eruda.init();
function wechatPay() { function wechatPay() {
$.ajax({ $.ajax({
url: '<%= pay_js_trainings_path %>', url: '<%= pay_js_trainings_path(friendly_id: @friendly_id) %>',
type: "POST", type: "POST",
data: '{}' data: '{}'
} }
@ -147,7 +147,7 @@
// 使用以上方式判断前端返回,微信团队郑重提示: // 使用以上方式判断前端返回,微信团队郑重提示:
//res.err_msg将在用户支付成功后返回ok但并不保证它绝对可靠。 //res.err_msg将在用户支付成功后返回ok但并不保证它绝对可靠。
setTimeout(function () { setTimeout(function () {
window.location.href = "/trainings/<% @tag_id %>/result"; window.location.href = "/trainings/<% @friendly_id %>/result";
}, 500); }, 500);
} else if (res.err_msg == 'get_brand_wcpay_request:cancel') { } else if (res.err_msg == 'get_brand_wcpay_request:cancel') {
@ -189,7 +189,7 @@
var data = new FormData(); var data = new FormData();
data.append('image', files[0]); data.append('image', files[0]);
data.append('tag_id', '<%= @tag_id %>'); data.append('friendly_id', '<%= @friendly_id %>');
$.ajax({ $.ajax({
url: '<%= update_picture_trainings_path %>', url: '<%= update_picture_trainings_path %>',

@ -41,12 +41,7 @@
<% if @training.training_payinfo.blank? || @training.training_payinfo.not_payed? %> <% if @training.training_payinfo.blank? || @training.training_payinfo.not_payed? %>
<div class="bottomBtn"> <div class="bottomBtn">
<%= link_to '转账支付', pay_training_path(id: @friendly_id, pay_type: 3), class: 'leftbtn' %> <%= link_to '转账支付', pay_training_path(id: @friendly_id, pay_type: 3), class: 'leftbtn' %>
<!-- TODO:: 测试微信支付,待删除 --> <%= 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 %>
<a href="javascript:void(0)" onclick="alert('即将开通');" class="rightbtn">微信支付</a>
<% end %>
</div> </div>
<% else %> <% else %>
<div class="bottomBtn"> <div class="bottomBtn">

Loading…
Cancel
Save