|
|
|
@ -38,12 +38,6 @@ class TrainingsController < ApplicationController
|
|
|
|
|
def pay
|
|
|
|
|
@training = current_training
|
|
|
|
|
|
|
|
|
|
# 防止重复支付,对于已支付过的,不应该再到这个页来
|
|
|
|
|
if @training.payed?
|
|
|
|
|
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
|
|
|
|
@ -126,27 +120,25 @@ class TrainingsController < ApplicationController
|
|
|
|
|
training_info = @training.training_payinfo || @training.build_training_payinfo
|
|
|
|
|
training_info.assign_attributes(params)
|
|
|
|
|
|
|
|
|
|
# 已支付不能修改人数
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
|
|
if attachment.blank?
|
|
|
|
|
if attachment.blank? && training_info.not_payed?
|
|
|
|
|
flash[:message] = '请先上传支付凭证'
|
|
|
|
|
render 'pay'
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
training_info.attachment = attachment
|
|
|
|
|
training_info.attachment = attachment if attachment.present?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
if training_info.pay_type.to_i == TrainingPayinfo::PayType_Wechat
|
|
|
|
|
training_info.status = TrainingPayinfo::Status_None
|
|
|
|
|
else
|
|
|
|
@ -156,7 +148,7 @@ class TrainingsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
training_info.save!
|
|
|
|
|
|
|
|
|
|
if params[:js] == 'true'
|
|
|
|
|
if params[:js] == 'true' && training_info.not_payed?
|
|
|
|
|
Rails.logger.info("### start wechat pay => fee: #{training_info.fee}")
|
|
|
|
|
_pay_js(training_info.fee)
|
|
|
|
|
else
|
|
|
|
|