# encoding:utf-8
class CreateRechargePromotions < ActiveRecord::Migration
  def up


    #店长促销表
    create_table :shop_promotions do |t|
      # 促销名称
      t.column :name, :string,:limit => 128
      #开始时间
      t.column :begin_time,:datetime
      #结束时间
      t.column :end_time,:datetime
      # 部门
      t.column :depart, :integer, :limit => 11, :null => false, :default => 0
      # 充值金额
      t.column :total, :integer, :limit => 11, :default => 0
      # 赠提货券
      t.column :cash, :integer, :limit => 11, :default => 0
      # 赠积分
      t.column :cent, :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
      # 赠品4
      t.column :send_prod4, :integer, :limit => 11, :default => 0
      # 赠品数量4
      t.column :send_nums4, :integer, :limit => 11, :default => 0
      # 赠品5
      t.column :send_prod5, :integer, :limit => 11, :default => 0
      # 赠品数量5
      t.column :send_nums5, :integer, :limit => 11, :default => 0
      # 状态
      t.column :is_enable, :boolean, :default=>1
      t.timestamps
    end

    add_index :shop_promotions, :begin_time
    add_index :shop_promotions, :end_time
    add_index :shop_promotions, :total


    #商城赠品
    create_table :presents do |t|
      # 微信ID
      t.column :wx_user_id, :integer, :limit => 11, :default => 0
      # 单价
      t.column :price, :integer, :limit => 11, :default => 0
      # 总价
      t.column :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
      # 状态
      t.column :status, :boolean, :default=>1
      # 订单号
      t.column :order_id, :string, :limit => 64
      #来源
      t.column :source, :string, :limit => 255
      #备注
      t.column :remark, :string, :limit => 255
      t.timestamps
    end

    add_index :presents, :wx_user_id
    add_index :presents, :order_id

    add_column :balance_promotions, :max_total, :integer, :default=>0,:limit => 11
    add_column :balance_promotions, :depart, :integer, :null => false, :default=>0,:limit => 11
    add_column :balance_promotions, :is_more, :boolean, :default=>0,:limit => 4
    add_column :promotions, :depart, :integer, :null => false, :default=>0,:limit => 11


  end

  def down
    drop_table :shop_promotions
    drop_table :presents
  end

end
