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

62 lines
2.1 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
  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:"pk autoincr"`
  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. IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"`
  26. CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建时间"`
  27. UpdatedAt time.Time `json:"updated_at" xorm:"updated" description:"更新时间"`
  28. }
  29. func (t *User) TableName() string {
  30. return UserTN
  31. }
  32. func (t *User) Alias(name string) string {
  33. return AliasTableName(t, name)
  34. }
  35. func (t *User) GetUserByOpenid(openId string) (bool, error) {
  36. return core.GetXormAuto().Where("openid=?", openId).Get(t)
  37. }
  38. func (t *User) SaveAndUpdateWithOpenId() error {
  39. exist, err := core.GetXormAuto().Table(UserTN).Where("openid=?", t.Openid).Exist()
  40. if err != nil {
  41. return err
  42. }
  43. if !exist {
  44. _, err = core.GetXormAuto().Insert(t)
  45. return err
  46. }
  47. _, err = core.GetXormAuto().Where("openid=?", t.Openid).Update(t)
  48. return err
  49. }
  50. func (t *User) SaveUserInfo(uid interface{}) (int64, error) {
  51. return core.GetXormAuto().Where("id=?", uid).Cols("nickname", "gender",
  52. "avatar", "unionid", "city", "province", "country").Update(t)
  53. }