|
|
@@ -1,6 +1,10 @@
|
|
|
+
|
|
|
class Product < ActiveRecord::Base
|
|
|
has_paper_trail
|
|
|
self.table_name = 'products'
|
|
|
+ #Thread.current[:current_user] = @current_user
|
|
|
+ scope :active, -> { where(ptype: "cent_sale") }
|
|
|
+ scope :inactive, -> { where(ptype: "direct_sale") }
|
|
|
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
|
|
|
@@ -9,7 +13,6 @@ class Product < ActiveRecord::Base
|
|
|
after_create :after_create
|
|
|
before_save :before_save
|
|
|
after_destroy :del_picture
|
|
|
-
|
|
|
def after_create
|
|
|
#主商品默认关联商品
|
|
|
if self.show_flag
|
|
|
@@ -117,15 +120,18 @@ class Product < ActiveRecord::Base
|
|
|
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
|
|
|
- end
|
|
|
- return ((rate*100).round.to_f/100).to_s + "%"
|
|
|
+ end
|
|
|
+
|
|
|
+ return rate
|
|
|
end
|
|
|
|
|
|
- rails_admin do
|
|
|
+
|
|
|
+ rails_admin do
|
|
|
+
|
|
|
navigation_label '商品管理'
|
|
|
weight -240
|
|
|
-
|
|
|
list do
|
|
|
+ #scopes [:inactive]
|
|
|
filters [:id,:detail,:status,:name]
|
|
|
|
|
|
field :id
|
|
|
@@ -146,11 +152,12 @@ class Product < ActiveRecord::Base
|
|
|
label "现金价格(元)"
|
|
|
formatted_value do # used in form views
|
|
|
value.to_f / 100
|
|
|
+
|
|
|
end
|
|
|
end
|
|
|
#field :robo_balance_price
|
|
|
field :user_sale_price
|
|
|
- #field :buy_price
|
|
|
+ # field :buy_price
|
|
|
#field :gross_interest_rate
|
|
|
field :count
|
|
|
field :recommend
|