Browse Source

Merge branch 'develop' into feature/docker_branch

* develop: (108 commits)
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  model add scope
  ...
abiao 4 years ago
parent
commit
a96452a995
2 changed files with 27 additions and 7 deletions
  1. 14 1
      app/models/ability.rb
  2. 13 6
      app/models/product.rb

+ 14 - 1
app/models/ability.rb

@@ -1,5 +1,6 @@
 class Ability
   include CanCan::Ability
+  D_ENUM =  []
 
   def initialize(user)
     # Define abilities for the passed in user here. For example:
@@ -11,6 +12,7 @@ class Ability
     #     can :read, :all
     #   end
     if user
+
       can :dashboard # allow access to dashboard
       can :access, :rails_admin # only allow admin users to access Rails Admin
       cannot :history, :all
@@ -27,11 +29,22 @@ class Ability
         # can :update, :all
       else
         user.permissions.each do |permission|
-           eval "can :#{permission.can}, #{permission.model}"
+          if permission.model=="Order"
+            D_ENUM.clear
+              departs = DepartRecord.find_by_sql("select id from depart_records ")
+              departs.each do |dep|
+                D_ENUM.push(dep.id)
+              end
+            can :update, Order, :depart => D_ENUM
+            can :read, Order, :depart => D_ENUM
+          else
+            eval "can :#{permission.can}, #{permission.model}"
+           end
         end 
                      
         can :update, AdminUser, :id => user.id
         can :read, AdminUser, :id => user.id
+
         cannot :history, :all
         # cannot :destroy, ChannelQrcode        
         # cannot :refund_at_once, Project

+ 13 - 6
app/models/product.rb

@@ -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