Skip to content

Commit

Permalink
perfect the customer create a new order,we dont do anything in commit…
Browse files Browse the repository at this point in the history
… action when the order has already get a payment for it. and change the mail sending time
  • Loading branch information
liwh committed Oct 12, 2011
1 parent 4c2d1a6 commit 9ca0788
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
23 changes: 12 additions & 11 deletions app/controllers/shop/order_controller.rb
Expand Up @@ -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

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

# 支付
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/order.rb
Expand Up @@ -116,6 +116,7 @@ def title

def pay!
order.financial_status = 'paid'
order.send_email_when_order_forward
#TODO
#支付记录
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/payment.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/shop.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/shop/order/_confirm_pay.html.haml
Expand Up @@ -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

0 comments on commit 9ca0788

Please sign in to comment.