互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "time"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. )
  6. const UserTN = TableNamePrefix + "user"
  7. //用户
  8. type User struct {
  9. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  10. Phone string `json:"phone" description:"手机号码"`
  11. Code string `json:"code" description:"验证码"`
  12. City string `json:"city" xorm:"not null"`
  13. Province string `json:"province" xorm:"not null"`
  14. Country string `json:"country"`
  15. Unionid string `json:"unionid" description:"unionid"`
  16. Openid string `json:"openid" description:"openid"`
  17. AccessToken string `json:"access_token" description:"token"`
  18. Nickname string `json:"nickname" description:"昵称"`
  19. Avatar string `json:"avatar" description:"头像"`
  20. Gender string `json:"gender" description:"性别[男,女]"`
  21. Balance float64 `json:"balance" description:"余额"`
  22. ActivityId int64 `json:"activity_id" description:"主活动id"` // 不存在
  23. AreaId int64 `json:"area_id" description:"地区id"` // 不存在
  24. AreaName string `json:"area_name" description:"地区名字"`
  25. Sig string `json:"sig" xorm:"-"`
  26. IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"`
  27. CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建时间"`
  28. UpdatedAt time.Time `json:"updated_at" xorm:"updated" description:"更新时间"`
  29. }
  30. func (t *User) TableName() string {
  31. return UserTN
  32. }
  33. func (t *User) Alias(name string) string {
  34. return AliasTableName(t, name)
  35. }
  36. func (t *User) GetUserByOpenid(openId string) (bool, error) {
  37. return core.GetXormAuto().Where("openid=?", openId).Get(t)
  38. }
  39. func (t *User) SaveUserInfo(uid interface{}) (int64, error) {
  40. return core.GetXormAuto().Where("id=?", uid).Cols("nickname", "gender",
  41. "avatar", "unionid", "city", "province", "country").Update(t)
  42. }
  43. func GetUsersByIds(ids interface{}) ([]*User, error) {
  44. users := make([]*User, 0)
  45. err := core.GetXormAuto().In("id", ids).Find(&users)
  46. return users, err
  47. }