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
0835d741
Commit
0835d741
authored
Sep 27, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve snapshot validate
parent
a1a3743c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
13 deletions
+31
-13
products_controller.rb
lib/shotengai/controllers/customer/products_controller.rb
+4
-0
product.rb
lib/shotengai/product.rb
+2
-0
snapshot.rb
lib/shotengai/snapshot.rb
+25
-13
No files found.
lib/shotengai/controllers/customer/products_controller.rb
View file @
0835d741
...
@@ -8,6 +8,10 @@ module Shotengai
...
@@ -8,6 +8,10 @@ module Shotengai
remove_actions
:create
,
:update
,
:destroy
remove_actions
:create
,
:update
,
:destroy
skip_before_action
:buyer_auth
skip_before_action
:buyer_auth
def
default_query
resources
resources
.
alive
end
def
index_query
resources
def
index_query
resources
resources
.
catalog_list_filter
(
::
Catalog
.
where
(
id:
params
[
:catalog_ids
]))
resources
.
catalog_list_filter
(
::
Catalog
.
where
(
id:
params
[
:catalog_ids
]))
end
end
...
...
lib/shotengai/product.rb
View file @
0835d741
...
@@ -58,6 +58,8 @@ module Shotengai
...
@@ -58,6 +58,8 @@ module Shotengai
end
end
end
end
scope
:alive
,
->
{
where
.
not
(
status:
'deleted'
)
}
def
status_zh
def
status_zh
{
{
not_on:
'未上架'
,
not_on:
'未上架'
,
...
...
lib/shotengai/snapshot.rb
View file @
0835d741
...
@@ -16,15 +16,18 @@ module Shotengai
...
@@ -16,15 +16,18 @@ module Shotengai
# type :string(255)
# type :string(255)
# meta :json
# meta :json
# shotengai_series_id :integer
# shotengai_series_id :integer
# shotengai_order_id :integer
# shotengai_order_id
:integer
# created_at :datetime not null
# created_at :datetime not null
# updated_at :datetime not null
# updated_at :datetime not null
#
#
manager_type :string(255)
#
Indexes
#
manager_id :integer
#
#
# index_shotengai_snapshots_on_shotengai_order_id (shotengai_order_id)
# Indexes
# index_shotengai_snapshots_on_shotengai_series_id (shotengai_series_id)
#
# index_shotengai_snapshots_on_type (type)
# index_shotengai_snapshots_on_manager_type_and_manager_id (manager_type,manager_id)
# index_shotengai_snapshots_on_shotengai_order_id (shotengai_order_id)
# index_shotengai_snapshots_on_shotengai_series_id (shotengai_series_id)
# index_shotengai_snapshots_on_type (type)
#
#
class
Snapshot
<
ActiveRecord
::
Base
class
Snapshot
<
ActiveRecord
::
Base
...
@@ -32,8 +35,11 @@ module Shotengai
...
@@ -32,8 +35,11 @@ module Shotengai
validate
:check_spec
,
if: :spec
validate
:check_spec
,
if: :spec
validates
:count
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:count
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validate
:cannot_edit_if_order_is_paid
validate
:cannot_edit
,
if: :order_was_paid
before_destroy
:cannot_edit
,
if: :order_was_paid
validate
:cannot_edit_or_create
,
if: :already_disable?
belongs_to
:shotengai_order
,
foreign_key: :shotengai_order_id
,
belongs_to
:shotengai_order
,
foreign_key: :shotengai_order_id
,
class_name:
'Shotengai::Order'
,
optional:
true
#, touch: true
class_name:
'Shotengai::Order'
,
optional:
true
#, touch: true
belongs_to
:shotengai_cart
,
foreign_key: :shotengai_order_id
,
belongs_to
:shotengai_cart
,
foreign_key: :shotengai_order_id
,
...
@@ -76,7 +82,11 @@ module Shotengai
...
@@ -76,7 +82,11 @@ module Shotengai
end
end
def
already_disable
def
already_disable
series
.
deleted?
series
.
deleted?
||
product
.
on_sale?
.!
end
def
order_was_paid
Shotengai
::
Snapshot
.
find_by_id
(
self
.
id
)
&
.
order_status
.
in?
([
'unpaid'
,
'cart'
,
nil
])
.!
end
end
def
manager
def
manager
...
@@ -138,10 +148,12 @@ module Shotengai
...
@@ -138,10 +148,12 @@ module Shotengai
end
end
# NOTE: Shotengai::Snapshot.find_by_id(self.id) to get the self before changed
# NOTE: Shotengai::Snapshot.find_by_id(self.id) to get the self before changed
def
cannot_edit_if_order_is_paid
def
cannot_edit
unless
Shotengai
::
Snapshot
.
find_by_id
(
self
.
id
)
&
.
order_status
.
in?
([
'unpaid'
,
'cart'
,
nil
])
errors
.
add
(
:id
,
'订单已支付,禁止修改商品快照。'
)
errors
.
add
(
:id
,
'订单已支付,禁止修改商品快照。'
)
end
end
def
cannot_edit_or_create
error
.
add
(
:id
,
'商品已下架,无法购买。'
)
end
end
def
set_manager
def
set_manager
...
...
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