Bladeren bron

add balance promotion shop promotion

abiao 4 jaren geleden
bovenliggende
commit
8b225e00d8

+ 1 - 1
app/models/balance_promotion.rb

@@ -3,7 +3,7 @@ class BalancePromotion < ActiveRecord::Base
     self.table_name = "balance_promotions"
     belongs_to :depart_record, :foreign_key => :depart
 
-    validates :begin_time,:end_time,:name,:depart,:min_total,:max_total, presence: true
+    validates :begin_time,:end_time,:name,:min_total,:max_total, presence: true
     validate :product_validation
     attr_accessor :get_depart_enum
 

+ 190 - 0
app/models/shop_promotion.rb

@@ -0,0 +1,190 @@
+class ShopPromotion < ActiveRecord::Base
+    has_paper_trail
+    self.table_name = "shop_promotions"
+    belongs_to :depart_record, :foreign_key => :depart
+
+    validates :begin_time,:end_time,:name,:total, presence: true
+    validate :product_validation
+    attr_accessor :get_depart_enum
+
+    def product_validation
+      if self.send_prod1 > 0
+        prd1 = Product.where("id = ?", self.send_prod1).first
+        if prd1.blank?
+          self.errors.add(:send_prod1,"赠品1不存在,请重新填写。")
+        end
+      end
+
+      if self.send_prod2 > 0
+        prd2 = Product.where("id = ?", self.send_prod2).first
+        if prd2.blank?
+          self.errors.add(:send_prod2,"赠品2不存在,请重新填写。")
+        end
+      end
+
+
+      if self.send_prod3 > 0
+        prd3 = Product.where("id = ?", self.send_prod3).first
+        if prd3.blank?
+          self.errors.add(:send_prod3,"赠品3不存在,请重新填写。")
+        end
+      end
+
+    end
+    def send_prodcut1
+      prd1 = Product.where("id = ?", self.send_prod1).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.name,self.send_nums1)
+      else
+        return "--"
+      end
+    end
+
+    def send_prodcut2
+      prd1 = Product.where("id = ?", self.send_prod2).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.name,self.send_nums2)
+      else
+        return "--"
+      end
+    end
+
+    def send_prodcut3
+      prd1 = Product.where("id = ?", self.send_prod3).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.name,self.send_nums3)
+      else
+        return "--"
+      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
+
+    DEPART_ENUM =  []
+    def get_depart_enum
+      DEPART_ENUM.clear
+      if DEPART_ENUM.length ==0
+        departAttrs = DepartRecord.where("1 ").order("id desc")
+        departAttrs.each do |attr|
+            a=[attr.name,attr.id]
+            DEPART_ENUM.push(a)
+          end
+      end
+      return DEPART_ENUM
+    end
+
+    
+    rails_admin do 
+
+        navigation_label '促销管理'
+        weight -100
+
+        list do 
+          filters [:id,:name,:begin_time,:end_time]
+          field :id
+          field :name
+          field :begin_time
+          field :end_time
+          field :total do
+            label "充值金额(元)"
+            formatted_value do # used in form views
+              value.to_f / 100
+            end
+          end
+          field :depart_record
+          field :send_prodcut1
+          field :send_prodcut1
+          field :send_prodcut2
+          field :send_prodcut3
+          field :cash do
+            label "代办金(元)"
+            formatted_value do # used in form views
+              value.to_f / 100
+            end
+          end
+          field :cent do
+            label "积分(元)"
+            formatted_value do # used in form views
+              value.to_f / 100
+            end
+          end
+          field :is_enable
+          field :created_at
+        end
+
+
+        show do
+          field :id      
+          field :name
+          field :begin_time
+          field :end_time
+      
+          field :total do
+            label "充值金额(元)"
+            formatted_value do # used in form views
+              value.to_f / 100
+            end
+          end
+
+          field :depart_record
+          field :send_prodcut1
+          field :send_prodcut2
+          field :send_prodcut3
+          field :send_prodcut4
+          field :send_prodcut5
+          field :is_enable
+          field :cash
+          field :cent
+          field :created_at
+          field :created_at
+          field :updated_at
+        end
+
+        edit do
+          field :name
+          field :begin_time
+          field :end_time
+          field :min_total
+          field :max_total
+          field :is_more
+=begin
+          field :depart, :enum do
+            enum do
+              bindings[:object].get_depart_enum
+            end
+          end
+=end
+          field :depart_record
+          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
+        end
+    end
+end

+ 1 - 1
config/locales/models/balance_promotion.yml

@@ -1,7 +1,7 @@
 zh-CN:
   activerecord:
     models:
-      balance_promotion: 充值促销管理
+      balance_promotion: 充值促销配置
     attributes:
       balance_promotion: 
         name: 促销名称

+ 32 - 0
config/locales/models/shop_promotion.yml

@@ -0,0 +1,32 @@
+zh-CN:
+  activerecord:
+    models:
+      shop_promotion: 店长促销配置
+    attributes:
+      shop_promotion: 
+        name: 促销名称
+        begin_time: 开始时间
+        end_time:  结束时间
+        total: 充值金额
+        depart: 部门
+        depart_record: 部门
+        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: 是否启用
+        send_prodcut1: 赠品1
+        send_prodcut2: 赠品2
+        send_prodcut3: 赠品3
+        send_prodcut4: 赠品4
+        send_prodcut5: 赠品5
+        cash: 赠代办费(分)
+        cent: 赠积分(分)
+        created_at: 创建时间
+        updated_at: 更新时间