Merge branch 'dev_trainings' of https://bdgit.educoder.net/Hjqreturn/pgfqe6ch8 into dev_trainings

dev_trainings
caishi 6 years ago
commit aeb3fe9b0e

@ -4,68 +4,38 @@ class TrainingsController < ApplicationController
wechat_responder
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}"
before_filter :authenticate, except: [:auth, :auth_callback, :pay_callback]
before_filter :find_tag_id, except: [:auth, :auth_callback, :pay_callback]
before_filter :find_training, only: [:show, :test]
before_filter :valid_training, only: [:pay, :result, :pay_js]
before_filter :check_training_type, only: [:enroll]
before_filter :check_current_training, only: [:show, :update, :pay, :pay_js, :update_payinfo, :result]
layout 'base_trainings'
# TAG_ID = 'bigdata_hnjcxy_2019'
def show
@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
def enroll
@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
def pay
@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)
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
@training.training_payinfo.pay_type = params[:pay_type].presence || 3
end
end
@ -113,36 +83,24 @@ class TrainingsController < ApplicationController
end
def create
@training = current_training || Training.new(params)
@training = Training.new
@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.save!
flash[:message] = '提交成功'
save_training
redirect_to pay_training_path(id: @tag_id)
end
flash[:message] = '报名成功'
redirect_to training_path(id: friendly_id)
end
def update
@training = current_training
if @training.blank?
redirect_to enroll_training_path(id: @tag_id)
return
end
save_training
@training.assign_attributes(params)
if @training.training_type == 3
@training.research_field = params[:research_field].select(&:present?).uniq.join(",")
end
@training.save!
flash[:message] = '提交成功'
flash[:message] = '保存成功'
redirect_to pay_training_path(id: @tag_id)
redirect_to training_path(id: friendly_id)
end
@ -152,48 +110,45 @@ class TrainingsController < ApplicationController
# 采用ajax调用方式返回支付参数
def update_payinfo
@training = current_training
if @training.blank?
redirect_to enroll_training_path(id: @tag_id)
return
end
training_info = @training.training_payinfo || @training.build_training_payinfo
training_info.assign_attributes(params)
attachment = nil
if params[:image]
attachment = Attachment.create!(file: params[:image], author: User.first)
# 已支付不能修改人数
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
#修改以前的订单信息
training_info = @training.training_payinfo
if training_info.present?
training_info.update_attributes(params)
else
training_info = TrainingPayinfo.new(params)
end
training_info.num = params[:enlistNum].to_i < 1 ? 1 : params[:enlistNum].to_i
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]
training_info.fee = @training.registration_fee(training_info.num)
training_info.attachment = attachment if attachment.present?
if attachment.blank?
flash[:message] = '请先上传支付凭证'
render 'pay'
return
end
if training_info.pay_type.to_i == TrainingPayinfo::PayType_Wechat
training_info.status = TrainingPayinfo::Status_None
elsif params[:offline_later_pay].to_s == 'true'
# 线下支付-稍后支付
training_info.status = TrainingPayinfo::Status_None
else
training_info.status = TrainingPayinfo::Status_Wait
end
training_info.attachment = attachment
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'
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)
if params[:js] == 'true'
Rails.logger.info("### start wechat pay => fee: #{training_info.fee}")
_pay_js(training_info.fee)
else
redirect_to result_training_path(id: friendly_id)
end
end
end
@ -268,29 +223,54 @@ class TrainingsController < ApplicationController
end
end
def find_tag_id
@tag_id = params[:tag_id] || params[:id]
Rails.logger.info("##########TAG_ID:#{@tag_id}")
@training_type = @tag_id == "aeee0601_2019" ? 3 : @tag_id == "ceeaa06_2019" ? 4 : 0
render_404 if @training_type == 0
end
def save_training
@training.assign_attributes(params)
@training.training_type = training_type
def find_training
if params[:id] == @tag_id
@training = current_training
else
render_404
if @training.training_type == 3
@training.research_field = params[:research_field].select(&:present?).uniq.join(",")
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
def current_training
Rails.logger.info("##########openid:#{session[:wechat_open_id]}, training_type: #{@training_type}")
@_current_training ||= Training.where(openid: session[:wechat_open_id], training_type: @training_type).first
@_current_training ||= begin
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
def valid_training
unless current_training
redirect_to training_path(id: @tag_id)
def check_current_training
if current_training.blank?
if training_type.blank?
render_404
return
end
redirect_to enroll_training_path(id: friendly_id)
return
end
end

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

