user.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_cygxzs/models"
  5. "hongze/hongze_cygxzs/utils"
  6. )
  7. var ERR_NO_USER_RECORD = errors.New("用户关系没有入库")
  8. var ERR_USER_NOT_BIND = errors.New("用户没有绑定")
  9. //通过用户 关系表记录 和 用户记录 格式化返回 用户数据
  10. func formatWxUserAndUserRecord(wxUser *models.WxUserItem, userRecord *models.UserRecord) {
  11. wxUser.OpenId = userRecord.OpenId
  12. wxUser.UnionId = userRecord.UnionId
  13. wxUser.NickName = userRecord.NickName
  14. //wxUser.RealName = userRecord.RealName
  15. //wxUser.BindAccount = userRecord.BindAccount
  16. wxUser.Headimgurl = userRecord.Headimgurl
  17. wxUser.SessionKey = userRecord.SessionKey
  18. }
  19. func GetWxUserItemByOpenId(unionId string) (item *models.WxUserItem, err error) {
  20. //通过openid获取用户关联信息
  21. item = new(models.WxUserItem)
  22. item.UnionId = unionId // 先写入 unionId
  23. userRecord, userRecordErr := models.GetUserRecordByUnionId(unionId)
  24. if userRecordErr != nil && userRecordErr.Error() != utils.ErrNoRow() {
  25. err = userRecordErr
  26. return
  27. }
  28. //如果 userRecord 表中的手机号不为空,那么就通过手机号来获取详情
  29. if userRecord != nil {
  30. if userRecord.BindAccount != "" {
  31. user, userErr := models.GetWxUserItemByUserMobile(userRecord.BindAccount)
  32. if userErr != nil && userErr.Error() != utils.ErrNoRow() {
  33. err = userErr
  34. return
  35. }
  36. if user != nil {
  37. item = user
  38. }
  39. }
  40. }
  41. return
  42. }