Commit 9d81dd42 by ivan Lan

Add remark to product & series & snapshot

parent 267b8da0
...@@ -24,7 +24,7 @@ module Shotengai ...@@ -24,7 +24,7 @@ module Shotengai
def snapshot_params def snapshot_params
params.require(:snapshot).permit( params.require(:snapshot).permit(
:shotengai_series_id, :count :shotengai_series_id, :count, remark_input: [:key, :val]
) )
end end
......
...@@ -31,7 +31,7 @@ module Shotengai ...@@ -31,7 +31,7 @@ module Shotengai
private private
def resource_params def resource_params
params.require(resource_key).permit( params.require(resource_key).permit(
:count, :shotengai_series_id :count, :shotengai_series_id, remark_input: [:key, :val]
) )
end end
......
...@@ -9,7 +9,7 @@ module Shotengai ...@@ -9,7 +9,7 @@ module Shotengai
skip_before_action :buyer_auth skip_before_action :buyer_auth
def default_query resources def default_query resources
resources.alive resources.on_sale
end end
def index_query resources def index_query resources
......
...@@ -85,12 +85,6 @@ module Shotengai ...@@ -85,12 +85,6 @@ module Shotengai
end end
end end
def initialize *arg
super(*arg)
self.remark = Hash[product.remark.map { |k, v| [k, true] }]
self
end
def cut_stock count def cut_stock count
self.stock.eql?(-1) || self.update!(stock: self.stock - count) self.stock.eql?(-1) || self.update!(stock: self.stock - count)
end end
...@@ -103,15 +97,6 @@ module Shotengai ...@@ -103,15 +97,6 @@ module Shotengai
super || {} super || {}
end end
def spec_output
spec.map { |key, val|
{
key: key,
val: val,
}
}
end
private private
# spec 字段 # spec 字段
def check_spec_value def check_spec_value
...@@ -127,8 +112,6 @@ module Shotengai ...@@ -127,8 +112,6 @@ module Shotengai
# product.remark.keys 包含 remark.keys # product.remark.keys 包含 remark.keys
illegal_key = (remark.keys - product.remark.keys) illegal_key = (remark.keys - product.remark.keys)
errors.add(:remark, "非法的关键字, #{illegal_key}") unless illegal_key.empty? errors.add(:remark, "非法的关键字, #{illegal_key}") unless illegal_key.empty?
# illegal_values = remark.reject { |k, v| !!v == v }.keys
# errors.add(:spec, "非法的值,仅允许布尔值。#{illegal_values}") unless illegal_values.empty?
end end
def uniq_spec def uniq_spec
......
...@@ -156,7 +156,8 @@ module Shotengai ...@@ -156,7 +156,8 @@ module Shotengai
def check_remark def check_remark
errors.add(:remark, 'remark 必须是个 Hash') unless remark.is_a?(Hash) errors.add(:remark, 'remark 必须是个 Hash') unless remark.is_a?(Hash)
required_key = series.series.remark.select{ |k, v| v }.keys nullable_key = series.remark.select{ |k, v| v }.keys
required_key = product.remark.keys - nullable_key
# remark 可添加多余字段 # remark 可添加多余字段
errors.add(:remark, '非法的关键字,或关键字缺失') unless (required_key - remark.keys).empty? errors.add(:remark, '非法的关键字,或关键字缺失') unless (required_key - remark.keys).empty?
end end
......
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