sign_up_channel.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # encoding:utf-8
  2. #小程序码
  3. class SignUpChannel < ActiveRecord::Base
  4. has_paper_trail
  5. self.table_name = "sign_up_channels"
  6. belongs_to :parent_signup_channel, :foreign_key => :parent_id
  7. rails_admin do
  8. navigation_label '用户管理'
  9. weight -300
  10. list do
  11. filters [:id, :channel_value, :invite_id]
  12. field :id
  13. field :parent_signup_channel
  14. field :qrcode_path
  15. field :channel_value
  16. field :channel_url
  17. field :img do
  18. formatted_value do
  19. bindings[:view].tag(:img,{:src => bindings[:object].get_img,
  20. :style => 'width: 100px;height: 100px;cursor: pointer;display: block;max-width: 100px;',
  21. :onClick => "javascript:window.open('#{bindings[:object].get_img}')"})
  22. end
  23. end
  24. field :invite_id
  25. field :qrcode_img_url
  26. field :scan_times
  27. field :created_at
  28. end
  29. edit do
  30. field :parent_id
  31. field :channel_value
  32. field :channel_url
  33. field :invite_id
  34. end
  35. end
  36. def qrcode_path
  37. # url = "#{CONFIG_FILE["api_host"]}/v1/xcx/qrcode/generate"
  38. path = "pages/start/start?scene=#{self.id}"
  39. return path
  40. end
  41. def qrcode_img_url
  42. # url = "#{CONFIG_FILE["api_host"]}/v1/xcx/qrcode/generate"
  43. url = "#{CONFIG_FILE["api_host"]}/v1/xcx/qrcode/channel/#{self.id}"
  44. if self.url_image.blank?
  45. open(url)
  46. end
  47. return url
  48. end
  49. def get_img
  50. url = "#{self.url_image}"
  51. return url
  52. end
  53. end