|
|
@@ -4,8 +4,8 @@ class Product < ActiveRecord::Base
|
|
|
belongs_to :product_cat, :foreign_key => :category_id
|
|
|
belongs_to :merchant, :foreign_key => :merchant_id
|
|
|
validates :name,:buy_price,:price,:category_id,:count,:robo_balance_price, presence: true
|
|
|
- attr_accessor :v_share_img,:get_size_enum,:gross_interest_rate
|
|
|
- after_find :get_size_enum
|
|
|
+ attr_accessor :v_share_img,:get_size_enum,:gross_interest_rate,:get_color_enum
|
|
|
+ after_find :get_size_enum,get_color_enum
|
|
|
TYPE_ENUM = [["直营","direct_sale"]]
|
|
|
#["代销","user_sale"]
|
|
|
SIZE_ENUM = []
|
|
|
@@ -22,8 +22,42 @@ class Product < ActiveRecord::Base
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
+
|
|
|
+ COLOR_ENUM = []
|
|
|
+ def get_color_enum
|
|
|
+ COLOR_ENUM.clear
|
|
|
+ if COLOR_ENUM.length ==0
|
|
|
+ @Color = ProductAttrConfig.where("product_id=? and size_type='color'",self.id).first
|
|
|
+ if !@Color.blank?
|
|
|
+ @productAttrs = ProductAttr.where("attr_key_id=?",@Color.id).order("recommend desc")
|
|
|
+ @productAttrs.each do |attr|
|
|
|
+ a=[attr.name,attr.id]
|
|
|
+ COLOR_ENUM.push(a)
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
IMG_STORE_PATH = "product"
|
|
|
|
|
|
+ def size_name
|
|
|
+ linkSize = ProductAttr.where("id = ?", self.size_id).first
|
|
|
+ if !linkSize.blank?
|
|
|
+ return linkSize.name
|
|
|
+ else
|
|
|
+ return "不存在"
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ def color_name
|
|
|
+ linkColor = ProductAttr.where("id = ?", self.color_id).first
|
|
|
+ if !linkColor.blank?
|
|
|
+ return linkColor.name
|
|
|
+ else
|
|
|
+ return "不存在"
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
def v_share_img=file
|
|
|
unless file.blank?
|
|
|
file_name = "#{UUID.new.generate[0...8].downcase}.jpg"
|
|
|
@@ -49,16 +83,6 @@ class Product < ActiveRecord::Base
|
|
|
end
|
|
|
|
|
|
def gross_interest_rate
|
|
|
-=begin
|
|
|
- @Size = ProductAttrConfig.where("product_id=? and size_type='size'",self.id).first
|
|
|
- if !@Size.blank?
|
|
|
- @productAttrs = ProductAttr.where("attr_key_id=?",@Size.id).order("recommend desc")
|
|
|
- @productAttrs.each do |attr|
|
|
|
- a=[attr.name,attr.id]
|
|
|
- SIZE_ENUM.push(a)
|
|
|
- end
|
|
|
- end
|
|
|
-=end
|
|
|
rate = 0
|
|
|
if self.buy_price != 0 && self.price != 0
|
|
|
rate = (( self.price.to_f - self.buy_price.to_f )/self.buy_price.to_f)*100
|
|
|
@@ -118,13 +142,8 @@ class Product < ActiveRecord::Base
|
|
|
end
|
|
|
field :is_only_new
|
|
|
field :video_state
|
|
|
- # field :get_size_enum
|
|
|
- field :size_id, :enum do
|
|
|
- enum do
|
|
|
- SIZE_ENUM
|
|
|
- end
|
|
|
- end
|
|
|
- field :color_id
|
|
|
+ field :size_name
|
|
|
+ field :color_name
|
|
|
field :relate_product_id
|
|
|
field :show_flag
|
|
|
field :created_at
|
|
|
@@ -182,8 +201,8 @@ class Product < ActiveRecord::Base
|
|
|
field :no_delivery_area
|
|
|
field :video_state
|
|
|
field :video_url
|
|
|
- field :size_id
|
|
|
- field :color_id
|
|
|
+ field :size_name
|
|
|
+ field :color_name
|
|
|
field :relate_product_id
|
|
|
field :show_flag
|
|
|
field :created_at
|
|
|
@@ -232,7 +251,11 @@ class Product < ActiveRecord::Base
|
|
|
SIZE_ENUM
|
|
|
end
|
|
|
end
|
|
|
- field :color_id
|
|
|
+ field :color_id, :enum do
|
|
|
+ enum do
|
|
|
+ COLOR_ENUM
|
|
|
+ end
|
|
|
+ end
|
|
|
field :relate_product_id
|
|
|
field :show_flag
|
|
|
end
|