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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
4 deletions
+22
-4
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
+16
-4
No files found.
lib/shotengai/controllers/customer/products_controller.rb
View file @
0835d741
...
...
@@ -8,6 +8,10 @@ module Shotengai
remove_actions
:create
,
:update
,
:destroy
skip_before_action
:buyer_auth
def
default_query
resources
resources
.
alive
end
def
index_query
resources
resources
.
catalog_list_filter
(
::
Catalog
.
where
(
id:
params
[
:catalog_ids
]))
end
...
...
lib/shotengai/product.rb
View file @
0835d741
...
...
@@ -58,6 +58,8 @@ module Shotengai
end
end
scope
:alive
,
->
{
where
.
not
(
status:
'deleted'
)
}
def
status_zh
{
not_on:
'未上架'
,
...
...
lib/shotengai/snapshot.rb
View file @
0835d741
...
...
@@ -19,9 +19,12 @@ module Shotengai
# shotengai_order_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# manager_type :string(255)
# manager_id :integer
#
# Indexes
#
# 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)
...
...
@@ -32,7 +35,10 @@ module Shotengai
validate
:check_spec
,
if: :spec
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
,
class_name:
'Shotengai::Order'
,
optional:
true
#, touch: true
...
...
@@ -76,7 +82,11 @@ module Shotengai
end
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
def
manager
...
...
@@ -138,10 +148,12 @@ module Shotengai
end
# NOTE: Shotengai::Snapshot.find_by_id(self.id) to get the self before changed
def
cannot_edit_if_order_is_paid
unless
Shotengai
::
Snapshot
.
find_by_id
(
self
.
id
)
&
.
order_status
.
in?
([
'unpaid'
,
'cart'
,
nil
])
def
cannot_edit
errors
.
add
(
:id
,
'订单已支付,禁止修改商品快照。'
)
end
def
cannot_edit_or_create
error
.
add
(
:id
,
'商品已下架,无法购买。'
)
end
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