user_perfomance.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_fomat
  35. field :end_date_fomat
  36. field :wx_user_id do
  37. filterable true
  38. end
  39. field :nickname
  40. field :order_perfomance
  41. field :shop_order_perfomance
  42. field :shop_perfomance
  43. field :balance_perfomance
  44. field :total
  45. field :created_at
  46. field :updated_at
  47. end
  48. show do
  49. field :id
  50. field :begin_date_fomat
  51. field :end_date_fomat
  52. field :wx_user_id
  53. field :nickname
  54. field :order_perfomance
  55. field :shop_order_perfomance
  56. field :shop_perfomance
  57. field :balance_perfomance
  58. field :total
  59. field :created_at
  60. field :updated_at
  61. end
  62. edit do
  63. field :begin_date
  64. field :end_date
  65. field :wx_user_id
  66. end
  67. end
  68. end