client.user.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "time"
  5. )
  6. type MerchantClientUser struct {
  7. ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // 主键
  8. Code string `gorm:"column:code;type:varchar(255)" json:"code"`
  9. ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"` // open_id 唯一索引
  10. Phone string `gorm:"column:phone;type:varchar(24)" json:"phone"` // 手机号
  11. NickName string `gorm:"column:nick_name;type:varchar(255)" json:"nick_name"` // 微信用户名
  12. AvatarUrl string `gorm:"column:avatar_url;type:varchar(255)" json:"avatar_url"` // 头像url
  13. Admin int `gorm:"column:admin;type:int(11)" json:"admin"` // 1-管理员
  14. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者
  15. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者
  16. CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间
  17. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间
  18. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
  19. }
  20. func (m *MerchantClientUser) TableName() string {
  21. return "merchant_client_user"
  22. }
  23. func (m *MerchantClientUser) GetNum() int {
  24. var count int
  25. tableCount := orm.ShMysql.Table(m.TableName()).Where("client_open_id = ? ", m.ClientOpenID)
  26. tableCount.Count(&count)
  27. return count
  28. }
  29. func (m *MerchantClientUser) GetCodeNum() int {
  30. var count int
  31. tableCount := orm.ShMysql.Table(m.TableName()).Where("code = ? ", m.Code)
  32. tableCount.Count(&count)
  33. return count
  34. }
  35. func (m *MerchantClientUser) GetUserInfo() (MerchantClientUser, error) {
  36. var doc MerchantClientUser
  37. table := orm.ShMysql.Table(m.TableName())
  38. table = table.Where("client_open_id = ? ", m.ClientOpenID)
  39. if err := table.Select("*").First(&doc).Error; err != nil {
  40. return doc, err
  41. }
  42. return doc, nil
  43. }
  44. func (u *MerchantClientUser) Create() (MerchantClientUser, error) {
  45. var doc MerchantClientUser
  46. var err error
  47. doc = *u
  48. err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
  49. if err != nil {
  50. return doc, err
  51. }
  52. return doc, nil
  53. }