diff --git a/api/proto/account/proto/account_op.go b/api/proto/account/proto/account_op.go index 583231af..16edf625 100644 --- a/api/proto/account/proto/account_op.go +++ b/api/proto/account/proto/account_op.go @@ -97,6 +97,21 @@ type OpListByUserIdResp struct { Data *OpListByUserIdData `json:"data"` } +// 根据UserId查询手机号 +type OpGetMobilePhoneByUserIdReq struct { + base.BaseRequest + UserId *int64 `json:"user_id"` //user_id查询 +} + +type OpGetMobilePhoneByUserIdData struct { + MobilePhone string `json:"mobile_phone"` +} + +type OpGetMobilePhoneByUserIdResp struct { + base.BaseResponse + Data *OpGetMobilePhoneByUserIdData `json:"data"` +} + // 根据UserId模糊查询(和姓名取交集) type OpListFuzzilyByUserIdReq struct { base.BaseRequest diff --git a/api/proto/account/proto/not_null_def_op.go b/api/proto/account/proto/not_null_def_op.go index fb799be0..dbf02ee2 100644 --- a/api/proto/account/proto/not_null_def_op.go +++ b/api/proto/account/proto/not_null_def_op.go @@ -23,6 +23,12 @@ func (p *OpListByUserIdReq) ProvideNotNullValue() (params []*validator.JsonParam return params } +func (p *OpGetMobilePhoneByUserIdReq) ProvideNotNullValue() (params []*validator.JsonParam) { + params = make([]*validator.JsonParam, 1) + params[0] = validator.NewInt64PtrParam("查询UserId不可为空!", p.UserId) + return params +} + func (p *OpListFuzzilyByUserIdReq) ProvideNotNullValue() (params []*validator.JsonParam) { params = make([]*validator.JsonParam, 1) params[0] = validator.NewInt64PtrParam("查询UserId不可为空!", p.UserId) diff --git a/app/mix/controller/account_op.go b/app/mix/controller/account_op.go index 5a9a8461..1f512ddb 100644 --- a/app/mix/controller/account_op.go +++ b/app/mix/controller/account_op.go @@ -98,6 +98,23 @@ func OpGetAccountListByUserId(ctx *gin.Context) { ReplyOk(ctx, data) } +func OpGetMobilePhoneByUserId(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*accountproto.OpGetMobilePhoneByUserIdReq) + + mobilePhone, ec := service.DefaultService.OpGetMobilePhoneByUserId(ctx, req) + if ec != errcode.ErrCodeAccountSrvOk { + logger.Error("OpGetMobilePhoneByUserId fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + data := &accountproto.OpGetMobilePhoneByUserIdData{ + MobilePhone: mobilePhone, + } + + ReplyOk(ctx, data) +} + func OpGetAccountListFuzzilyByUserId(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.OpListFuzzilyByUserIdReq) diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 77ed3504..d93de05c 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -252,6 +252,7 @@ func Init(r *gin.Engine) { opAccountGroup.POST("list_by_mid", middleware.JSONParamValidator(accountproto.OpListByMidReq{}), middleware.JwtAuthenticator(), OpGetAccountListByMid) //opAccountGroup.POST("list_by_mids", middleware.JSONParamValidator(accountproto.OpListByMidsReq{}), middleware.JwtAuthenticator(), OpGetAccountListByMids) opAccountGroup.POST("list_by_user_id", middleware.JSONParamValidator(accountproto.OpListByUserIdReq{}), middleware.JwtAuthenticator(), OpGetAccountListByUserId) + opAccountGroup.POST("get_mobile_phone_by_user_id", middleware.JSONParamValidator(accountproto.OpGetMobilePhoneByUserIdReq{}), middleware.JwtAuthenticator(), OpGetMobilePhoneByUserId) opAccountGroup.POST("list_fuzzily_by_user_id", middleware.JSONParamValidator(accountproto.OpListFuzzilyByUserIdReq{}), middleware.JwtAuthenticator(), OpGetAccountListFuzzilyByUserId) opAccountGroup.POST("list_fuzzily_by_name", middleware.JSONParamValidator(accountproto.OpListFuzzilyByNameReq{}), middleware.JwtAuthenticator(), OpGetAccountListFuzzilyByName) opAccountGroup.POST("list_others_by_mid", middleware.JSONParamValidator(accountproto.OpListOthersByMidReq{}), middleware.JwtAuthenticator(), OpGetAccountListForOthersByMid) diff --git a/app/mix/service/opservice_business_validation.go b/app/mix/service/opservice_business_validation.go index 262cc7ff..5c6e9007 100644 --- a/app/mix/service/opservice_business_validation.go +++ b/app/mix/service/opservice_business_validation.go @@ -266,6 +266,24 @@ func (s *Service) OpGetAccountListByUserIdBusinessValidate(ctx *gin.Context, req return } +func (s *Service) OpGetMobilePhoneByUserIdBusinessValidate(ctx *gin.Context, req *accountproto.OpGetMobilePhoneByUserIdReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountSrvOk + + // 1.业务校验 + result := businessvalidator.NewAuthBusinessValidator(ctx, req). + QueryAccount(_DefaultAccount.OpListByMid). + EnsureAccountExist(). + EnsureIsOpRole(). + Validate(). + Collect() + if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { + logger.Error("OpGetMobilePhoneByUserId business validation failed") + return + } + + return +} + func (s *Service) OpGetAccountListFuzzilyByUserIdBusinessValidate(ctx *gin.Context, req *accountproto.OpListFuzzilyByUserIdReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeAccountSrvOk diff --git a/app/mix/service/service.go b/app/mix/service/service.go index ff5ec41d..18361d70 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -1,6 +1,7 @@ package service import ( + "encoding/base64" "errors" "fmt" "service/api/base" @@ -820,6 +821,32 @@ func (s *Service) OpGetAccountListByUserId(ctx *gin.Context, req *accountproto.O return } +func (s *Service) OpGetMobilePhoneByUserId(ctx *gin.Context, req *accountproto.OpGetMobilePhoneByUserIdReq) (mobilePhone string, ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountSrvOk + + // 业务鉴权 + if ec = s.OpGetMobilePhoneByUserIdBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountSrvOk { + return + } + + account, err := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{ + UserId: req.UserId, + }) + if err != nil { + logger.Error("OpListByUserId fail, err: %v", err) + ec = errcode.ErrCodeAccountSrvFail + return + } + if account != nil { + base64DecryptedBytes, _ := base64.StdEncoding.DecodeString(util.DerefString(account.MobilePhone)) + phoneBytes, _ := mycrypto.CryptoServiceInstance().AES.Decrypt(base64DecryptedBytes) + mobilePhone = string(phoneBytes) + + } + + return +} + func (s *Service) OpGetAccountListFuzzilyByUserId(ctx *gin.Context, req *accountproto.OpListFuzzilyByUserIdReq) (volist []*accountproto.OpListVO, ec errcode.ErrCode) { ec = errcode.ErrCodeAccountSrvOk