b_user_info.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. log "github.com/sirupsen/logrus"
  6. "youngee_b_api/db"
  7. "youngee_b_api/model/http_model"
  8. )
  9. var BUserInfo *bUserInfo
  10. type bUserInfo struct {
  11. }
  12. // FindBUserInfoByToken 根据Token查询商家端用户信息
  13. func (*bUserInfo) FindBUserInfoByToken(ctx context.Context, token string) (*http_model.GetUserInfoData, error) {
  14. if token != "" {
  15. if auth, err := LoginAuth.AuthToken(ctx, token); err == nil {
  16. var userInfo *http_model.GetUserInfoData
  17. userInfo = &http_model.GetUserInfoData{
  18. EnterpriseId: auth.EnterpriseID,
  19. UserId: auth.ID,
  20. Role: auth.Role,
  21. }
  22. if auth.Role == "3" {
  23. fmt.Println("EnterpriseUser")
  24. } else if auth.Role == "4" {
  25. subaccountInfo, subaccountErr := db.FindSubAccountByPhone(ctx, auth.Phone)
  26. if subaccountErr != nil {
  27. return nil, subaccountErr
  28. }
  29. userInfo.SubAccountId = subaccountInfo.SubAccountId
  30. }
  31. return userInfo, nil
  32. } else {
  33. log.Infof("[LoginAuthMiddleware] auth fail,err:%+v", err)
  34. return nil, err
  35. }
  36. }
  37. return nil, nil
  38. }