123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package service
- import (
- "context"
- "fmt"
- log "github.com/sirupsen/logrus"
- "youngee_b_api/db"
- "youngee_b_api/model/http_model"
- )
- var BUserInfo *bUserInfo
- type bUserInfo struct {
- }
- // FindBUserInfoByToken 根据Token查询商家端用户信息
- func (*bUserInfo) FindBUserInfoByToken(ctx context.Context, token string) (*http_model.GetUserInfoData, error) {
- if token != "" {
- if auth, err := LoginAuth.AuthToken(ctx, token); err == nil {
- var userInfo *http_model.GetUserInfoData
- userInfo = &http_model.GetUserInfoData{
- EnterpriseId: auth.EnterpriseID,
- UserId: auth.ID,
- Role: auth.Role,
- }
- if auth.Role == "3" {
- fmt.Println("EnterpriseUser")
- } else if auth.Role == "4" {
- subaccountInfo, subaccountErr := db.FindSubAccountByPhone(ctx, auth.Phone)
- if subaccountErr != nil {
- return nil, subaccountErr
- }
- userInfo.SubAccountId = subaccountInfo.SubAccountId
- }
- return userInfo, nil
- } else {
- log.Infof("[LoginAuthMiddleware] auth fail,err:%+v", err)
- return nil, err
- }
- }
- return nil, nil
- }
|