From f0074facd9fa8f198bb6dee5b811ed646280a6fc Mon Sep 17 00:00:00 2001 From: Leufolium Date: Mon, 22 Apr 2024 07:15:46 +0800 Subject: [PATCH] by Robin at 20240422 --- .../proto/zone_collaborator_api.go | 7 ++- app/mix/controller/zone_collaborator_api.go | 7 ++- app/mix/service/apiservice.go | 62 ++++++++++++------- .../service/apiservice_business_validation.go | 43 ++++++++++++- 4 files changed, 89 insertions(+), 30 deletions(-) diff --git a/api/proto/zone_collaborator/proto/zone_collaborator_api.go b/api/proto/zone_collaborator/proto/zone_collaborator_api.go index cded3f76..0ba21ff9 100644 --- a/api/proto/zone_collaborator/proto/zone_collaborator_api.go +++ b/api/proto/zone_collaborator/proto/zone_collaborator_api.go @@ -57,9 +57,10 @@ type ApiListReq struct { } type ApiListData struct { - List []*ZoneCollaboratorApiVO `json:"list"` - Offset int `json:"offset"` - More int `json:"more"` + List []*ZoneCollaboratorApiVO `json:"list"` + ZoneThirdPartner *dbstruct.ZoneThirdPartner `json:"zone_third_partner"` + Offset int `json:"offset"` + More int `json:"more"` } type ApiListResp struct { diff --git a/app/mix/controller/zone_collaborator_api.go b/app/mix/controller/zone_collaborator_api.go index d2786003..c67f2b68 100644 --- a/app/mix/controller/zone_collaborator_api.go +++ b/app/mix/controller/zone_collaborator_api.go @@ -56,7 +56,7 @@ func ApiGetZoneCollaboratorList(ctx *gin.Context) { req.Limit = consts.DefaultPageSize } - list, ec := service.DefaultService.ApiGetZoneCollaboratorList(ctx, req) + list, zoneThirdPartner, ec := service.DefaultService.ApiGetZoneCollaboratorList(ctx, req) if ec != errcode.ErrCodeZoneCollaboratorSrvOk { logger.Error("ApiGetZoneCollaboratorList fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) @@ -71,8 +71,9 @@ func ApiGetZoneCollaboratorList(ctx *gin.Context) { mediafiller.FillList(ctx, mediaFillableList) data := &zone_collaborator_proto.ApiListData{ - List: list, - Offset: req.Offset + len(list), + List: list, + ZoneThirdPartner: zoneThirdPartner, + Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index d3408f6a..f12e76b3 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2987,6 +2987,11 @@ func (s *Service) ApiGetZoneThirdPartnerList(ctx *gin.Context, req *zone_third_p // ZoneCollaborator func (s *Service) ApiCreateZoneCollaborator(ctx *gin.Context, req *zone_collaborator_proto.ApiCreateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneCollaboratorSrvOk + + if ec = s.ApiCreateZoneCollaboratorBusinessValidate(ctx, req); ec != errcode.ErrCodeZoneCollaboratorSrvOk { + return + } + err := _DefaultZoneCollaborator.OpCreate(ctx, &zone_collaborator_proto.OpCreateReq{ BaseRequest: req.BaseRequest, ZoneCollaborator: req.ZoneCollaborator, @@ -3029,8 +3034,10 @@ func (s *Service) ApiDeleteZoneCollaborator(ctx *gin.Context, id int64) (ec errc return } -func (s *Service) ApiGetZoneCollaboratorList(ctx *gin.Context, req *zone_collaborator_proto.ApiListReq) (volist []*zone_collaborator_proto.ZoneCollaboratorApiVO, ec errcode.ErrCode) { +func (s *Service) ApiGetZoneCollaboratorList(ctx *gin.Context, req *zone_collaborator_proto.ApiListReq) (volist []*zone_collaborator_proto.ZoneCollaboratorApiVO, zoneThirdPartner *dbstruct.ZoneThirdPartner, ec errcode.ErrCode) { ec = errcode.ErrCodeZoneCollaboratorSrvOk + + // 查询协作者表 list, err := _DefaultZoneCollaborator.OpList(ctx, &zone_collaborator_proto.OpListReq{ BaseRequest: req.BaseRequest, Zid: req.Zid, @@ -3041,35 +3048,44 @@ func (s *Service) ApiGetZoneCollaboratorList(ctx *gin.Context, req *zone_collabo ec = errcode.ErrCodeZoneCollaboratorSrvFail return } - if len(list) == 0 { - return make([]*zone_collaborator_proto.ZoneCollaboratorApiVO, 0), errcode.ErrCodeZoneCollaboratorNotExist - } - midSet := make(map[int64]*dbstruct.Moment) - mids := make([]int64, 0) - for _, zone_collaborator := range list { - mid := zone_collaborator.GetCollaboratorMid() - if midSet[mid] == nil { - midSet[mid] = &dbstruct.Moment{} - mids = append(mids, mid) + // 填充协作者VO + volist = make([]*zone_collaborator_proto.ZoneCollaboratorApiVO, 0) + if len(list) > 0 { + midSet := make(map[int64]*dbstruct.Moment) + mids := make([]int64, 0) + for _, zone_collaborator := range list { + mid := zone_collaborator.GetCollaboratorMid() + if midSet[mid] == nil { + midSet[mid] = &dbstruct.Moment{} + mids = append(mids, mid) + } + } + + acctMp, err := _DefaultAccount.GetAccountMapByMids(ctx, mids) + if err != nil { + logger.Error("_DefaultAccount GetAccountMapByMids fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeAccountSrvFail + return + } + + for _, zone_collaborator := range list { + mid := zone_collaborator.GetCollaboratorMid() + vo := &zone_collaborator_proto.ZoneCollaboratorApiVO{ + ZoneCollaborator: zone_collaborator, + Account: acctMp[mid], + } + volist = append(volist, vo) } } - acctMp, err := _DefaultAccount.GetAccountMapByMids(ctx, mids) + // 查询代运营信息 + zoneThirdPartner, err = _DefaultZoneThirdPartner.GetZoneThirdPartnerByZid(ctx, util.DerefInt64(req.Zid)) if err != nil { - logger.Error("_DefaultAccount GetAccountMapByMids fail, req: %v, err: %v", util.ToJson(req), err) - ec = errcode.ErrCodeAccountSrvFail + logger.Error("_DefaultZoneThirdPartner GetZoneThirdPartnerByZid fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneThirdPartnerSrvFail return } - for _, zone_collaborator := range list { - mid := zone_collaborator.GetCollaboratorMid() - vo := &zone_collaborator_proto.ZoneCollaboratorApiVO{ - ZoneCollaborator: zone_collaborator, - Account: acctMp[mid], - } - volist = append(volist, vo) - } - return } diff --git a/app/mix/service/apiservice_business_validation.go b/app/mix/service/apiservice_business_validation.go index 5e34d7aa..487ddf7b 100644 --- a/app/mix/service/apiservice_business_validation.go +++ b/app/mix/service/apiservice_business_validation.go @@ -10,6 +10,7 @@ import ( streamerproto "service/api/proto/streamer/proto" streamerauthapprovalproto "service/api/proto/streamerauthapproval/proto" vericodeproto "service/api/proto/vericode/proto" + zone_collaborator_proto "service/api/proto/zone_collaborator/proto" zone_third_partner_proto "service/api/proto/zone_third_partner/proto" zonemomentproto "service/api/proto/zonemoment/proto" businessvalidator "service/app/mix/service/business_validator" @@ -581,7 +582,7 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon func (s *Service) ApiCreateZoneThirdPartnerBusinessValidate(ctx *gin.Context, req *zone_third_partner_proto.ApiCreateReq) (vericode *dbstruct.VeriCode, ec errcode.ErrCode) { ec = errcode.ErrCodeLoginSrvOk - // 1.业务校验 + // 1.登录业务校验 req.CalcPhoneHash() //计算手机号哈希 resultList := businessvalidator.NewLoginBusinessValidator(ctx, req). QueryVeriCode(_DefaultVeriCode.OpListByPhoneHash). @@ -598,5 +599,45 @@ func (s *Service) ApiCreateZoneThirdPartnerBusinessValidate(ctx *gin.Context, re logger.Error("ApiCreateZoneThirdPartner business validation failed!") return } + + // 3.鉴权校验 + resultList = businessvalidator.NewAuthBusinessValidator(ctx, req). + EnsureIsNotOperatingHisOwn(util.DerefInt64(req.ThirdPartnerMid)). + Validate(). + Collect() + ec, _ = resultList[0].(errcode.ErrCode) + // 4.错误信息 + if ec == errcode.ErrCodeOperationToSelfIsNotPermitted { + ec = errcode.ErrCodeZoneThirdPartnerWrongThirdPartner + } + if ec != errcode.ErrCodeOk { + logger.Error("ApiCreateZoneThirdPartner business validation failed!") + return + } + + return +} + +func (s *Service) ApiCreateZoneCollaboratorBusinessValidate(ctx *gin.Context, req *zone_collaborator_proto.ApiCreateReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeZoneCollaboratorSrvOk + + result := businessvalidator.NewAuthBusinessValidator(ctx, req). + QueryZoneThirdPartnerByZid(_DefaultZoneThirdPartner.GetZoneThirdPartnerByZid, util.DerefInt64(req.Zid)). + EnsureZoneThirdPartnerExist(). + EnsureZoneCollaboratorCreaterIsZoneThirdPartner(req.GetBaseRequest().Mid). + EnsureIsNotOperatingHisOwn(util.DerefInt64(req.CollaboratorMid)). + QueryAccountForUid(_DefaultAccount.OpListByMid, util.DerefInt64(req.CollaboratorMid)). + EnsureIsNotThisRole(consts.Streamer). + Validate(). + Collect() + ec = result[0].(errcode.ErrCode) + if ec == errcode.ErrCodeOperationToSelfIsNotPermitted || ec == errcode.ErrCodeRolePrivilegesNotEnough { + ec = errcode.ErrCodeZoneCollaboratorWrongCollaborator + } + if ec != errcode.ErrCodeOk { + logger.Error("ApiGetAccountRelationCount business validation failed") + return + } + return }