互动
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.

60 lines
2.5 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
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 int `json:"id" xorm:"not null pk autoincr INT(11)"`
  10. IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"`
  11. CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建时间"`
  12. UpdatedAt time.Time `json:"updated_at" xorm:"updated" description:"更新时间"`
  13. Username string `json:"username" xorm:"not null default '' comment('用户名') VARCHAR(128)"`
  14. Phone string `json:"phone" xorm:"not null default '' comment('手机号码') VARCHAR(128)"`
  15. Password string `json:"password" xorm:"not null default '' comment('密码') VARCHAR(128)"`
  16. Code string `json:"code" xorm:"not null default '' comment('验证码') VARCHAR(128)"`
  17. City string `json:"city" xorm:"not null default '' comment('城市') VARCHAR(128)"`
  18. Province string `json:"province" xorm:"not null default '' comment('省份') VARCHAR(128)"`
  19. Country string `json:"country" xorm:"not null default '' comment('国家') VARCHAR(128)"`
  20. Unionid string `json:"unionid" xorm:"not null default '' comment('unionid') VARCHAR(128)"`
  21. Openid string `json:"openid" xorm:"not null default '' comment('openid') VARCHAR(128)"`
  22. Nickname string `json:"nickname" xorm:"not null default '' comment('昵称') VARCHAR(128)"`
  23. Avatar string `json:"avatar" xorm:"not null default '' comment('头像') VARCHAR(128)"`
  24. Gender string `json:"gender" xorm:"not null default '' comment('性别[男,女]') VARCHAR(128)"`
  25. Balance float64 `json:"balance" xorm:"not null default 0.00 comment('余额') DECIMAL(18,2)"`
  26. //ActivityId int `json:"activity_id" description:"主活动id"` // 不存在
  27. //AreaId int `json:"area_id" description:"地区id"` // 不存在
  28. //AreaName string `json:"area_name" description:"地区名字"`
  29. // 无关变量
  30. Sig string `json:"sig" xorm:"-"`
  31. }
  32. func (t *User) TableName() string {
  33. return UserTN
  34. }
  35. func (t *User) Alias(name string) string {
  36. return Alias(t, name)
  37. }
  38. func (t *User) GetUserByOpenid(openId string) (bool, error) {
  39. return core.GetXormAuto().Where("openid=?", openId).Get(t)
  40. }
  41. func (t *User) SaveUserInfo(uid interface{}) (int64, error) {
  42. return core.GetXormAuto().Where("id=?", uid).Cols("nickname", "gender",
  43. "avatar", "unionid", "city", "province", "country").Update(t)
  44. }
  45. func GetUsersByIds(ids interface{}) ([]*User, error) {
  46. users := make([]*User, 0)
  47. err := core.GetXormAuto().In("id", ids).Find(&users)
  48. return users, err
  49. }