order_award.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #encoding
  2. module RailsAdmin
  3. module Config
  4. module Actions
  5. class OrderAward < RailsAdmin::Config::Actions::Base
  6. register_instance_option :visible? do
  7. unless bindings[:object].blank?
  8. authorized? && bindings[:object].status == "processing" && bindings[:object].has_commission ==false && bindings[:object].source =="sys"
  9. else
  10. authorized?
  11. end
  12. end
  13. register_instance_option :member do
  14. true
  15. end
  16. register_instance_option :link_icon do
  17. 'icon-plane'
  18. end
  19. register_instance_option :pjax? do
  20. false
  21. end
  22. register_instance_option :controller do
  23. Proc.new do
  24. require 'rest-client'
  25. order = Order.where("id = ? and status = ? and has_commission = ? and source = ? ",@object.id,"processing",false,"sys").first
  26. n = "发放成功"
  27. unless order.blank?
  28. n = "已成功发放"
  29. url = "#{CONFIG_FILE["api_host"]}/railsadmin/order/award/#{@object.id}"
  30. begin
  31. ret = RestClient.get url, {} #per_page: 5
  32. rescue Exception => e
  33. n = "发放失败!"
  34. end
  35. end
  36. redirect_to :back, notice: "#{n}"
  37. end
  38. end
  39. end
  40. end
  41. end
  42. end