Procházet zdrojové kódy

增加促销活动

abiao před 5 roky
rodič
revize
fd8edaffb7

+ 143 - 0
app/models/promotion.rb

@@ -0,0 +1,143 @@
+class Promotion < ActiveRecord::Base
+    has_paper_trail
+    self.table_name = "promotions"
+    validates :begin_time,:end_time,:name, presence: true
+
+    def prodcut1
+      prd1 = Product.where("id = ?", self.prod1).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.Name,self.nums1)
+      else
+        return "不存在"
+      end
+    end
+
+    def prodcut2
+      prd1 = Product.where("id = ?", self.prod1).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.Name,self.nums1)
+      else
+        return "不存在"
+      end
+    end
+
+
+    def prodcut3
+      prd1 = Product.where("id = ?", self.prod1).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.Name,self.nums1)
+      else
+        return "不存在"
+      end
+    end
+
+
+    def send_prodcut1
+      prd1 = Product.where("id = ?", self.prod1).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.Name,self.nums1)
+      else
+        return "不存在"
+      end
+    end
+
+    def send_prodcut2
+      prd1 = Product.where("id = ?", self.prod1).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.Name,self.nums1)
+      else
+        return "不存在"
+      end
+    end
+
+
+    def send_prodcut3
+      prd1 = Product.where("id = ?", self.prod1).first
+      if !prd1.blank?
+        return format("%s-%d",prd1.Name,self.nums1)
+      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 :is_first
+          field :is_more
+          field :min_total do
+            label "订单最小金额(元)"
+            formatted_value do # used in form views
+              value.to_f / 100
+            end
+          end
+          field :max_total do
+            label "订单最大金额(元)"
+            formatted_value do # used in form views
+              value.to_f / 100
+            end
+          end
+          field :prodcut1
+          field :prodcut2
+          field :prodcut3
+          field :send_prodcut1
+          field :send_prodcut2
+          field :send_prodcut3
+          field :is_enable
+          field :created_at
+        end
+
+
+        show do
+          field :id      
+          field :name
+          field :begin_time
+          field :end_time
+          field :is_first
+          field :is_more
+          field :min_total
+          field :max_total
+          field :prodcut1
+          field :prodcut2
+          field :prodcut3
+          field :send_prodcut1
+          field :send_prodcut2
+          field :send_prodcut3
+          field :is_enable
+          field :created_at
+          field :created_at
+          field :updated_at
+        end
+
+        edit do
+          field :name
+          field :begin_time
+          field :end_time
+          field :is_first
+          field :is_more
+          field :min_total
+          field :max_total
+          field :prod1
+          field :nums1
+          field :prod2
+          field :nums2
+          field :prod3
+          field :nums3
+          field :send_prod1
+          field :send_nums1
+          field :send_prod2
+          field :send_nums2
+          field :send_prod3
+          field :send_nums3
+          field :is_enable
+        end
+    end
+end

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

@@ -0,0 +1,32 @@
+zh-CN:
+  activerecord:
+    models:
+      promotion: 促销管理
+    attributes:
+      promotion: 
+        name: 促销名称
+        begin_time: 开始时间
+        end_time: 结束时间
+        is_first: 是否首单
+        is_more: 多买多送
+        min_total: 订单最小金额(单位:分)
+        max_total: 订单最大金额(单位:分)
+        prod1: 买品1ID
+        nums1: 买品1数量
+        prod2: 买品2ID
+        nums2: 买品2数量
+        prod3: 买品3ID3
+        nums3: 买品3数量
+        send_prod1: 赠品1ID
+        send_nums1: 赠品1数量
+        send_prod2: 赠品2ID
+        send_nums2: 赠品2数量
+        send_prod3: 赠品3ID
+        prodcut1: 买品1
+        prodcut2: 买品2
+        prodcut3: 买品3
+        send_prodcut1: 赠品1
+        send_prodcut2: 赠品2
+        send_prodcut3: 赠品3
+        created_at: 创建时间
+        updated_at: 更新时间

+ 60 - 0
db/migrate/20201102114643_create_promotions.rb

@@ -0,0 +1,60 @@
+# encoding:utf-8
+class CreatePromotions < ActiveRecord::Migration
+  def up
+    #促销表
+    create_table :promotions do |t|
+      # 促销名称
+      t.column :name, :string,:limit => 128
+      #开始时间
+      t.column :begin_time,:datetime
+      #结束时间
+      t.column :end_time,:datetime
+      # 是否首单
+      t.column :is_first, :boolean, :default=>1
+      # 多买多送
+      t.column :is_more, :boolean, :default=>1
+      # 最小金额
+      t.column :min_total, :integer, :limit => 11, :default => 0
+      # 最大金额
+      t.column :max_total, :integer, :limit => 11, :default => 0
+      # 买品1
+      t.column :prod1, :integer, :limit => 11, :default => 0
+      # 数量1
+      t.column :nums1, :integer, :limit => 11, :default => 0
+      # 买品2
+      t.column :prod2, :integer, :limit => 11, :default => 0
+      # 数量3
+      t.column :nums2, :integer, :limit => 11, :default => 0
+      # 买品3
+      t.column :prod3, :integer, :limit => 11, :default => 0
+      # 数量3
+      t.column :nums3, :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.timestamps
+    end
+    add_index :shop_applications, :user_id
+    add_index :shop_applications, :wx_user_id
+    add_index :promotions, :begin_time
+    add_index :promotions, :end_time
+  end
+
+  def down
+    remove_index :shop_applications, :user_id
+    remove_index :shop_applications, :wx_user_id
+    drop_table :promotions
+  end
+
+end