# encoding:utf-8
# 立即提现
module RailsAdmin
  module Config
    module Actions     

      class TakecashAtOnce < RailsAdmin::Config::Actions::Base
            register_instance_option :visible? do
          if not bindings[:object].blank?
            authorized? && bindings[:object].audit_state == 1 && bindings[:object].pay_state ==0 && [nil,0].include?(bindings[:object].paied_at)
          else
            authorized?
          end
        end
        # We want the action on members, not the Users collection
        register_instance_option :member do
          true
        end

        register_instance_option :link_icon do
          'icon-plane'
        end
        # You may or may not want pjax for your action
        register_instance_option :pjax? do
          false
        end

        register_instance_option :controller do
          Proc.new do
            if @object.audit_state == 1 && @object.pay_state ==0 && [nil,0].include?(@object.paied_at)
              @object.update_attribute(:expc_pay_at, Time.now) 
            end                  
            # redirect_to back_or_index, notice: "已提现"
            redirect_to :back,notice: "已提现"
          end
        end
      end

    end
  end
end