|
|
@@ -5,22 +5,22 @@ class Product < ActiveRecord::Base
|
|
|
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 :gross_interest_rate
|
|
|
+ after_find :get_size_enum
|
|
|
TYPE_ENUM = [["直营","direct_sale"]]
|
|
|
#["代销","user_sale"]
|
|
|
|
|
|
SIZE_ENUM = []
|
|
|
def get_size_enum
|
|
|
-=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)
|
|
|
+ if SIZE_ENUM.length ==0
|
|
|
+ @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
|
|
|
-=end
|
|
|
return "--"
|
|
|
end
|
|
|
IMG_STORE_PATH = "product"
|
|
|
@@ -50,6 +50,7 @@ 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")
|
|
|
@@ -58,6 +59,7 @@ class Product < ActiveRecord::Base
|
|
|
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
|