Commit d508d3fa by ivan Lan

Improve order about amount & product_amount & product_original_amount

parent 1f2477a1
json.extract! order, :id, :seq, :address, json.extract! order, :id, :seq, :address, :amount,
:product_amount, :product_original_amount,
:total_price, :total_original_price, :total_price, :total_original_price,
:pay_time, :delivery_time, :receipt_time, :pay_time, :delivery_time, :receipt_time,
:delivery_way, :delivery_cost, :delivery_way, :delivery_cost,
......
json.extract! order, :id, :seq, :address, json.extract! order, :id, :seq, :address, :amount
:total_price, :total_original_price, :product_amount, :product_original_amount,
:pay_time, :delivery_time, :receipt_time, :pay_time, :delivery_time, :receipt_time,
:delivery_way, :delivery_cost, :delivery_way, :delivery_cost,
:merchant_remark, :mark, :customer_remark, :merchant_remark, :mark, :customer_remark,
......
json.extract! order, :id, :seq, :total_price, :total_original_price, json.extract! order, :id, :seq, :amount,
:product_amount, :product_original_amount,
:status_zh, :address, :status_zh, :address,
:pay_time, :delivery_time, :receipt_time, :pay_time, :delivery_time, :receipt_time,
:delivery_way, :delivery_cost, :customer_remark, :delivery_way, :delivery_cost, :customer_remark,
......
json.extract! order, :id, :seq, :address, json.extract! order, :id, :seq, :address, :amount,
:total_price, :total_original_price, :product_amount, :product_original_amount,
:pay_time, :delivery_time, :receipt_time, :pay_time, :delivery_time, :receipt_time,
:delivery_way, :delivery_cost, :customer_remark, :delivery_way, :delivery_cost, :customer_remark,
:status, :status_zh, :meta, :created_at :status, :status_zh, :meta, :created_at
\ No newline at end of file
...@@ -98,10 +98,6 @@ module Shotengai ...@@ -98,10 +98,6 @@ module Shotengai
update!(receipt_time: Time.now) update!(receipt_time: Time.now)
end end
def set_amount
self.update!(amount: product_amount + delivery_cost)
end
def set_seq def set_seq
timestamp = Time.now.strftime("%Y%m%d-%H%M") timestamp = Time.now.strftime("%Y%m%d-%H%M")
no_length = 4 no_length = 4
...@@ -109,6 +105,14 @@ module Shotengai ...@@ -109,6 +105,14 @@ module Shotengai
self.update!(seq: "#{timestamp}-#{no}}") self.update!(seq: "#{timestamp}-#{no}}")
end end
def set_amount
self.update!(amount: product_amount + delivery_cost)
end
def amount
read_attribute(:amount) || product_amount + delivery_cost
end
def product_amount def product_amount
snapshots.sum(&:total_price) snapshots.sum(&:total_price)
end end
...@@ -117,6 +121,8 @@ module Shotengai ...@@ -117,6 +121,8 @@ module Shotengai
snapshots.sum(&:total_original_price) snapshots.sum(&:total_original_price)
end end
# into order # into order
def incr_snapshot_ids= ids def incr_snapshot_ids= ids
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment