# encoding:utf-8
# 审批提现订单
module RailsAdmin
  module Config
    module Actions     

      class AuditTakecashOrder < RailsAdmin::Config::Actions::Base
            register_instance_option :visible? do
          if not bindings[:object].blank?
            authorized? && bindings[:object].audit_state == 0 && bindings[:object].pay_state==0
          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-thumbs-up'
        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 == 0 && @object.pay_state==0
              @object.update_attribute(:audit_state, 1)
              @object.update_attribute(:expc_pay_at, Time.now + 5.minutes) 
            end                  
            # redirect_to back_or_index, notice: "已审批!"
            redirect_to :back, notice: "审批通过!"
          end
        end
      end

    end
  end
end