From 56bea6da3ad110f4fc5b5431b1bd162deb632f1a Mon Sep 17 00:00:00 2001
From: p31729568
Date: Sun, 16 Jun 2019 19:51:01 +0800
Subject: [PATCH] modify trainings
---
app/controllers/trainings_controller.rb | 22 ++++++-----------
app/views/trainings/pay.html.erb | 32 +++++++++++++++----------
app/views/trainings/result.html.erb | 2 +-
3 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/app/controllers/trainings_controller.rb b/app/controllers/trainings_controller.rb
index 834509d3..7c95c150 100644
--- a/app/controllers/trainings_controller.rb
+++ b/app/controllers/trainings_controller.rb
@@ -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
diff --git a/app/views/trainings/pay.html.erb b/app/views/trainings/pay.html.erb
index 9ec09189..4e565525 100644
--- a/app/views/trainings/pay.html.erb
+++ b/app/views/trainings/pay.html.erb
@@ -77,20 +77,24 @@
¥<%= @training.training_payinfo.fee || @training.registration_fee %>
-
-
-
- <%= @training.training_payinfo.num || 1 %>人
-
-
-
+ <% if @training.training_payinfo.not_payed? %>
+
+
+
+ <%= @training.training_payinfo.num || 1 %>人
+
+
+
+ <% else %>
+ <%= @training.training_payinfo.num || 1 %>人
+ <% end %>
" id="paySubmitBtn">
@@ -244,11 +248,13 @@
$('#submitFormBtn').on('click', function () {
if(!checkBillInfo()){ return; }
- var image = $("input[name='image']").val()
- if (!image || image.length < 0) {
- alert('请先上传支付凭证');
- return;
- }
+ <% if @training.training_payinfo.not_payed? %>
+ var image = $("input[name='image']").val()
+ if (!image || image.length < 0) {
+ alert('请先上传支付凭证');
+ return;
+ }
+ <% end %>
$('form').submit();
});
diff --git a/app/views/trainings/result.html.erb b/app/views/trainings/result.html.erb
index 6a660ca1..d43da5f0 100644
--- a/app/views/trainings/result.html.erb
+++ b/app/views/trainings/result.html.erb
@@ -105,7 +105,7 @@
<%= link_to "返回", training_path(id: @friendly_id, disable_redirect: true), class: 'leftbtn' %>
立即支付
<% 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 %>