user.go 851 B

1234567891011121314151617181920212223242526272829303132333435
  1. package mysql
  2. import orm "duoduo/database"
  3. type User struct {
  4. CreateTime string `gorm:"column:create_time" json:"createTime"`
  5. OpenID string `gorm:"column:open_id" json:"openId"`
  6. Phone string `gorm:"column:phone" json:"phone"`
  7. Pid string `gorm:"column:pid" json:"pid"`
  8. UpdateTime string `gorm:"column:update_time" json:"updateTime"`
  9. }
  10. // TableName sets the insert table name for this struct type
  11. func (u *User) TableName() string {
  12. return "user"
  13. }
  14. func (u *User) GetNum() int {
  15. var count int
  16. tableCount := orm.Eloquent.Table(u.TableName()).Where("open_id = ? ", u.OpenID)
  17. tableCount.Count(&count)
  18. return count
  19. }
  20. func (u *User) Create() (User, error) {
  21. var doc User
  22. result := orm.Eloquent.Table(u.TableName()).Create(&u)
  23. if result.Error != nil {
  24. err := result.Error
  25. return doc, err
  26. }
  27. doc = *u
  28. return doc, nil
  29. }