|
|
|
@ -10,7 +10,7 @@ class TrainingsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
before_filter :authenticate, except: [:auth, :auth_callback, :pay_callback]
|
|
|
|
|
|
|
|
|
|
before_filter :find_tag_id, only: [:show, :create, :update, :enroll, :test]
|
|
|
|
|
before_filter :find_tag_id, except: [:auth, :auth_callback, :pay_callback]
|
|
|
|
|
|
|
|
|
|
before_filter :find_training, only: [:show, :test]
|
|
|
|
|
|
|
|
|
@ -44,10 +44,13 @@ class TrainingsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pay
|
|
|
|
|
_pay_params
|
|
|
|
|
|
|
|
|
|
@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)
|
|
|
|
@ -55,7 +58,6 @@ class TrainingsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@training.training_payinfo ||= TrainingPayinfo.new
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pay_callback
|
|
|
|
@ -98,11 +100,9 @@ class TrainingsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def result
|
|
|
|
|
_pay_params
|
|
|
|
|
@training = current_training
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
@training = current_training || Training.new(params)
|
|
|
|
|
@training.training_type = @training_type
|
|
|
|
@ -113,6 +113,7 @@ class TrainingsController < ApplicationController
|
|
|
|
|
@training.save!
|
|
|
|
|
|
|
|
|
|
flash[:message] = '提交成功'
|
|
|
|
|
|
|
|
|
|
redirect_to enroll_training_path(id: @tag_id)
|
|
|
|
|
# redirect_to pay_training_path(id: @tag_id)
|
|
|
|
|
end
|
|
|
|
@ -120,8 +121,8 @@ class TrainingsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
@training = current_training
|
|
|
|
|
unless @training
|
|
|
|
|
render_404
|
|
|
|
|
if @training.blank?
|
|
|
|
|
redirect_to enroll_training_path(id: @tag_id)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -132,6 +133,7 @@ class TrainingsController < ApplicationController
|
|
|
|
|
@training.save!
|
|
|
|
|
|
|
|
|
|
flash[:message] = '提交成功'
|
|
|
|
|
|
|
|
|
|
redirect_to enroll_training_path(id: @tag_id)
|
|
|
|
|
# redirect_to pay_training_path(id: @tag_id)
|
|
|
|
|
end
|
|
|
|
@ -143,13 +145,11 @@ class TrainingsController < ApplicationController
|
|
|
|
|
# 采用ajax调用方式,返回支付参数
|
|
|
|
|
def update_payinfo
|
|
|
|
|
@training = current_training
|
|
|
|
|
unless @training
|
|
|
|
|
render_404
|
|
|
|
|
if @training.blank?
|
|
|
|
|
redirect_to enroll_training_path(id: @tag_id)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
_pay_params
|
|
|
|
|
|
|
|
|
|
attachment = nil
|
|
|
|
|
if params[:image]
|
|
|
|
|
attachment = Attachment.create!(file: params[:image], author: User.first)
|
|
|
|
@ -163,12 +163,9 @@ class TrainingsController < ApplicationController
|
|
|
|
|
training_info = TrainingPayinfo.new(params)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
training_info.num = params[:enlistN].to_i
|
|
|
|
|
if training_info.num < 1
|
|
|
|
|
training_info.num = 1
|
|
|
|
|
end
|
|
|
|
|
training_info.num = params[:enlistN].to_i < 1 ? 1 : params[:enlistN].to_i
|
|
|
|
|
|
|
|
|
|
training_info.fee = (training_info.num * @pay_fee).to_i
|
|
|
|
|
training_info.fee = @training.registration_fee(training_info.num)
|
|
|
|
|
|
|
|
|
|
training_info.attachment = attachment if attachment.present?
|
|
|
|
|
|
|
|
|
@ -183,7 +180,8 @@ class TrainingsController < ApplicationController
|
|
|
|
|
training_info.save!
|
|
|
|
|
|
|
|
|
|
if params[:js] == 'true'
|
|
|
|
|
_pay_js(training_info.fee)
|
|
|
|
|
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)
|
|
|
|
|
end
|
|
|
|
@ -218,7 +216,7 @@ class TrainingsController < ApplicationController
|
|
|
|
|
#
|
|
|
|
|
# 写入wechat_pay付费表
|
|
|
|
|
WechatPay.create!(training_id: @training.id, out_trade_no: out_trade_no)
|
|
|
|
|
render json: {status: 0, data: unifiedorder(out_trade_no, fee)}
|
|
|
|
|
render json: {status: 0, data: unifiedorder(out_trade_no, fee, @training.pay_order_title)}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -248,9 +246,6 @@ class TrainingsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
def _pay_params
|
|
|
|
|
@pay_fee = Redmine::Configuration['training_fee'].to_f || 5000
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def authenticate
|
|
|
|
|
if Rails.env.development?
|
|
|
|
@ -279,7 +274,7 @@ class TrainingsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def current_training
|
|
|
|
|
Rails.logger.info("##########openid:#{session[:wechat_open_id]}, training_type: #{@training_type}")
|
|
|
|
|
Training.where(openid: session[:wechat_open_id], training_type: @training_type).first
|
|
|
|
|
@_current_training ||= Training.where(openid: session[:wechat_open_id], training_type: @training_type).first
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def valid_training
|
|
|
|
@ -326,14 +321,10 @@ class TrainingsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def unifiedorder(out_trade_no, fee)
|
|
|
|
|
def unifiedorder(out_trade_no, fee, title)
|
|
|
|
|
@config = {}
|
|
|
|
|
|
|
|
|
|
output = Wechat.pay.unifiedorder('湖南警察学院大数据培训会-报名费',
|
|
|
|
|
(fee * 100).to_i,
|
|
|
|
|
session[:wechat_open_id],
|
|
|
|
|
client_ip,
|
|
|
|
|
out_trade_no)
|
|
|
|
|
output = Wechat.pay.unifiedorder(title, (fee * 100).to_i, session[:wechat_open_id], client_ip, out_trade_no)
|
|
|
|
|
data = output.fetch("xml")
|
|
|
|
|
if data.nil?
|
|
|
|
|
raise "获取微信统一单错误"
|
|
|
|
@ -361,5 +352,4 @@ class TrainingsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
@config
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|