From 9ca07888a0d4dcd9e9edf6a5bd2a98c4b3df6c50 Mon Sep 17 00:00:00 2001 From: liwh Date: Thu, 13 Oct 2011 00:08:10 +0800 Subject: [PATCH] perfect the customer create a new order,we dont do anything in commit action when the order has already get a payment for it. and change the mail sending time --- app/controllers/shop/order_controller.rb | 23 +++++++++++---------- app/models/order.rb | 1 + app/models/payment.rb | 2 +- app/models/shop.rb | 2 +- app/views/shop/order/_confirm_pay.html.haml | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/controllers/shop/order_controller.rb b/app/controllers/shop/order_controller.rb index fdd94cb9..663c46d5 100644 --- a/app/controllers/shop/order_controller.rb +++ b/app/controllers/shop/order_controller.rb @@ -79,7 +79,7 @@ def create end #增加默认的付款方式为支付宝 - order.payment = shop.payments.where(payment_type_id: KeyValues::PaymentType.first.id).first + #order.payment = shop.payments.where(payment_type_id: KeyValues::PaymentType.first.id).first #税率 order.tax_price = shop.taxes_included ? 0.0 : cart_total_price * shop.countries.find_by_code(order.shipping_address.country_code).tax_percentage/100 @@ -92,14 +92,11 @@ def create # 发货方式、付款方式Step2 def pay + order.payment ||= shop.payments.first end def forward - if order - order.send_email_when_order_forward - else - render file: 'public/404.html',layout: false, status: 404 - end + render file: 'public/404.html',layout: false, status: 404 unless order end # 支付 @@ -110,11 +107,15 @@ def commit data = data.merge({error: 'shipping_rate', shipping_rate: params[:shipping_rate] }) if !include_shipping_rate data = data.merge({payment_error: true}) if !params[:order][:payment_id] else - params[:buyer_accepts_marketing] == 'true' ? order.customer.accepts_marketing = true : order.customer.accepts_marketing = false - order.customer.save - order.financial_status = 'pending' - order.payment = shop.payments.find(params[:order][:payment_id]) - order.save + #若是已提交过的订单,则不做任何操作 + unless order.payment.id? + params[:buyer_accepts_marketing] == 'true' ? order.customer.accepts_marketing = true : order.customer.accepts_marketing = false + order.customer.save + order.financial_status = 'pending' + order.payment = shop.payments.find(params[:order][:payment_id]) + order.save + order.send_email_when_order_forward if order.payment.name #发送邮件,非在线支付方式。在线支付方式在付款之后发送邮件 + end data = {success: true, url: forward_order_path(params[:shop_id],params[:token])} end render json: data diff --git a/app/models/order.rb b/app/models/order.rb index a06587d6..e47d8989 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -116,6 +116,7 @@ def title def pay! order.financial_status = 'paid' + order.send_email_when_order_forward #TODO #支付记录 end diff --git a/app/models/payment.rb b/app/models/payment.rb index 4c867d73..9c04280b 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -2,7 +2,7 @@ class Payment < ActiveRecord::Base belongs_to :shop validates_presence_of :partner,:account,:key, if: Proc.new{|p| p.payment_type_id?} validates_presence_of :name, if: Proc.new{|p| !p.payment_type_id?} - default_scope order('created_at') + #default_scope order('created_at') def payment_type KeyValues::PaymentType.find(self.payment_type_id) end diff --git a/app/models/shop.rb b/app/models/shop.rb index 7d51dcc7..dda0a18b 100644 --- a/app/models/shop.rb +++ b/app/models/shop.rb @@ -27,7 +27,7 @@ class Shop < ActiveRecord::Base has_many :emails , dependent: :destroy has_many :countries , dependent: :destroy has_many :activities , dependent: :destroy , order: 'created_at desc' - has_many :payments , dependent: :destroy + has_many :payments , dependent: :destroy , order: 'payment_type_id, created_at' has_many :tasks , dependent: :destroy , order: 'id asc', class_name: 'ShopTask' has_many :policies , dependent: :destroy , order: 'id asc', class_name: 'ShopPolicy' has_many :consumptions , dependent: :destroy diff --git a/app/views/shop/order/_confirm_pay.html.haml b/app/views/shop/order/_confirm_pay.html.haml index 04ca1dba..e764e2ac 100644 --- a/app/views/shop/order/_confirm_pay.html.haml +++ b/app/views/shop/order/_confirm_pay.html.haml @@ -14,4 +14,4 @@ .actions = button_to_function "确认支付", "$('#payment-form > div').remove();$('#payment-form').submit()",class:'btn' =w('or') - =link_to w('cancel'),account_index_path + =link_to w('cancel'),show_shop_url