Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
shotengai
Commits
198c2bdd
Commit
198c2bdd
authored
Sep 26, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add manager_id and manager_type to snapshot
parent
2a759485
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
13 deletions
+16
-13
1_create_shotengai_products_and_orders.rb
db/migrate/1_create_shotengai_products_and_orders.rb
+4
-11
snapshot.rb
lib/shotengai/snapshot.rb
+12
-2
No files found.
db/migrate/1_create_shotengai_products_and_orders.rb
View file @
198c2bdd
...
@@ -20,14 +20,10 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
...
@@ -20,14 +20,10 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
# Single Table Inheritance
# Single Table Inheritance
t
.
string
:type
t
.
string
:type
t
.
json
:meta
t
.
json
:meta
t
.
integer
:manager_id
t
.
string
:manager_type
t
.
references
:manager
,
polymorphic:
true
,
index:
true
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
...
@@ -66,15 +61,12 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
...
@@ -66,15 +61,12 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
t
.
string
:status
t
.
string
:status
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
...
...
lib/shotengai/snapshot.rb
View file @
198c2bdd
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment