Commit 198c2bdd by ivan Lan

Add manager_id and manager_type to snapshot

parent 2a759485
......@@ -20,14 +20,10 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
# Single Table Inheritance
t.string :type
t.json :meta
t.integer :manager_id
t.string :manager_type
t.references :manager, polymorphic: true, index: true
t.timestamps
end
add_index :shotengai_products, [:manager_id, :manager_type]
add_index :shotengai_products, :type
end
......@@ -43,7 +39,6 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
t.json :meta
t.references :shotengai_product, foreign_key: true
t.timestamps
end
......@@ -66,15 +61,12 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
t.string :status
t.string :type
t.json :meta
t.integer :buyer_id
t.string :buyer_type
t.references :buyer, polymorphic: true, index: true
t.timestamps
end
add_index :shotengai_orders, :type
add_index :shotengai_orders, [:buyer_id, :buyer_type]
end
def create_snapshot
......@@ -96,6 +88,7 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
t.references :shotengai_series, foreign_key: true
t.references :shotengai_order, foreign_key: true
t.references :manager, polymorphic: true, index: true
t.timestamps
end
......
......@@ -39,6 +39,9 @@ module Shotengai
belongs_to :shotengai_cart, foreign_key: :shotengai_order_id,
class_name: 'Shotengai::Cart', optional: true#, touch: true
belongs_to :manager, polymorphic: true, optional: true
before_save :set_manager
scope :in_order, -> { joins(:shotengai_order).where.not(shotengai_orders: { status: 'cart'}) }
scope :in_cart, -> { joins(:shotengai_order).where(shotengai_orders: { status: 'cart'}) }
......@@ -60,8 +63,6 @@ module Shotengai
end
end
delegate :manager, to: :series
# 支付前 信息 delegate to series
%i{
original_price price spec banners
......@@ -78,6 +79,10 @@ module Shotengai
series.deleted?
end
def manager
super || series.manager
end
# 订单支付后 存储当时信息快照
def copy_info
# cut_stock
......@@ -138,6 +143,10 @@ module Shotengai
errors.add(:id, '订单已支付,禁止修改商品快照。')
end
end
def set_manager
self.manager = self.series.product.manager
end
end
end
\ No newline at end of file
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