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.
|
|
package models
import ( "errors" "github.com/ouxuanserver/osmanthuswine/src/core" )
const UserTN = TableNamePrefix + "user"
//用户
type User struct { Model `xorm:"extends"` //Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
//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:"更新时间"`
Username string `json:"username" xorm:"not null default '' comment('用户名') VARCHAR(128)"` Phone string `json:"phone" xorm:"not null default '' comment('手机号码') VARCHAR(128)"` Password string `json:"password" xorm:"not null default '' comment('密码') VARCHAR(128)"` Code string `json:"code" xorm:"not null default '' comment('验证码') VARCHAR(128)"` City string `json:"city" xorm:"not null default '' comment('城市') VARCHAR(128)"` Province string `json:"province" xorm:"not null default '' comment('省份') VARCHAR(128)"` Country string `json:"country" xorm:"not null default '' comment('国家') VARCHAR(128)"` Unionid string `json:"unionid" xorm:"not null default '' comment('unionid') VARCHAR(128)"` Openid string `json:"openid" xorm:"not null default '' comment('openid') VARCHAR(128)"` Nickname string `json:"nickname" xorm:"not null default '' comment('昵称') VARCHAR(128)"` Avatar string `json:"avatar" xorm:"not null default '' comment('头像') VARCHAR(128)"` Gender string `json:"gender" xorm:"not null default '' comment('性别[男,女]') VARCHAR(128)"` Balance float64 `json:"balance" xorm:"not null default 0.00 comment('余额') DECIMAL(18,2)"` Token string `json:"token" xorm:"not null default '' comment('token') VARCHAR(255)"`
// 无关变量
Sig string `json:"sig" xorm:"-"` }
func (t *User) TableName() string { return UserTN }
func (t *User) Alias(name string) string { return Alias(t, name) }
func (t *User) GetUserByOpenid(openId string) (bool, error) { return core.GetXormAuto().Where("openid=?", openId).Get(t) }
func (t *User) SaveUserInfo(uid interface{}) (int64, error) { return core.GetXormAuto().Where("id=?", uid).Cols("nickname", "gender", "avatar", "unionid", "city", "province", "country").Update(t) }
func GetUsersByIds(ids interface{}) ([]*User, error) { users := make([]*User, 0) err := core.GetXormAuto().In("id", ids).Find(&users) return users, err }
func (t *User) GetByToken(token string) error { exist, err := core.GetXormAuto().Where("is_delete=0 and token=?", token).Get(t) if err != nil { return err } if !exist { return errors.New("token认证错误") } return nil }
|