# encoding:utf-8
class RechargeCashOrder < ActiveRecord::Base
  has_paper_trail
  self.table_name = "recharge_cash_orders"
  belongs_to :user
  belongs_to :wx_user
  validates :order_id,:user_id,:total_price,presence: true

  PAY_WAY_ENUM = [
    ["微信支付","recharge_wxpay"],
  ]

  rails_admin do
    navigation_label '资金管理'
    parent CashBalance
    weight -920

    list do
      filters [:user,:wx_user,:order_id,:state]
      field :id
      field :order_id
      field :user
      field :wx_user
      field :pay_way ,:enum do
        enum do
          PAY_WAY_ENUM
        end
      end
      field :trade_no
      field :paied_at do
        formatted_value do
          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
        end
      end
      field :total_price do
        label "总额（元）"
        formatted_value do # used in form views
          value.to_f / 100
        end
      end
      field :state
      field :remark
      field :balance_bank_card_no
      field :created_at
      field :updated_at
    end

    show do
      field :order_id
      field :user
      field :wx_user
      field :pay_way ,:enum do
        enum do
          PAY_WAY_ENUM
        end
      end
      field :trade_no
      field :paied_at do
        formatted_value do
          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
        end
      end
      field :total_price do
        label "总额（元）"
        formatted_value do # used in form views
          value.to_f / 100
        end
      end
      field :state
      field :balance_bank_card_no
      field :remark
      field :created_at
    end

    edit do
      field :order_id
      field :user_id
      field :wx_user_id
      field :pay_way ,:enum do
        enum do
          PAY_WAY_ENUM
        end
      end
      field :trade_no
      field :paied_at do
        label "支付时间单位(秒)"
      end
      field :total_price do
        label "总额（分）"
      end
      field :state
      field :remark
      field :balance_bank_card_no
    end
  end
end
