package models import ( "time" "github.com/ouxuanserver/osmanthuswine/src/core" ) const UserTableName = TableNamePrefix + "user" //用户 type User struct { Id int64 `json:"id" xorm:"pk autoincr"` Phone string `json:"phone" description:"手机号码"` Code string `json:"code" description:"验证码"` City string `json:"city" xorm:"not null"` Province string `json:"province" xorm:"not null"` Country string `json:"country"` Unionid string `json:"unionid" description:"unionid"` Openid string `json:"openid" description:"openid"` AccessToken string `json:"access_token" description:"token"` Nickname string `json:"nickname" description:"昵称"` Avatar string `json:"avatar" description:"头像"` Gender string `json:"gender" description:"性别[男,女]"` Balance float64 `json:"balance" description:"余额"` ActivityId int64 `json:"activity_id" description:"主活动id"` // 不存在 AreaId int64 `json:"area_id" description:"地区id"` // 不存在 AreaName string `json:"area_name" description:"地区名字"` IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"` CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建时间"` UpdatedAt time.Time `json:"updated_at" xorm:"updated" description:"更新时间"` } func (t *User) TableName() string { return UserTableName } func (t *User) Alias(name string) string { return AliasTableName(t, name) } func (t *User) GetUserByOpenid(openId string) (bool, error) { return core.GetXormAuto().Where("openid=?", openId).Get(t) } func (t *User) SaveAndUpdateWithOpenId() error { exist, err := core.GetXormAuto().Table("ox_user"). Where("openid=?", t.Openid).Exist() if err != nil { return err } if !exist { _, err := core.GetXormAuto().Insert(t) return err } _, err = core.GetXormAuto().Where("openid=?", t.Openid).AllCols().Update(t) return err }