| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- # encoding:utf-8
- class ScaleUser < ActiveRecord::Base
- has_paper_trail
- self.table_name = "scale_users"
- belongs_to :wx_user
- has_many :scale_results, :foreign_key => :user_id, :dependent => :destroy
- attr_accessor :v_avatar
- #after_create :update_paied_time
- SEX_ENUM = [["男",0],["女",1]]
- def wx_user_contact
- return "-" if wx_user.blank?
- user = wx_user.user
- return "-" if user.blank?
- contact = user.tel
- contact = user.email if contact.blank?
- contact.blank? ? "-" : contact
- end
- def get_avatar_img
- return "https://x-encrpt-bucket.s3.ap-southeast-2.amazonaws.com/encript/1766455493300.jpeg" if self.avatar.blank?
- url = "http://#{Ali::Oss::CDN_URL_FOR_HOST}/#{self.avatar}"
- return url
- end
- rails_admin do
- navigation_label '体脂秤用户'
- parent ScaleDevice
- weight 1
- list do
- filters [:wx_user,:created_at]
- field :id
- field :wx_user_id
- field :wx_user do
- pretty_value do
- bindings[:object].wx_user_contact
- end
- end
- field :nick_name
- field :avatar do
- formatted_value do
- bindings[:view].tag(:img,{:src => bindings[:object].get_avatar_img,
- :style => 'width: 100px;height: 100px;cursor: pointer;display: block;max-width: 100px',
- :onClick => "javascript:window.open('#{bindings[:object].get_avatar_img}')"})
- end
- end
- field :sex, :enum do
- filterable true
- enum do
- SEX_ENUM
- end
- end
- field :height
- field :age
- field :target_weight
- field :birthday
- field :created_at
- field :updated_at
- end
- show do
- field :wx_user_id
- field :wx_user do
- pretty_value do
- bindings[:object].wx_user_contact
- end
- end
- field :nick_name
- field :avatar do
- formatted_value do
- bindings[:view].tag(:img,{:src => bindings[:object].get_avatar_img,
- :style => 'width: 100px;height: 100px;cursor: pointer;display: block;max-width: 100px',
- :onClick => "javascript:window.open('#{bindings[:object].get_avatar_img}')"})
- end
- end
- field :sex, :enum do
- filterable true
- enum do
- SEX_ENUM
- end
- end
- field :height
- field :age
- field :target_weight
- field :birthday
- field :created_at
- field :updated_at
- end
- edit do
- # field :wx_user_id
- field :wx_user
- field :nick_name
- field :v_avatar, :file_upload do
- pretty_value do
- bindings[:view].tag(:img, {:src => bindings[:object].get_avatar_img, :class => 'preview'})
- end
- end
- field :sex, :enum do
- filterable true
- enum do
- SEX_ENUM
- end
- end
- field :height
- field :age
- field :target_weight
- field :birthday
- field :created_at
- field :updated_at
- end
- end
- def v_avatar=file
- unless file.blank?
- clear_avatar_img
- file_name = "#{UUID.new.generate[0...8].downcase}.jpg"
- file_path = "#{IMG_STORE_PATH}/#{file_name}"
- Ali::Oss.store(Ali::Oss::BUCKET_NAME_PUBLIC_READ, file_path, file.read)
- self.head = file_path
- self.save
- end
- end
- def clear_avatar_img
- file_path = "#{self.head}"
- Ali::Oss.delete_object(Ali::Oss::BUCKET_NAME_PUBLIC_READ, file_path)
- end
- end
|