|
|
@ -13,20 +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 = [
|
|
|
|
|
|
|
|
'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'
|
|
|
|
layout 'base_trainings'
|
|
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
def show
|
|
|
@ -37,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
|
|
|
|
|
|
|
|
|
|
|
@ -60,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
|
|
|
@ -168,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
|
|
|
@ -203,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
|
|
|
|