1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package service
- import (
- "context"
- "fmt"
- log "github.com/sirupsen/logrus"
- "youngee_b_api/db"
- "youngee_b_api/model/http_model"
- )
- var SUserInfo *sUserInfo
- type sUserInfo struct {
- }
- // FindBUserInfoByToken 根据Token查询商家端用户信息
- func (*sUserInfo) 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{
- SupplierId: auth.SupplierId,
- UserId: auth.ID,
- Role: auth.Role,
- }
- if auth.Role == "6" {
- // 服务商主账号
- fmt.Println("SupplierUser")
- userInfo.JobName = "主账号无岗位名称"
- userInfo.CommercialCenter = "1"
- userInfo.CommercialManagement = "1"
- userInfo.CooperatePermission = "1"
- userInfo.FinancialPermission = "1"
- } else if auth.Role == "7" {
- // 服务商子账号
- subaccountInfo, subaccountErr := db.FindSubAccountByPhone(ctx, auth.Phone)
- if subaccountErr != nil {
- return nil, subaccountErr
- }
- userInfo.SubAccountId = subaccountInfo.SubAccountId
- jobInfo, jonErr := db.FindJobByJobId(ctx, subaccountInfo.JobId)
- if jonErr != nil {
- return nil, jonErr
- }
- userInfo.JobName = jobInfo.JobName
- userInfo.CommercialCenter = jobInfo.CommercialCenter
- userInfo.CommercialManagement = jobInfo.CommercialManagement
- userInfo.CooperatePermission = jobInfo.CooperatePermission
- userInfo.FinancialPermission = jobInfo.FinancialPermission
- }
- supplierUserInfo, supplierUserErr := db.GetUserByPhone(ctx, auth.Phone)
- if supplierUserErr != nil {
- return nil, supplierUserErr
- }
- if supplierUserInfo != nil {
- userInfo.AuthStatus = supplierUserInfo.AuthStatus
- }
- return userInfo, nil
- } else {
- log.Infof("[LoginAuthMiddleware] auth fail,err:%+v", err)
- return nil, err
- }
- }
- return nil, nil
- }
|