@ -2,13 +2,16 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title><%= if params[:controller] == "trainings" && params[:action] == "enroll"
"报名"
elsif params[:controller] == "trainings" && params[:action] == "pay"
"费用支付"
elsif params[:controller] == "trainings" && params[:action] == "result"
"支付状态"
end %></title>
<title>
<%=
case "#{params[:controller]}-#{params[:action]}"
when 'trainings-show' then '报名信息'
when 'trainings-enroll' then '报名'
when 'trainings-pay' then '费用支付和发票信息'
when 'trainings-result' then '支付信息'
end
%>
</title>
<meta name="description" content="高校智能课堂与综合实训平台" />
<meta name="keywords" content="智能课堂,实训项目" />
<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 class="weui-uploader__bd">
<% if training.training_payinfo.attachment_url.present? %>
@ -6,8 +7,10 @@
<% else %>
<li id="uploaderFiles" class="weui-uploader__file"></li>
<% end %>
<div class="weui-uploader__input-box">
<input name="image" id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple="">
</div>
<% unless disabled %>
<div class="weui-uploader__input-box">
<input name="image" id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple="">
</div>
<% end %>
</div>
</div>

@ -124,9 +124,9 @@
</script>
<% end %>
<div>
<p class="collegeInfo"><%= @training_title %></p>
<p class="collegeInfo"><%= @training_type == 3 ? '信息技术新工科产学研联盟师资培训班' : '工程教育认证' %></p>
<%= form_for @training do |f| %>
<%= hidden_field_tag(:tag_id, @tag_id) %>
<%= hidden_field_tag(:friendly_id, @friendly_id) %>
<p class="subtitle">基本信息</p>
<li class="clearfix infoBar">
@ -187,7 +187,7 @@
<!-- <input type="text" class="right_input" placeholder="请输入Email" id="userEmail" name="email" value="<%#= @training.email %>"/>-->
<!-- </li>-->
<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 %>
</div>
@ -211,11 +211,6 @@
$('#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">
<div style="padding-top: 10px">
<%= hidden_field_tag(:tag_id, params[:id]) %>
<%= hidden_field_tag(:offline_later_pay, 'false') %>
<%= hidden_field_tag(:friendly_id, @friendly_id) %>
<!-- <div class="showPanel" id="payTypeLine" NavShow>-->
<div class="showPanel" id="payTypeLine">
<p class="clearfix pr">
<label>支付方式</label>
<!-- <p class="clearfix pr">-->
<!-- <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;">线下支付</span>
<i class="iconfont icon-gengduo1 rightArrow" style="color: #323232;right: 4px"></i>
</p>
<p class="payTip" style="margin-top:0px;margin-bottom:9px;">微信支付将于6月18日开通</p>
<!-- <span class="mr5" style="margin-right: 24px;">线下支付</span>-->
<!-- <i class="iconfont icon-gengduo1 rightArrow" style="color: #323232;right: 4px"></i>-->
<!-- </p>-->
<!-- <div class="<%#= @training.training_payinfo.pay_type.to_i == 3 ? "" : "none" %> mt5" id="payInfos">-->
<div class="mt5" id="payInfos">
<div class="payInfo df">
@ -34,7 +32,7 @@
</li>
</div>
</div>
<p class="payTip">完成线下支付后,请将支付截图粘贴到备注中,以便财务审核</p>
<p class="payTip">完成银行转账后,请上传转账凭证,由会务组审核</p>
</div>
</div>
<div class="infoBar mb10">
@ -46,12 +44,13 @@
<p class="clearfix" id="billRemark">
<span class="grey fl">发票内容</span>
<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>
</div>
<div class="infoBar mb10">
<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} %>
</div>
@ -61,7 +60,7 @@
<span class="color-orange" id="percentPay">3人及以上8折优惠)</span>
<% end %>
</p>
<p class="break-word justify moneyDetail">含会议注册费、场地费、培训费、教材资料费、餐费、专家差旅费等</p>
<p class="break-word justify moneyDetail">含会费、培训费、教材资料费、餐费、专家差旅费等</p>
<p class="clearfix">
<input type="hidden" name="enlistNum" value="<%= @training.training_payinfo.num || 1 %>"/>
<input type="hidden" name="enlistMoney" value="<%= @training.training_payinfo.fee || @training.registration_fee %>"/>
@ -80,12 +79,12 @@
</div>
<p style="height: 44px;"></p>
<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="javascript:void(0)" class="rightbtn" id="submitFormBtn">立即支付</a>
<a href="<%= training_path(id: @friendly_id) %>" class="leftbtn">返回</a>
<a href="javascript:void(0)" class="rightbtn" id="submitFormBtn">完成转账</a>
</div>
<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>
</div>
@ -234,13 +233,13 @@
//线下支付提交
$('#submitFormBtn').on('click', function () {
if(!checkBillInfo()){ return }
$('form').submit();
});
$('#laterSubmitFormBtn').on('click', function () {
if(!checkBillInfo()){ return }
if(!checkBillInfo()){ return; }
$('#offline_later_pay').val('true');
var image = $("input[name='image']").val()
if (!image || image.length < 0) {
alert('请先上传支付凭证');
return;
}
$('form').submit();
});

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

@ -175,7 +175,7 @@ input[type='text'].right_input{
float: right;color: #333;
}
.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{
width: 50%;float: left;background-color: #fff;color: #676767;
@ -203,7 +203,7 @@ input[type='text'].right_input{
line-height: 20px;margin-top: 3px;
}
.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{
line-height: 20px;color: #4B4B4B;

Loading…
Cancel
Save