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

67 lines
2.3 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
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) GetById(id interface{}) (bool, error) {
  40. return core.GetXormAuto().Where("is_delete=0 and id=?", id).Get(t)
  41. }
  42. func (t *User) SaveAndUpdateWithOpenId() error {
  43. exist, err := core.GetXormAuto().Table(UserTN).Where("openid=?", t.Openid).Exist()
  44. if err != nil {
  45. return err
  46. }
  47. if !exist {
  48. _, err = core.GetXormAuto().Insert(t)
  49. return err
  50. }
  51. _, err = core.GetXormAuto().Where("openid=?", t.Openid).Update(t)
  52. return err
  53. }
  54. func (t *User) SaveUserInfo(uid interface{}) (int64, error) {
  55. return core.GetXormAuto().Where("id=?", uid).Cols("nickname", "gender",
  56. "avatar", "unionid", "city", "province", "country").Update(t)
  57. }