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
6072cd27
Commit
6072cd27
authored
Oct 13, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve detail
parent
2ef915a2
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
55 additions
and
44 deletions
+55
-44
shotengai.rb
lib/shotengai.rb
+1
-0
carts_controller.rb
lib/shotengai/controller/customer/carts_controller.rb
+3
-2
orders_controller.rb
lib/shotengai/controller/customer/orders_controller.rb
+2
-2
product_snapshots_controller.rb
...engai/controller/customer/product_snapshots_controller.rb
+2
-2
product_series_controller.rb
...hotengai/controller/merchant/product_series_controller.rb
+4
-4
product_snapshots_controller.rb
...engai/controller/merchant/product_snapshots_controller.rb
+1
-1
products_controller.rb
lib/shotengai/controller/merchant/products_controller.rb
+2
-2
harray.rb
lib/shotengai/harray.rb
+2
-1
json_column.rb
lib/shotengai/json_column.rb
+8
-8
order.rb
lib/shotengai/order.rb
+0
-2
product.rb
lib/shotengai/product.rb
+1
-1
series.rb
lib/shotengai/series.rb
+20
-14
snapshot.rb
lib/shotengai/snapshot.rb
+9
-5
No files found.
lib/shotengai.rb
View file @
6072cd27
...
...
@@ -13,6 +13,7 @@ module Shotengai
autoload
:AASM_DLC
,
'shotengai/aasm_dlc'
autoload
:WebError
,
'shotengai/web_error'
autoload
:JsonColumn
,
'shotengai/json_column'
autoload
:Harray
,
'shotengai/harray'
autoload
:Model
,
'shotengai/model'
module
Controller
...
...
lib/shotengai/controller/customer/carts_controller.rb
View file @
6072cd27
...
...
@@ -23,9 +23,10 @@ module Shotengai
end
def
snapshot_params
remark_value
=
params
.
fetch
(
:snapshot
).
fetch
(
:remark_input
,
nil
)
&
.
permit!
params
.
require
(
:snapshot
).
permit
(
:shotengai_series_id
,
:count
,
remark_input:
[
:key
,
:val
]
)
:shotengai_series_id
,
:count
)
.
merge
(
remark_value:
remark_value
)
end
def
edit_only_unpaid
...
...
lib/shotengai/controller/customer/orders_controller.rb
View file @
6072cd27
...
...
@@ -47,10 +47,10 @@ module Shotengai
end
def
snapshot_params
remark_
input
=
params
.
fetch
(
:snapshot
).
fetch
(
:remark_input
,
nil
)
&
.
map
(
&
:permit!
)
remark_
value
=
params
.
fetch
(
:snapshot
).
fetch
(
:remark_input
,
nil
)
&
.
permit!
params
.
fetch
(
:snapshot
).
permit
(
:shotengai_series_id
,
:count
,
).
merge
(
remark_
input:
remark_input
)
).
merge
(
remark_
value:
remark_value
)
end
def
edit_only_unpaid
...
...
lib/shotengai/controller/customer/product_snapshots_controller.rb
View file @
6072cd27
...
...
@@ -30,8 +30,8 @@ module Shotengai
private
def
resource_params
remark_value
=
params
.
require
(
resource_key
).
fetch
(
:remark_value
,
nil
)
&
.
map
(
&
:permit!
)
info_value
=
params
.
require
(
resource_key
).
fetch
(
:info_value
,
nil
)
&
.
map
(
&
:permit!
)
remark_value
=
params
.
require
(
resource_key
).
fetch
(
:remark_value
,
nil
)
&
.
permit!
info_value
=
params
.
require
(
resource_key
).
fetch
(
:info_value
,
nil
)
&
.
permit!
params
.
require
(
resource_key
).
permit
(
:count
,
:shotengai_series_id
).
merge
({
remark_value:
remark_value
,
info_value:
info_value
})
...
...
lib/shotengai/controller/merchant/product_series_controller.rb
View file @
6072cd27
...
...
@@ -39,10 +39,10 @@ module Shotengai
private
def
resource_params
spec_value
=
params
.
require
(
resource_key
).
fetch
(
:spec_value
,
nil
)
&
.
map
(
&
:permit!
)
info_value
=
params
.
require
(
resource_key
).
fetch
(
:info_value
,
nil
)
&
.
map
(
&
:permit!
)
remark_value
=
params
.
require
(
resource_key
).
fetch
(
:remark_value
,
nil
)
&
.
map
(
&
:permit!
)
meta
=
params
.
require
(
resource_key
).
fetch
(
:meta
,
nil
)
.
try
(
:permit!
)
spec_value
=
params
.
require
(
resource_key
).
fetch
(
:spec_value
,
nil
)
&
.
permit!
info_value
=
params
.
require
(
resource_key
).
fetch
(
:info_value
,
nil
)
&
.
permit!
remark_value
=
params
.
require
(
resource_key
).
fetch
(
:remark_value
,
nil
)
&
.
permit!
meta
=
params
.
require
(
resource_key
).
fetch
(
:meta
,
nil
)
&
.
permit!
# ????????!!!!!, spec_value: [:key, :val] 一样的输出值 却在test报错???
# QUESTION: WARNING: 文档bug吧?????
params
.
require
(
resource_key
).
permit
(
...
...
lib/shotengai/controller/merchant/product_snapshots_controller.rb
View file @
6072cd27
...
...
@@ -22,7 +22,7 @@ module Shotengai
private
def
resource_params
remark_value
=
params
.
require
(
resource_key
).
fetch
(
:remark_value
,
nil
)
&
.
map
(
&
:permit!
)
remark_value
=
params
.
require
(
resource_key
).
fetch
(
:remark_value
,
nil
)
&
.
permit!
params
.
require
(
resource_key
).
permit
(
:revised_amount
).
merge
({
remark_value:
remark_value
})
...
...
lib/shotengai/controller/merchant/products_controller.rb
View file @
6072cd27
...
...
@@ -66,8 +66,8 @@ module Shotengai
spec_template
=
params
.
require
(
resource_key
).
fetch
(
:spec_template
,
nil
)
&
.
map
(
&
:permit!
)
remark_template
=
params
.
require
(
resource_key
).
fetch
(
:remark_template
,
nil
)
&
.
map
(
&
:permit!
)
info_template
=
params
.
require
(
resource_key
).
fetch
(
:info_template
,
nil
)
&
.
map
(
&
:permit!
)
detail
=
params
.
require
(
resource_key
).
fetch
(
:detail
,
nil
)
.
try
(
:permit!
)
meta
=
params
.
require
(
resource_key
).
fetch
(
:meta
,
nil
)
.
try
(
:permit!
)
detail
=
params
.
require
(
resource_key
).
fetch
(
:detail
,
nil
)
&
.
permit!
meta
=
params
.
require
(
resource_key
).
fetch
(
:meta
,
nil
)
&
.
permit!
# NOTE: :catalog_list is a default catalog list for template example, maybe should move it to the template controller, but it need add controller template for every controller
params
.
require
(
resource_key
).
permit
(
:title
,
:default_series_id
,
...
...
lib/shotengai/harray.rb
View file @
6072cd27
...
...
@@ -9,7 +9,8 @@ module Shotengai
end
def
val_at
key
self
.
bsearch
{
|
obj
|
obj
[
'key'
].
eql?
(
key
)
}
&
.
[
](
'val'
)
self
.
each
{
|
obj
|
return
obj
[
'val'
]
if
obj
[
'key'
].
eql?
(
key
)
}
nil
end
end
end
lib/shotengai/json_column.rb
View file @
6072cd27
...
...
@@ -31,25 +31,25 @@ module Shotengai
# like meta, detail these json using for code development
end
def
generate_hash_template_column_for
names
def
generate_hash_template_column_for
*
names
names
.
each
do
|
name
|
class_eval
%Q{
def
#{
name
}
_
valu
e
Shotengai::Harray.new(super())
def
#{
name
}
_
templat
e
Shotengai::Harray.new(super()
|| []
)
end
def
#{
name
}
_
valu
e= val
raise Shotengai::WebError.new('
#{
name
}
_val 必须是个 Array'
)
, -1 , 401) unless val.nil? || Array === val
def
#{
name
}
_
templat
e= val
raise Shotengai::WebError.new('
#{
name
}
_val 必须是个 Array', -1 , 401) unless val.nil? || Array === val
super(val)
end
}
end
end
def
generate_hash_value_column_for
names
,
options
=
{}
def
generate_hash_value_column_for
*
names
,
delegate_template_to:
nil
names
.
each
do
|
name
|
class_eval
%Q{
delegate :
#{
name
}
_template, to: :
#{
options
[
:delegate_template_to
]
}
if self.respond_to?(
#{
options
[
:delegate_template_to
]
}
)
delegate :
#{
name
}
_template, to: :
#{
delegate_template_to
}
def
#{
name
}
{
template: self.
#{
name
}
_template,
...
...
@@ -59,7 +59,7 @@ module Shotengai
end
def
#{
name
}
_value= val
raise Shotengai::WebError.new('
#{
name
}
_val 必须是个 Hash'
)
, -1 , 401) unless val.nil? || Hash === val
raise Shotengai::WebError.new('
#{
name
}
_val 必须是个 Hash', -1 , 401) unless val.nil? || Hash === val
super(val)
end
}
...
...
lib/shotengai/order.rb
View file @
6072cd27
...
...
@@ -38,8 +38,6 @@ module Shotengai
after_create
:set_seq
custom_hash_columns
:spec
include
AASM_DLC
aasm
column: :status
do
state
:unpaid
,
initial:
true
...
...
lib/shotengai/product.rb
View file @
6072cd27
...
...
@@ -31,7 +31,7 @@ module Shotengai
require
'acts-as-taggable-on'
self
.
table_name
=
'shotengai_products'
generate_hash_template_column_for
[
:spec
,
:info
,
:remark
]
generate_hash_template_column_for
:spec
,
:info
,
:remark
belongs_to
:manager
,
polymorphic:
true
,
optional:
true
#, touch: true
...
...
lib/shotengai/series.rb
View file @
6072cd27
...
...
@@ -23,17 +23,19 @@ module Shotengai
class
Series
<
Shotengai
::
Model
self
.
table_name
=
'shotengai_series'
validates_presence_of
:spec_value
,
unless: :
product_
spec_template_empty?
validates_presence_of
:spec_value
,
unless: :spec_template_empty?
validates_presence_of
:price
validate
:check_spec_value
,
unless: :product_spec_template_empty?
# Using validates_uniqueness_of do not work if the order of Hash is diff
validate
:uniq_spec_value
,
unless: :product_spec_template_empty?
validate
:only_one_series
,
if: :product_spec_template_empty?
# validate spec_value
validate
:check_spec_value
,
unless: :spec_template_empty?
## Using validates_uniqueness_of do not work if the order of Hash is diff
validate
:uniq_spec_value
,
unless: :spec_template_empty?
validate
:only_one_series
,
if: :spec_template_empty?
validate
:check_remark_value
# validate remark
validate
:check_remark_value
,
unless: :remark_template_empty?
generate_hash_value_column_for
[
:spec
,
:info
,
:remark
]
,
delegate_template_to: :product
generate_hash_value_column_for
:spec
,
:info
,
:remark
,
delegate_template_to: :product
delegate
:title
,
:detail
,
:banners
,
:cover_image
,
:status
,
:status_zh
,
:manager
,
to: :product
...
...
@@ -44,7 +46,7 @@ module Shotengai
scope
:query_spec_value_with_product
,
->
(
val
,
product
)
{
if
val
.
keys
.
sort
==
product
.
spec_template
.
keys
.
sort
keys
=
[];
values
=
[]
val
.
map
{
|
k
,
v
|
keys
<<
"spec->'$.
\"
#{
k
}
\"
' = ? "
;
values
<<
v
}
val
.
map
{
|
k
,
v
|
keys
<<
"spec
_value
->'$.
\"
#{
k
}
\"
' = ? "
;
values
<<
v
}
where
(
product:
product
).
where
(
keys
.
join
(
' and '
),
*
values
)
else
self
.
none
...
...
@@ -104,15 +106,19 @@ module Shotengai
private
# spec 字段
def
product_spec_template_empty?
product
.
spec_template
.
empty?
def
spec_template_empty?
spec_template
.
empty?
&&
spec_value
.
nil?
# 当且仅当二者都为空才跳过验证
end
def
remark_template_empty?
remark_template
.
empty?
&&
remark_value
.
nil?
# 当且仅当二者都为空才跳过验证
end
def
check_spec_value
errors
.
add
(
:spec_value
,
'spec_value 必须是个 Hash'
)
unless
spec_value
.
is_a?
(
Hash
)
errors
.
add
(
:spec_value
,
'非法的关键字,或关键字缺失'
)
unless
(
product
.
spec_
valu
e
.
keys
-
spec_value
.
keys
).
empty?
errors
.
add
(
:spec_value
,
'非法的关键字,或关键字缺失'
)
unless
(
product
.
spec_
templat
e
.
keys
-
spec_value
.
keys
).
empty?
illegal_values
=
{}
spec_value
.
each
{
|
key
,
value
|
illegal_values
[
key
]
=
value
unless
value
.
in?
(
product
.
spec_template
.
val_at
(
key
))
}
spec_value
.
each
{
|
key
,
value
|
illegal_values
[
key
]
=
value
unless
value
.
in?
(
product
.
spec_template
.
val_at
(
key
)
||
[]
)
}
errors
.
add
(
:spec_value
,
"非法的值,
#{
illegal_values
}
"
)
unless
illegal_values
.
empty?
end
...
...
@@ -126,10 +132,10 @@ module Shotengai
errors
.
add
(
:spec_value
,
"无规格系列仅允许存在一项"
)
unless
product
.
series
.
empty?
end
def
check_remark
def
check_remark
_value
errors
.
add
(
:remark_value
,
'remark_value 必须是个 Hash'
)
unless
remark_value
.
is_a?
(
Hash
)
# product.remark_value.keys 包含 remark_value.keys
illegal_key
=
(
remark_value
.
keys
-
product
.
remark_template
.
keys
)
illegal_key
=
(
remark_value
.
keys
-
product
.
remark_template
&
.
keys
)
errors
.
add
(
:remark_value
,
"非法的关键字,
#{
illegal_key
}
"
)
unless
illegal_key
.
empty?
end
end
...
...
lib/shotengai/snapshot.rb
View file @
6072cd27
...
...
@@ -33,10 +33,10 @@ module Shotengai
class
Snapshot
<
Shotengai
::
Model
self
.
table_name
=
'shotengai_snapshots'
validate
:check_spec_value
validate
:check_remark_value
validate
:check_remark_value
,
unless: :remark_template_empty?
validates
:count
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
generate_hash_value_column_for
[
:spec
,
:info
,
:remark
]
,
delegate_template_to: :series
generate_hash_value_column_for
:spec
,
:info
,
:remark
,
delegate_template_to: :series
column_has_children
:meta
,
children:
[
'product'
,
'series'
],
as: :snapshot
column_has_children
:info_value
,
children:
[
'series'
],
as: :snapshot
...
...
@@ -77,10 +77,10 @@ module Shotengai
# 支付前 信息 delegate to series
%i{
original_price price spec banners
original_price price spec
_value
banners
cover_image detail title
}
.
each
do
|
column
|
define_method
(
column
)
{
super
||
self
.
series
.
send
(
column
)
}
define_method
(
column
)
{
super
()
||
self
.
series
.
send
(
column
)
}
end
def
already_disable
...
...
@@ -149,7 +149,11 @@ module Shotengai
# spec 字段
def
check_spec_value
errors
.
add
(
:spec_value
,
'spec 与 所给系列不符。'
)
unless
spec_value
==
series
.
spec_value
errors
.
add
(
:spec_value
,
'spec 与 所给系列不符。'
)
unless
spec_value
.
nil?
||
spec_value
==
series
.
spec_value
end
def
remark_template_empty?
remark_template
.
empty?
&&
remark_value
.
nil?
# 当且仅当二者都为空才跳过验证
end
def
check_remark_value
...
...
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