training: modify flow

dev_trainings
p31729568 6 years ago
parent 04790c1302
commit c0a3620bb4

@ -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

@ -42,6 +42,9 @@ class TrainingPayinfo < ActiveRecord::Base
pay_type.to_i == PayType_Wechat && status != Status_Payed pay_type.to_i == PayType_Wechat && status != Status_Payed
end end
def not_payed?
status.nil? || status == Status_None
end
def payed? def payed?
status == Status_Payed status == Status_Payed

@ -2,13 +2,16 @@
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title><%= if params[:controller] == "trainings" && params[:action] == "enroll" <title>
"报名" <%=
elsif params[:controller] == "trainings" && params[:action] == "pay" case "#{params[:controller]}-#{params[:action]}"
"费用支付" when 'trainings-show' then '报名信息'
elsif params[:controller] == "trainings" && params[:action] == "result" when 'trainings-enroll' then '报名'
"支付状态" when 'trainings-pay' then '费用支付和发票信息'
end %></title> when 'trainings-result' then '支付信息'
end
%>
</title>
<meta name="description" content="高校智能课堂与综合实训平台" /> <meta name="description" content="高校智能课堂与综合实训平台" />
<meta name="keywords" content="智能课堂,实训项目" /> <meta name="keywords" content="智能课堂,实训项目" />
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,target-densitydpi=device-dpi" /> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,target-densitydpi=device-dpi" />

@ -1,3 +1,4 @@
<% disabled ||= false %>
<div id="sendPhoto" class="<%= training.training_payinfo.pay_type.to_i == 3 ? "" : "none" %>" style="padding-bottom: 10px;"> <div id="sendPhoto" class="<%= training.training_payinfo.pay_type.to_i == 3 ? "" : "none" %>" style="padding-bottom: 10px;">
<div class="weui-uploader__bd"> <div class="weui-uploader__bd">
<% if training.training_payinfo.attachment_url.present? %> <% if training.training_payinfo.attachment_url.present? %>
@ -6,8 +7,10 @@
<% else %> <% else %>
<li id="uploaderFiles" class="weui-uploader__file"></li> <li id="uploaderFiles" class="weui-uploader__file"></li>
<% end %> <% end %>
<div class="weui-uploader__input-box"> <% unless disabled %>
<input name="image" id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple=""> <div class="weui-uploader__input-box">
</div> <input name="image" id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple="">
</div>
<% end %>
</div> </div>
</div> </div>

@ -124,9 +124,9 @@
</script> </script>
<% end %> <% end %>
<div> <div>
<p class="collegeInfo"><%= @training_title %></p> <p class="collegeInfo"><%= @training_type == 3 ? '信息技术新工科产学研联盟师资培训班' : '工程教育认证' %></p>
<%= form_for @training do |f| %> <%= form_for @training do |f| %>
<%= hidden_field_tag(:tag_id, @tag_id) %> <%= hidden_field_tag(:friendly_id, @friendly_id) %>
<p class="subtitle">基本信息</p> <p class="subtitle">基本信息</p>
<li class="clearfix infoBar"> <li class="clearfix infoBar">
@ -187,7 +187,7 @@
<!-- <input type="text" class="right_input" placeholder="请输入Email" id="userEmail" name="email" value="<%#= @training.email %>"/>--> <!-- <input type="text" class="right_input" placeholder="请输入Email" id="userEmail" name="email" value="<%#= @training.email %>"/>-->
<!-- </li>--> <!-- </li>-->
<p style="height: 50px;"></p> <p style="height: 50px;"></p>
<a href="javascript:void(0)" class="EnrollNext" onclick="NextStep();">提交</a> <a href="javascript:void(0)" class="EnrollNext" onclick="NextStep();"><%= @training.new_record? ? '我要报名' : '保存' %></a>
<% end %> <% end %>
</div> </div>
@ -211,11 +211,6 @@
$('#sex').val("2"); $('#sex').val("2");
} }
}); });
var message = "<%= flash[:message] %>";
if (message && message.length > 0) {
alert(message);
}
}) })
//下一步 //下一步

