employ.rb 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # encoding: utf-8
  2. class Employ < ActiveRecord::Base
  3. self.table_name = "employs"
  4. validates :mobile,:user_name,presence: true
  5. validate :employ_validation
  6. def employ_validation
  7. usr = User.where("tel = ?", self.mobile).first
  8. if !usr.blank?
  9. wu = WxUser.where("user_id = ?", usr.id).first
  10. if !wu.blank?
  11. self.wx_user_id = wu.id
  12. end
  13. else
  14. self.errors.add(:mobile,"该手机号尚未绑定微信账号,请员工预先绑定小程序!")
  15. end
  16. end
  17. rails_admin do
  18. navigation_label '食堂管理'
  19. weight -500
  20. list do
  21. filters [:mobile,:wx_user_id,:user_name]
  22. field :id
  23. field :user_name
  24. field :mobile
  25. field :wx_user_id
  26. field :created_at
  27. # field :updated_at
  28. end
  29. show do
  30. field :id
  31. field :user_name
  32. field :mobile
  33. field :wx_user_id
  34. field :created_at
  35. field :updated_at
  36. end
  37. edit do
  38. field :user_name
  39. field :mobile
  40. end
  41. end
  42. end