# encoding:utf-8
class WxFormId < ActiveRecord::Base
  has_paper_trail
  self.table_name = "wx_form_ids"

  attr_accessor :wx_user_name, :user_id, :is_outdate, :investments

  def wx_user_name
    wxUser = WxUser.where(" openid = ? ", self.openid).first
    if !wxUser.blank?
      return wxUser.nickname
    end
    return "-"
  end
  def user_id
    wxUser = WxUser.where(" openid = ? ", self.openid).first
    if !wxUser.blank?
      return wxUser.user_id
    end
    return "-"
  end
  def is_outdate
    if self.state == 1 
      return true
    else
      return Time.now.to_i - 7 * 24 * 60 * 60 > self.created_at.to_i
    end
  end


  rails_admin do
    navigation_label '推送管理'
    weight -450

    list do
      filters [:id,:state, :created_at]
      field :id
      field :wx_user_name
      field :user_id
      # field :openid
      # field :form_id
      field :state
      field :is_outdate, :boolean
      field :created_at
      field :updated_at
    end

    show do
      field :id
      field :wx_user_name
      field :user_id
      field :openid
      field :form_id
      field :state
      field :is_outdate, :boolean
      field :created_at
      field :updated_at
    end

    edit do
      field :openid
      field :form_id
      field :state
    end
  end
end