1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package models
- import (
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- type UserRecord struct {
- UserRecordId int `orm:"pk"`
- OpenId string `description:"用户openid,最大长度:32"`
- UnionId string `description:"用户unionid,最大长度:64"`
- Subscribe int `description:"是否关注"`
- SubscribeTime time.Time `description:""`
- NickName string `descritpion:"用户昵称,最大长度:32"`
- RealName string `descritpion:"用户实际名称,最大长度:32"`
- Sex int `descritpion:"普通用户性别,1为男性,2为女性"`
- Province string `description:"普通用户个人资料填写的省份,最大长度:30"`
- City string `description:"普通用户个人资料填写的城市,最大长度:30"`
- Country string `description:"国家,如中国为CN,最大长度:30"`
- Headimgurl string `description:"用户第三方(微信)头像,最大长度:512"`
- CreateTime time.Time `description:"创建时间,关系添加时间、用户授权时间"`
- SessionKey string `description:"微信小程序会话密钥,最大长度:255"`
- UserId int `description:"用户id"`
- }
- func (item *UserRecord) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(item, cols...)
- return
- }
- func (item *UserRecord) Insert() (insertId int64, err error) {
- o := orm.NewOrm()
- insertId, err = o.Insert(item)
- return
- }
- // 根据openid获取用户关系
- func GetUserRecordByOpenId(openId string) (item *UserRecord, err error) {
- sql := `SELECT * FROM user_record WHERE open_id=? `
- o := orm.NewOrm()
- err = o.Raw(sql, openId).QueryRow(&item)
- return
- }
- func UserSubscribe(subscribeType int, openId string) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE user_record SET subscribe=?,subscribe_time=NOW() WHERE open_id = ? `
- _, err = o.Raw(sql, subscribeType, openId).Exec()
- return
- }
- // GetUserRecordByUnionId 通过unionid获取已绑定用户的user_record信息
- func GetUserRecordByUnionId(unionId string) (item *UserRecord, err error) {
- sql := `SELECT * FROM user_record WHERE union_id=? `
- err = orm.NewOrm().Raw(sql, unionId).QueryRow(&item)
- return
- }
|