user_record.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. type UserRecord struct {
  7. UserRecordId int `orm:"column(user_record_id);pk"`
  8. OpenId string `description:"用户openid,最大长度:32"`
  9. UnionId string `description:"用户unionid,最大长度:64"`
  10. Subscribe int `description:"是否关注"`
  11. SubscribeTime time.Time `description:""`
  12. NickName string `descritpion:"用户昵称,最大长度:32"`
  13. RealName string `descritpion:"用户实际名称,最大长度:32"`
  14. Sex int `descritpion:"普通用户性别,1为男性,2为女性"`
  15. Province string `description:"普通用户个人资料填写的省份,最大长度:30"`
  16. City string `description:"普通用户个人资料填写的城市,最大长度:30"`
  17. Country string `description:"国家,如中国为CN,最大长度:30"`
  18. Headimgurl string `description:"用户第三方(微信)头像,最大长度:512"`
  19. CreateTime time.Time `description:"创建时间,关系添加时间、用户授权时间"`
  20. SessionKey string `description:"微信小程序会话密钥,最大长度:255"`
  21. UserId int `description:"用户id"`
  22. }
  23. // 根据用户id和平台id获取用户关系
  24. func GetUserRecordByUserId(userId int) (item *UserRecord, err error) {
  25. sql := `SELECT * FROM user_record WHERE user_id=? `
  26. err = orm.NewOrm().Raw(sql, userId).QueryRow(&item)
  27. return
  28. }
  29. func GetUserRecordByUnionids(unionIds []string) (items []*UserRecord, err error) {
  30. if len(unionIds) == 0 {
  31. return
  32. }
  33. sql := `SELECT * FROM user_record WHERE union_id IN (`
  34. for range unionIds {
  35. sql += "?,"
  36. }
  37. sql = sql[:len(sql)-1]
  38. sql += `) `
  39. _, err = orm.NewOrm().Raw(sql, unionIds).QueryRows(&items)
  40. return
  41. }