user_perfomance.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # encoding: utf-8
  2. require 'date' # 包含DateTime
  3. require 'time'
  4. class UserPerfomance < ActiveRecord::Base
  5. has_paper_trail
  6. self.table_name = "user_perfomances"
  7. belongs_to :wx_user, :foreign_key => :wx_user_id
  8. #validates_presence_of :wx_user_id
  9. #after_create :user_perfomance
  10. after_update :user_perfomance
  11. validates :wx_user_id,:begin_date,:end_date,presence: true
  12. def user_perfomance
  13. #统计订单商品销售数据
  14. url = "#{CONFIG_FILE["api_host"]}/railsadmin/user/perfomance/#{self.id}"
  15. p url
  16. open(url)
  17. end
  18. def begin_date_fomat
  19. if !self.begin_date.nil?
  20. return self.begin_date.strftime
  21. end
  22. end
  23. def end_date_fomat
  24. if !self.end_date.nil?
  25. return self.end_date.strftime
  26. end
  27. end
  28. rails_admin do
  29. navigation_label '统计汇总'
  30. weight -500
  31. list do
  32. filters [:wx_user_id,:begin_date,:end_date]
  33. field :id
  34. field :begin_date do
  35. visible false
  36. filterable true
  37. end
  38. field :end_date do
  39. visible false
  40. filterable true
  41. end
  42. field :begin_date_fomat
  43. field :end_date_fomat
  44. field :wx_user_id do
  45. filterable true
  46. end
  47. field :nickname
  48. field :order_perfomance
  49. field :shop_order_perfomance
  50. field :shop_perfomance
  51. field :balance_perfomance
  52. field :total
  53. field :created_at
  54. field :updated_at
  55. end
  56. show do
  57. field :id
  58. field :begin_date_fomat
  59. field :end_date_fomat
  60. field :wx_user_id
  61. field :nickname
  62. field :order_perfomance
  63. field :shop_order_perfomance
  64. field :shop_perfomance
  65. field :balance_perfomance
  66. field :total
  67. field :created_at
  68. field :updated_at
  69. end
  70. edit do
  71. field :begin_date
  72. field :end_date
  73. field :wx_user_id
  74. end
  75. end
  76. end