# encoding: utf-8
class Present < ActiveRecord::Base
  has_paper_trail
  self.table_name = "presents"
  validates :wx_user_id,:send_prod1,:remark,presence: true
  belongs_to :wx_user
  SOURCE_ENUM = [["店长促销发放", "shop"],
                 ["充值促销发放", "balance"],
                 ["手工添加", "others"],
                 ]
  def send_product
    prd1 = Product.where("id = ?", self.send_prod1).first
    if !prd1.blank?
      return format("%s-%d",prd1.name,self.send_nums1)
    else
      return "--"
    end
  end
  rails_admin do
    navigation_label '促销管理'
    weight -600
    list do
      filters [:wx_user_id,:send_prod1,:source]
      field :id
      field :wx_user_id do
        visible true
        filterable true
      end
      field :wx_user
      field :price do
        label "单价（元）"
        formatted_value do # used in form views
          value.to_f / 100
        end
      end
      field :total do
        label "总价（元）"
        formatted_value do # used in form views
          value.to_f / 100
        end
      end
      field :send_prod1
      #field :send_nums1
      field :send_product
      field :order_id
      field :status
      field :source, :enum do
        enum do
          SOURCE_ENUM
        end
      end
      field :remark
      field :created_at
      # field :updated_at
    end

    show do
      field :id
      field :wx_user_id
      field :price do
        label "单价（元）"
        formatted_value do # used in form views
          value.to_f / 100
        end
      end
      field :total do
        label "总价（元）"
        formatted_value do # used in form views
          value.to_f / 100
        end
      end
      field :send_prod1
      field :send_nums1
      field :order_id
      field :status
      field :source, :enum do
        enum do
          SOURCE_ENUM
        end
      end
      field :remark
      field :created_at
      # field :updated_at
    end

    edit do
      field :wx_user_id
      field :price
      field :total
      field :send_prod1
      field :send_nums1
      field :order_id
      field :status
      field :source, :enum do
        enum do
          SOURCE_ENUM
        end
      end
      field :remark
      field :remark    
    end

  end

end


