Sfoglia il codice sorgente

Merge branch 'develop'

* develop: (110 commits)
  add promotion products
  add promotion products
  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 anni fa
parent
commit
a61b452532

+ 13 - 0
.gitignore

@@ -0,0 +1,13 @@
+
+.idea
+.cache
+.DS_Store
+
+
+
+/build.sh
+/Dockerfile
+/run_unicorn_docker.sh
+/config/version.json
+/docker-compose.yml
+./log/

+ 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

+ 57 - 0
app/models/promotion.rb

@@ -32,6 +32,25 @@ class Promotion < ActiveRecord::Base
     end
 
 
+    def prodcut4
+      prd1 = Product.where("id = ?", self.prod4).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.name,self.nums4)
+      else
+        return "不存在"
+      end
+    end
+
+
+    def prodcut5
+      prd1 = Product.where("id = ?", self.prod5).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.name,self.nums5)
+      else
+        return "不存在"
+      end
+    end
+
     def send_prodcut1
       prd1 = Product.where("id = ?", self.send_prod1).first
       if !prd1.blank?
@@ -60,6 +79,27 @@ class Promotion < ActiveRecord::Base
       end
     end
 
+
+
+    def send_prodcut4
+      prd1 = Product.where("id = ?", self.send_prod4).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.name,self.send_nums4)
+      else
+        return "不存在"
+      end
+    end
+
+
+    def send_prodcut5
+      prd1 = Product.where("id = ?", self.send_prod5).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.name,self.send_nums5)
+      else
+        return "不存在"
+      end
+    end
+
     TYPE_ENUM = [["普通",0],["秒杀",1],["店长",2]]
 
 
@@ -97,9 +137,14 @@ class Promotion < ActiveRecord::Base
           field :prodcut1
           field :prodcut2
           field :prodcut3
+          field :prodcut4
+          field :prodcut5
           field :send_prodcut1
           field :send_prodcut2
           field :send_prodcut3
+          field :send_prodcut4
+          field :send_prodcut5
+
           field :cash do
             label "代办金(元)"
             formatted_value do # used in form views
@@ -145,9 +190,13 @@ class Promotion < ActiveRecord::Base
           field :prodcut1
           field :prodcut2
           field :prodcut3
+          field :prodcut4
+          field :prodcut5
           field :send_prodcut1
           field :send_prodcut2
           field :send_prodcut3
+          field :send_prodcut4
+          field :send_prodcut5
           field :is_enable
           field :cash
           field :cent
@@ -176,12 +225,20 @@ class Promotion < ActiveRecord::Base
           field :nums2
           field :prod3
           field :nums3
+          field :prod4
+          field :nums4
+          field :prod5
+          field :nums5
           field :send_prod1
           field :send_nums1
           field :send_prod2
           field :send_nums2
           field :send_prod3
           field :send_nums3
+          field :send_prod4
+          field :send_nums4
+          field :send_prod5
+          field :send_nums5
           field :cash
           field :cent
           field :is_enable

+ 3 - 3
config/database.yml

@@ -16,7 +16,7 @@ development:
   pool: 5
   username: root
   password: fohow123!@#
-  host: 127.0.0.1
+  host: 47.52.141.54
 
 # Warning: The database defined as "test" will be erased and
 # re-generated from your development database when you run "rake".
@@ -25,11 +25,11 @@ test:
   adapter: mysql2
   encoding: utf8
   reconnect: false
-  database: org_db
+  database: test_fohow
   pool: 5
   username: root
   password: fohow123!@#
-  host: 127.0.0.1
+  host: 47.52.141.54
 
 production:
   adapter: mysql2

+ 12 - 0
config/locales/models/promotion.yml

@@ -18,19 +18,31 @@ zh-CN:
         nums2: 买品2数量
         prod3: 买品3ID3
         nums3: 买品3数量
+        prod4: 买品4ID3
+        nums4: 买品4数量
+        prod5: 买品5ID3
+        nums5: 买品5数量
         send_prod1: 赠品1ID
         send_nums1: 赠品1数量
         send_prod2: 赠品2ID
         send_nums2: 赠品2数量
         send_prod3: 赠品3ID
         send_nums3: 赠品3数量
+        send_prod4: 赠品4ID
+        send_nums4: 赠品4数量
+        send_prod5: 赠品5ID
+        send_nums5: 赠品5数量
         is_enable: 是否启用
         prodcut1: 买品1
         prodcut2: 买品2
         prodcut3: 买品3
+        prodcut4: 买品4
+        prodcut5: 买品5
         send_prodcut1: 赠品1
         send_prodcut2: 赠品2
         send_prodcut3: 赠品3
+        send_prodcut4: 赠品3
+        send_prodcut5: 赠品3
         cash: 赠代办费(分)
         cent: 赠积分(分)
         created_at: 创建时间

+ 26 - 0
db/migrate/20210203114699_add_products.rb

@@ -0,0 +1,26 @@
+# This migration and CreateVersionAssociations provide the necessary
+# schema for tracking associations.
+class AddProducts < ActiveRecord::Migration
+  def up
+    add_column :promotions, :prod4, :integer
+    add_column :promotions, :nums4, :integer
+    add_column :promotions, :prod5, :integer
+    add_column :promotions, :nums5, :integer
+    add_column :promotions, :send_prod4, :integer
+    add_column :promotions, :send_nums4, :integer
+    add_column :promotions, :send_prod5, :integer
+    add_column :promotions, :send_nums5, :integer
+
+  end
+
+  def down
+    remove_column :promotions, :prod4
+    remove_column :promotions, :nums4
+    remove_column :promotions, :prod5
+    remove_column :promotions, :nums5
+    remove_column :promotions, :send_prod4
+    remove_column :promotions, :send_nums4
+    remove_column :promotions, :send_prod5
+    remove_column :promotions, :send_nums5
+  end
+end