user_perfomance.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. return self.begin_date.strftime("%m/%d/%Y")
  22. end
  23. end
  24. def end_date_fomat
  25. if !self.end_date.nil?
  26. #return self.end_date.strftime
  27. return self.end_date.strftime("%m/%d/%Y")
  28. end
  29. end
  30. rails_admin do
  31. navigation_label '统计汇总'
  32. weight -500
  33. list do
  34. filters [:wx_user_id,:begin_date,:end_date]
  35. field :id
  36. field :begin_date do
  37. visible false
  38. filterable true
  39. end
  40. field :end_date do
  41. visible false
  42. filterable true
  43. end
  44. field :begin_date_fomat
  45. field :end_date_fomat
  46. field :wx_user_id do
  47. filterable true
  48. end
  49. field :nickname
  50. field :order_perfomance
  51. field :shop_order_perfomance
  52. field :shop_perfomance
  53. field :balance_perfomance
  54. field :total
  55. field :created_at
  56. field :updated_at
  57. end
  58. show do
  59. field :id
  60. field :begin_date_fomat
  61. field :end_date_fomat
  62. field :wx_user_id
  63. field :nickname
  64. field :order_perfomance
  65. field :shop_order_perfomance
  66. field :shop_perfomance
  67. field :balance_perfomance
  68. field :total
  69. field :created_at
  70. field :updated_at
  71. end
  72. edit do
  73. field :begin_date
  74. field :end_date
  75. field :wx_user_id
  76. end
  77. end
  78. end