@ -1,17 +1,15 @@
<form action="/trainings/update_payinfo" method="post" accept-charset="UTF-8" enctype="multipart/form-data"> <form action="/trainings/update_payinfo" method="post" accept-charset="UTF-8" enctype="multipart/form-data">
<div style="padding-top: 10px"> <div style="padding-top: 10px">
<%= hidden_field_tag(:tag_id, params[:id]) %> <%= hidden_field_tag(:friendly_id, @friendly_id) %>
<%= hidden_field_tag(:offline_later_pay, 'false') %>
<!-- <div class="showPanel" id="payTypeLine" NavShow>--> <!-- <div class="showPanel" id="payTypeLine" NavShow>-->
<div class="showPanel" id="payTypeLine"> <div class="showPanel" id="payTypeLine">
<p class="clearfix pr"> <!-- <p class="clearfix pr">-->
<label>支付方式</label> <!-- <label>支付方式</label>-->
<!-- <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>-->
<span class="mr5" style="margin-right: 24px;">线下支付</span> <!-- <span class="mr5" style="margin-right: 24px;">线下支付</span>-->
<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>-->
<p class="payTip" style="margin-top:0px;margin-bottom:9px;">微信支付将于6月18日开通</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">-->
<div class="mt5" id="payInfos"> <div class="mt5" id="payInfos">
<div class="payInfo df"> <div class="payInfo df">
@ -34,7 +32,7 @@
</li> </li>
</div> </div>
</div> </div>
<p class="payTip">完成线下支付后,请将支付截图粘贴到备注中,以便财务审核</p> <p class="payTip">完成银行转账后,请上传转账凭证,由会务组审核</p>
</div> </div>
</div> </div>
<div class="infoBar mb10"> <div class="infoBar mb10">
@ -46,12 +44,13 @@
<p class="clearfix" id="billRemark"> <p class="clearfix" id="billRemark">
<span class="grey fl">发票内容</span> <span class="grey fl">发票内容</span>
<input type="text" name="invoice_content" class="right_input" <input type="text" name="invoice_content" class="right_input"
value="<%= @training.training_payinfo.try(:invoice_content).presence || '师资培训费' %>"/> value="<%= @training.training_payinfo.try(:invoice_content).presence || '会议注册费' %>"/>
</p> </p>
</div> </div>
<div class="infoBar mb10"> <div class="infoBar mb10">
<p>备注</p> <p>备注</p>
<textarea class="remarkAccount" name="info" id="info"><%= @training.training_payinfo.info %></textarea> <textarea class="remarkAccount" name="info" id="info" placeholder="请您在此输入您的留言"><%= @training.training_payinfo.info %></textarea>
<p>上传转账凭证</p>
<!--图片上传--> <!--图片上传-->
<%= render :partial => 'upload_img', :locals => {:training => @training} %> <%= render :partial => 'upload_img', :locals => {:training => @training} %>
</div> </div>
@ -61,7 +60,7 @@
<span class="color-orange" id="percentPay">3人及以上8折优惠)</span> <span class="color-orange" id="percentPay">3人及以上8折优惠)</span>
<% end %> <% end %>
</p> </p>
<p class="break-word justify moneyDetail">含会议注册费、场地费、培训费、教材资料费、餐费、专家差旅费等</p> <p class="break-word justify moneyDetail">含会费、培训费、教材资料费、餐费、专家差旅费等</p>
<p class="clearfix"> <p class="clearfix">
<input type="hidden" name="enlistNum" value="<%= @training.training_payinfo.num || 1 %>"/> <input type="hidden" name="enlistNum" value="<%= @training.training_payinfo.num || 1 %>"/>
<input type="hidden" name="enlistMoney" value="<%= @training.training_payinfo.fee || @training.registration_fee %>"/> <input type="hidden" name="enlistMoney" value="<%= @training.training_payinfo.fee || @training.registration_fee %>"/>
@ -80,12 +79,12 @@
</div> </div>
<p style="height: 44px;"></p> <p style="height: 44px;"></p>
<div class="bottomBtn <%= @training.training_payinfo.pay_type.to_i == 1 ? "none" : "" %>" id="offlinePaySubmitBtn"> <div class="bottomBtn <%= @training.training_payinfo.pay_type.to_i == 1 ? "none" : "" %>" id="offlinePaySubmitBtn">
<a href="javascript:void(0)" class="leftbtn" id="laterSubmitFormBtn">稍后支付</a> <a href="<%= training_path(id: @friendly_id) %>" class="leftbtn">返回</a>
<a href="javascript:void(0)" class="rightbtn" id="submitFormBtn">立即支付</a> <a href="javascript:void(0)" class="rightbtn" id="submitFormBtn">完成转账</a>
</div> </div>
<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="<%= enroll_training_path(id: @tag_id) %>" class="leftbtn">返回</a> <a href="<%= training_path(id: @friendly_id) %>" class="leftbtn">返回</a>
<a href="javascript:void(0)" class="rightbtn" id="payBtn">立即支付</a> <a href="javascript:void(0)" class="rightbtn" id="payBtn">立即支付</a>
</div> </div>
@ -234,13 +233,13 @@
//线下支付提交 //线下支付提交
$('#submitFormBtn').on('click', function () { $('#submitFormBtn').on('click', function () {
if(!checkBillInfo()){ return } if(!checkBillInfo()){ return; }
$('form').submit();
});
$('#laterSubmitFormBtn').on('click', function () {
if(!checkBillInfo()){ return }
$('#offline_later_pay').val('true'); var image = $("input[name='image']").val()
if (!image || image.length < 0) {
alert('请先上传支付凭证');
return;
}
$('form').submit(); $('form').submit();
}); });

