|
|
@ -4,68 +4,38 @@ class TrainingsController < ApplicationController
|
|
|
|
wechat_responder
|
|
|
|
wechat_responder
|
|
|
|
|
|
|
|
|
|
|
|
skip_before_filter :check_if_login_required
|
|
|
|
skip_before_filter :check_if_login_required
|
|
|
|
skip_before_filter :verify_signature, only: [:show, :create, :update, :test, :enroll]
|
|
|
|
skip_before_filter :verify_signature, except: [:auth, :auth_callback, :pay_callback]
|
|
|
|
|
|
|
|
|
|
|
|
ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}"
|
|
|
|
ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}"
|
|
|
|
|
|
|
|
|
|
|
|
before_filter :authenticate, except: [:auth, :auth_callback, :pay_callback]
|
|
|
|
before_filter :authenticate, except: [:auth, :auth_callback, :pay_callback]
|
|
|
|
|
|
|
|
|
|
|
|
before_filter :find_tag_id, except: [:auth, :auth_callback, :pay_callback]
|
|
|
|
before_filter :check_training_type, only: [:enroll]
|
|
|
|
|
|
|
|
before_filter :check_current_training, only: [:show, :update, :pay, :pay_js, :update_payinfo, :result]
|
|
|
|
before_filter :find_training, only: [:show, :test]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before_filter :valid_training, only: [:pay, :result, :pay_js]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
layout 'base_trainings'
|
|
|
|
layout 'base_trainings'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TAG_ID = 'bigdata_hnjcxy_2019'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
def show
|
|
|
|
@training = current_training
|
|
|
|
@training = current_training
|
|
|
|
|
|
|
|
|
|
|
|
url = nil
|
|
|
|
|
|
|
|
if @training && !@training.pay?
|
|
|
|
|
|
|
|
url = enroll_training_path(id: @tag_id)
|
|
|
|
|
|
|
|
elsif @training && @training.pay?
|
|
|
|
|
|
|
|
url = result_training_path(id: @tag_id)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
url = enroll_training_path(id: @tag_id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redirect_to url
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def enroll
|
|
|
|
def enroll
|
|
|
|
@training = current_training || Training.new
|
|
|
|
@training = current_training || Training.new
|
|
|
|
|
|
|
|
|
|
|
|
if @training && @training.pay?
|
|
|
|
|
|
|
|
redirect_to result_training_path(id: @tag_id)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rails.logger.info("##########training_type:#{@training_type}")
|
|
|
|
|
|
|
|
@training_title = @training_type == 3 ? "信息技术新工科产学研联盟师资培训班" : "工程教育认证"
|
|
|
|
|
|
|
|
Rails.logger.info("##########training_title:#{@training_title}")
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def pay
|
|
|
|
def pay
|
|
|
|
@training = current_training
|
|
|
|
@training = current_training
|
|
|
|
|
|
|
|
|
|
|
|
if @training.blank?
|
|
|
|
|
|
|
|
redirect_to enroll_training_path(id: @tag_id)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 防止重复支付,对于已支付过的,不应该再到这个页来
|
|
|
|
# 防止重复支付,对于已支付过的,不应该再到这个页来
|
|
|
|
if @training.payed?
|
|
|
|
if @training.payed?
|
|
|
|
redirect_to result_training_path(id: @tag_id)
|
|
|
|
redirect_to result_training_path(id: friendly_id)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if @training.training_payinfo.blank?
|
|
|
|
if @training.training_payinfo.blank?
|
|
|
|
@training.build_training_payinfo
|
|
|
|
@training.build_training_payinfo
|
|
|
|
@training.training_payinfo.fee = @training.registration_fee
|
|
|
|
@training.training_payinfo.fee = @training.registration_fee
|
|
|
|
|
|
|
|
@training.training_payinfo.pay_type = params[:pay_type].presence || 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -113,36 +83,24 @@ class TrainingsController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
def create
|
|
|
|
@training = current_training || Training.new(params)
|
|
|
|
@training = Training.new
|
|
|
|
@training.training_type = @training_type
|
|
|
|
@training.training_type = @training_type
|
|
|
|
if @training_type == 3
|
|
|
|
|
|
|
|
@training.research_field = params[:research_field].select(&:present?).uniq.join(",")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
@training.openid = session[:wechat_open_id]
|
|
|
|
@training.openid = session[:wechat_open_id]
|
|
|
|
@training.save!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flash[:message] = '提交成功'
|
|
|
|
save_training
|
|
|
|
|
|
|
|
|
|
|
|
redirect_to pay_training_path(id: @tag_id)
|
|
|
|
flash[:message] = '报名成功'
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redirect_to training_path(id: friendly_id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
def update
|
|
|
|
@training = current_training
|
|
|
|
@training = current_training
|
|
|
|
if @training.blank?
|
|
|
|
save_training
|
|
|
|
redirect_to enroll_training_path(id: @tag_id)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@training.assign_attributes(params)
|
|
|
|
flash[:message] = '保存成功'
|
|
|
|
if @training.training_type == 3
|
|
|
|
|
|
|
|
@training.research_field = params[:research_field].select(&:present?).uniq.join(",")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
@training.save!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flash[:message] = '提交成功'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redirect_to pay_training_path(id: @tag_id)
|
|
|
|
redirect_to training_path(id: friendly_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -152,48 +110,45 @@ class TrainingsController < ApplicationController
|
|
|
|
# 采用ajax调用方式,返回支付参数
|
|
|
|
# 采用ajax调用方式,返回支付参数
|
|
|
|
def update_payinfo
|
|
|
|
def update_payinfo
|
|
|
|
@training = current_training
|
|
|
|
@training = current_training
|
|
|
|
if @training.blank?
|
|
|
|
training_info = @training.training_payinfo || @training.build_training_payinfo
|
|
|
|
redirect_to enroll_training_path(id: @tag_id)
|
|
|
|
training_info.assign_attributes(params)
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attachment = nil
|
|
|
|
# 已支付不能修改人数
|
|
|
|
if params[:image]
|
|
|
|
if training_info.not_payed?
|
|
|
|
attachment = Attachment.create!(file: params[:image], author: User.first)
|
|
|
|
training_info.num = params[:enlistNum].to_i < 1 ? 1 : params[:enlistNum].to_i
|
|
|
|
|
|
|
|
training_info.fee = @training.registration_fee(training_info.num)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#修改以前的订单信息
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
training_info = @training.training_payinfo
|
|
|
|
if training_info.pay_type.to_i == TrainingPayinfo::PayType_bank
|
|
|
|
if training_info.present?
|
|
|
|
attachment = nil
|
|
|
|
training_info.update_attributes(params)
|
|
|
|
attachment = Attachment.create!(file: params[:image], author: User.first) if params[:image]
|
|
|
|
else
|
|
|
|
|
|
|
|
training_info = TrainingPayinfo.new(params)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training_info.num = params[:enlistNum].to_i < 1 ? 1 : params[:enlistNum].to_i
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training_info.fee = @training.registration_fee(training_info.num)
|
|
|
|
if attachment.blank?
|
|
|
|
|
|
|
|
flash[:message] = '请先上传支付凭证'
|
|
|
|
training_info.attachment = attachment if attachment.present?
|
|
|
|
render 'pay'
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if training_info.pay_type.to_i == TrainingPayinfo::PayType_Wechat
|
|
|
|
training_info.attachment = attachment
|
|
|
|
training_info.status = TrainingPayinfo::Status_None
|
|
|
|
end
|
|
|
|
elsif params[:offline_later_pay].to_s == 'true'
|
|
|
|
|
|
|
|
# 线下支付-稍后支付
|
|
|
|
|
|
|
|
training_info.status = TrainingPayinfo::Status_None
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
training_info.status = TrainingPayinfo::Status_Wait
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training_info.training_id = @training.id
|
|
|
|
if training_info.not_payed?
|
|
|
|
|
|
|
|
if training_info.pay_type.to_i == TrainingPayinfo::PayType_Wechat
|
|
|
|
|
|
|
|
training_info.status = TrainingPayinfo::Status_None
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
training_info.status = TrainingPayinfo::Status_Wait
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
training_info.save!
|
|
|
|
training_info.save!
|
|
|
|
|
|
|
|
|
|
|
|
if params[:js] == 'true'
|
|
|
|
if params[:js] == 'true'
|
|
|
|
Rails.logger.info("### start wechat pay => fee: #{training_info.fee}")
|
|
|
|
Rails.logger.info("### start wechat pay => fee: #{training_info.fee}")
|
|
|
|
_pay_js(0.01 || training_info.fee)
|
|
|
|
_pay_js(training_info.fee)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
redirect_to url = result_training_path(id: @tag_id)
|
|
|
|
redirect_to result_training_path(id: friendly_id)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -268,29 +223,54 @@ class TrainingsController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def find_tag_id
|
|
|
|
def save_training
|
|
|
|
@tag_id = params[:tag_id] || params[:id]
|
|
|
|
@training.assign_attributes(params)
|
|
|
|
Rails.logger.info("##########TAG_ID:#{@tag_id}")
|
|
|
|
@training.training_type = training_type
|
|
|
|
@training_type = @tag_id == "aeee0601_2019" ? 3 : @tag_id == "ceeaa06_2019" ? 4 : 0
|
|
|
|
|
|
|
|
render_404 if @training_type == 0
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_training
|
|
|
|
if @training.training_type == 3
|
|
|
|
if params[:id] == @tag_id
|
|
|
|
@training.research_field = params[:research_field].select(&:present?).uniq.join(",")
|
|
|
|
@training = current_training
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
render_404
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@training.save!
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def friendly_id
|
|
|
|
|
|
|
|
@friendly_id ||= params[:friendly_id].presence || params[:id]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def training_type
|
|
|
|
|
|
|
|
@training_type ||=
|
|
|
|
|
|
|
|
case friendly_id
|
|
|
|
|
|
|
|
when 'aeee0601_2019' then 3
|
|
|
|
|
|
|
|
when 'ceeaa06_2019' then 4
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def current_training
|
|
|
|
def current_training
|
|
|
|
Rails.logger.info("##########openid:#{session[:wechat_open_id]}, training_type: #{@training_type}")
|
|
|
|
@_current_training ||= begin
|
|
|
|
@_current_training ||= Training.where(openid: session[:wechat_open_id], training_type: @training_type).first
|
|
|
|
Rails.logger.info("##########openid:#{session[:wechat_open_id]}, friendly_id: #{friendly_id}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return if training_type.blank?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Training.where(openid: session[:wechat_open_id], training_type: training_type).first
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_training_type
|
|
|
|
|
|
|
|
return if training_type.present?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def valid_training
|
|
|
|
def check_current_training
|
|
|
|
unless current_training
|
|
|
|
if current_training.blank?
|
|
|
|
redirect_to training_path(id: @tag_id)
|
|
|
|
if training_type.blank?
|
|
|
|
|
|
|
|
render_404
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
redirect_to enroll_training_path(id: friendly_id)
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|