Commit 198c2bdd by ivan Lan

Add manager_id and manager_type to snapshot

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