@ -86,35 +86,28 @@
</div> </div>
<div class="showPanel"> <div class="showPanel">
<p class="clearfix mb5"><label>其他信息</label></p> <% if @training.training_payinfo.info.present? %>
<p class="mb5 line20"><%= @training.training_payinfo.info %></p> <p class="clearfix mb5"><label>备注信息</label></p>
<p class="mb5 line20"><%= @training.training_payinfo.info %></p>
<% end %>
<% if @training.training_payinfo.attachment_id.to_i > 0 || @training.training_payinfo.pay_type != TrainingPayinfo::PayType_Wechat %> <% if @training.training_payinfo.attachment_id.to_i > 0 || @training.training_payinfo.pay_type != TrainingPayinfo::PayType_Wechat %>
<p class="clearfix mb5"><label>支付凭证</label></p>
<!--图片上传--> <!--图片上传-->
<%= render :partial => 'upload_img', :locals => {:training => @training} %> <%= render partial: 'upload_img', locals: { training: @training, disabled: true } %>
<% end %> <% end %>
<!-- <p class="sendMoney clearfix"><span class="red font-16 fr">¥<%#= @training.training_payinfo.fee %></span><span class="mr5 font-12 fr"><%#= @training.training_payinfo.num %>人</span></p>-->
</div> </div>
<br/> <br/>
<br/> <br/>
<!-- <p class="clearfix enrollNum">
<%#= link_to '查看会议信息', training_path(id: 'bigdata_hnjcxy_2019', force: true), class:'fl meetInfo' %> <div class="bottomBtn">
<span class="fr">已报名人数:<%#= TrainingPayinfo.total_num %>人</span> <% if @training.training_payinfo.wechat_wait_pay? %>
</p> <%= link_to "返回", training_path(id: @friendly_id), class: 'leftbtn' %>
<p style="height: 50px;"></p>--> <a href="javascript:void(0)" class="rightbtn" id="wechatPayBtn">立即支付</a>
<% else%>
<% if @training.payed? %> <%= link_to "返回", pay_training_path(id: @friendly_id), class: 'rightbtn', style: 'width: 100%' %>
<a href="javascript:void(0);" onclick="closeWx();" class="submitForm">完成</a> <% end %>
<% else %> </div>
<% if @training.training_payinfo.wechat_wait_pay? %>
<div class="bottomBtn">
<%= link_to "返回", pay_training_path(id: @tag_id), class: 'leftbtn' %>
<a href="javascript:void(0)" class="rightbtn" id="wechatPayBtn">立即支付</a>
</div>
<% elsif !@training.payed? %>
<%= link_to "返回", pay_training_path(id: @tag_id), class: 'returnBtn' %>
<% end %>
<% end %>
</div> </div>
</div> </div>

@ -175,7 +175,7 @@ input[type='text'].right_input{
float: right;color: #333; float: right;color: #333;
} }
.bottomBtn{ .bottomBtn{
position: fixed;bottom: 0px;left: 0px;width: 100%;height: 44px;line-height: 44px;font-size: 1.6rem;text-align: center; position: fixed;bottom: 0px;left: 0px;width: 100%;height: 44px;line-height: 44px;font-size: 1.6rem;text-align: center;z-index: 20;
} }
.bottomBtn .leftbtn{ .bottomBtn .leftbtn{
width: 50%;float: left;background-color: #fff;color: #676767; width: 50%;float: left;background-color: #fff;color: #676767;
@ -203,7 +203,7 @@ input[type='text'].right_input{
line-height: 20px;margin-top: 3px; line-height: 20px;margin-top: 3px;
} }
.remarkAccount{ .remarkAccount{
width: 100%;resize: none;height: 80px;margin-bottom:14px;border: 1px solid #eee;padding: 5px;box-sizing: border-box; width: 100%;resize: none;height: 80px;border: 1px solid #eee;padding: 5px;box-sizing: border-box;
} }
.moneyDetail{ .moneyDetail{
line-height: 20px;color: #4B4B4B; line-height: 20px;color: #4B4B4B;

Loading…
Cancel
Save