modify trainings

dev_trainings
p31729568 6 years ago
parent 3a301499ca
commit 56bea6da3a

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

@ -77,6 +77,7 @@
<span class="fl red mr5 font-16">¥<span id="enlistM"><%= @training.training_payinfo.fee || @training.registration_fee %></span></span> <span class="fl red mr5 font-16">¥<span id="enlistM"><%= @training.training_payinfo.fee || @training.registration_fee %></span></span>
<span class="lastPrice"></span> <span class="lastPrice"></span>
<span class="fr font-16"> <span class="fr font-16">
<% if @training.training_payinfo.not_payed? %>
<a href="javascript:void(0)" class="minusNum" onclick="minusNum(this)"> <a href="javascript:void(0)" class="minusNum" onclick="minusNum(this)">
<i class="iconfont icon-default sky_blue font-18"></i> <i class="iconfont icon-default sky_blue font-18"></i>
</a> </a>
@ -84,13 +85,16 @@
<a href="javascript:void(0)" class="plusNum" onclick="plusNum(this)"> <a href="javascript:void(0)" class="plusNum" onclick="plusNum(this)">
<i class="iconfont icon-roundaddfill blue font-18"></i> <i class="iconfont icon-roundaddfill blue font-18"></i>
</a> </a>
<% else %>
<span class="mr5 ml5 font-14"><span id="enlistN"><%= @training.training_payinfo.num || 1 %></span>人</span>
<% end %>
</span> </span>
</p> </p>
</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="<%= training_path(id: @friendly_id, disable_redirect: true) %>" class="leftbtn">返回</a> <a href="<%= training_path(id: @friendly_id, disable_redirect: true) %>" class="leftbtn">返回</a>
<a href="javascript:void(0)" class="rightbtn" id="submitFormBtn">完成转账</a> <a href="javascript:void(0)" class="rightbtn" id="submitFormBtn"><%= @training.training_payinfo.new_record? ? '完成转账' : '提交' %></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">
@ -244,11 +248,13 @@
$('#submitFormBtn').on('click', function () { $('#submitFormBtn').on('click', function () {
if(!checkBillInfo()){ return; } if(!checkBillInfo()){ return; }
<% if @training.training_payinfo.not_payed? %>
var image = $("input[name='image']").val() var image = $("input[name='image']").val()
if (!image || image.length < 0) { if (!image || image.length < 0) {
alert('请先上传支付凭证'); alert('请先上传支付凭证');
return; return;
} }
<% end %>
$('form').submit(); $('form').submit();
}); });

@ -105,7 +105,7 @@
<%= link_to "返回", training_path(id: @friendly_id, disable_redirect: true), class: 'leftbtn' %> <%= link_to "返回", training_path(id: @friendly_id, disable_redirect: true), class: 'leftbtn' %>
<a href="javascript:void(0)" class="rightbtn" id="wechatPayBtn">立即支付</a> <a href="javascript:void(0)" class="rightbtn" id="wechatPayBtn">立即支付</a>
<% else%> <% else%>
<%= link_to "返回", training_path(id: @friendly_id, disable_redirect: true), class: 'rightbtn', style: 'width: 100%' %> <%= link_to "返回", pay_training_path(id: @friendly_id, disable_redirect: true), class: 'rightbtn', style: 'width: 100%' %>
<% end %> <% end %>
</div> </div>
</div> </div>

Loading…
Cancel
Save