Commit 9d81dd42 by ivan Lan

Add remark to product & series & snapshot

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