Переглянути джерело

add confirm on balance order

abiao 4 роки тому
батько
коміт
d37534fb87

+ 111 - 0
app/models/balance_promotion.rb

@@ -0,0 +1,111 @@
+class BalancePromotion < ActiveRecord::Base
+    has_paper_trail
+    self.table_name = "balance_promotions"
+    validates :begin_time,:end_time,:name, presence: true
+
+    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
+
+    
+    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 :min_total do
+            label "充值最小金额(元)"
+            formatted_value do # used in form views
+              value.to_f / 100
+            end
+          end
+          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 :min_total do
+            label "订单最小金额(元)"
+            formatted_value do # used in form views
+              value.to_f / 100
+            end
+          end
+          field :send_prodcut1
+          field :send_prodcut2
+          field :send_prodcut3
+          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 :send_prod1
+          field :send_nums1
+          field :send_prod2
+          field :send_nums2
+          field :send_prod3
+          field :send_nums3
+          field :cash
+          field :cent
+          field :is_enable
+        end
+    end
+end

+ 11 - 11
app/models/promotion.rb

@@ -8,7 +8,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.nums1)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -17,7 +17,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.nums2)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -27,7 +27,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.nums3)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -37,7 +37,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.nums4)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -47,7 +47,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.nums5)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -56,7 +56,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.send_nums1)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -65,7 +65,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.send_nums2)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -75,7 +75,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.send_nums3)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -86,7 +86,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.send_nums4)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -96,7 +96,7 @@ class Promotion < ActiveRecord::Base
       if !prd1.blank?
         return format("%s-%d",prd1.name,self.send_nums5)
       else
-        return "不存在"
+        return "--"
       end
     end
 
@@ -105,7 +105,7 @@ class Promotion < ActiveRecord::Base
 
     rails_admin do 
 
-        navigation_label '商品管理'
+        navigation_label '系统配置'
         weight -100
 
         list do 

+ 24 - 0
config/locales/models/balance_promotion.yml

@@ -0,0 +1,24 @@
+zh-CN:
+  activerecord:
+    models:
+      balance_promotion: 充值促销管理
+    attributes:
+      balance_promotion: 
+        name: 促销名称
+        begin_time: 开始时间
+        end_time:  结束时间
+        min_total: 充值最小金额(单位:分)
+        send_prod1: 赠品1ID
+        send_nums1: 赠品1数量
+        send_prod2: 赠品2ID
+        send_nums2: 赠品2数量
+        send_prod3: 赠品3ID
+        send_nums3: 赠品3数量
+        is_enable: 是否启用
+        send_prodcut1: 赠品1
+        send_prodcut2: 赠品2
+        send_prodcut3: 赠品3
+        cash: 赠代办费(分)
+        cent: 赠积分(分)
+        created_at: 创建时间
+        updated_at: 更新时间

+ 43 - 0
db/migrate/20210304114641_create_balance_promotions.rb

@@ -0,0 +1,43 @@
+# encoding:utf-8
+class CreateBalancePromotions < ActiveRecord::Migration
+  def up
+    #充值促销
+    create_table :balance_promotions do |t|
+      # 促销名称
+      t.column :name, :string,:limit => 128
+      #开始时间
+      t.column :begin_time,:datetime
+      #结束时间
+      t.column :end_time,:datetime
+      # 最小金额
+      t.column :min_total, :integer, :limit => 11, :default => 0
+      # 赠品1
+      t.column :send_prod1, :integer, :limit => 11, :default => 0
+      # 数量1
+      t.column :send_nums1, :integer, :limit => 11, :default => 0
+      # 赠品2
+      t.column :send_prod2, :integer, :limit => 11, :default => 0
+      # 赠品数量2
+      t.column :send_nums2, :integer, :limit => 11, :default => 0
+      # 赠品3
+      t.column :send_prod3, :integer, :limit => 11, :default => 0
+      # 赠品数量3
+      t.column :send_nums3, :integer, :limit => 11, :default => 0
+      # 状态
+      t.column :is_enable, :boolean, :default=>1
+      # 赠代办金
+      t.column :cash, :integer, :limit => 11, :default => 0
+      # 赠积分
+      t.column :cent, :integer, :limit => 11, :default => 0
+      t.timestamps
+    end
+    add_index :balance_promotions, :wx_user_id
+    add_index :balance_promotions, :product_id
+  end
+
+  def down
+  	drop_table :balance_promotions
+  end
+end
+
+