query.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package user_record
  2. import "hongze/hongze_yb/global"
  3. // GetByUserId 根据用户id和平台id获取用户关系
  4. func GetByUserId(userId, platform int) (item *UserRecord, err error) {
  5. err = global.DEFAULT_MYSQL.Where("user_id = ? and create_platform = ?", userId, platform).First(&item).Error
  6. return
  7. }
  8. // GetByUnionID 根据用户UnionID和平台id获取用户关系
  9. func GetByUnionID(unionID string, platform int) (item *UserRecord, err error) {
  10. err = global.DEFAULT_MYSQL.Where("union_id = ? and create_platform = ?", unionID, platform).First(&item).Error
  11. return
  12. }
  13. // GetByOpenID 根据用户OpenID获取用户关系
  14. func GetByOpenID(openID string) (item *UserRecord, err error) {
  15. err = global.DEFAULT_MYSQL.Where("open_id = ? ", openID).First(&item).Error
  16. return
  17. }
  18. // GetUserThirdRecordByUserId 获取该用户第一个的 三方信息(微信头像信息)
  19. func GetUserThirdRecordByUserId(userId int) (item *UserRecord, err error) {
  20. err = global.DEFAULT_MYSQL.Where("user_id = ? ", userId).Order("user_record_id asc").First(&item).Error
  21. return
  22. }
  23. // GetFirstByUnionID 根据用户UnionID获取最小平台的用户关系(已经绑定了user_id的)
  24. func GetFirstByUnionID(unionID string) (item *UserRecord, err error) {
  25. err = global.DEFAULT_MYSQL.Where("union_id = ? and user_id>0", unionID).Order("create_platform asc").First(&item).Error
  26. return
  27. }
  28. // GetRepeatBindAccount 获取重复的绑定账号
  29. func GetRepeatBindAccount(account, unionId string) (items []*UserRecord, err error) {
  30. err = global.DEFAULT_MYSQL.Model(UserRecord{}).Where("bind_account = ? AND union_id <> ? AND create_platform IN (3,6)", account, unionId).Find(&items).Error
  31. return
  32. }
  33. // ClearRepeatBindAccount 清除重复的绑定账号
  34. func ClearRepeatBindAccount(account, unionId string) (err error) {
  35. sql := ` UPDATE user_record SET bind_account = '', user_id = 0 WHERE bind_account = ? AND union_id <> ? AND create_platform IN (3,6)`
  36. err = global.DEFAULT_MYSQL.Exec(sql, account, unionId).Error
  37. return
  38. }