From f73d0f9a75115e88a4b7815f8fb9a991b9e32509 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Tue, 6 Aug 2024 14:12:48 +0800 Subject: [PATCH 1/3] by Robin at 20240806 --- .../service/opservice_business_validation.go | 12 ++++-- app/mix/service/service.go | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/app/mix/service/opservice_business_validation.go b/app/mix/service/opservice_business_validation.go index 27644dbf..f6c02ff4 100644 --- a/app/mix/service/opservice_business_validation.go +++ b/app/mix/service/opservice_business_validation.go @@ -1402,13 +1402,17 @@ func (s *Service) OpHeadZoneMomentBusinessValidate(ctx *gin.Context, req *zonemo func (s *Service) OpUpdateZoneThirdPartnerBusinessValidate(ctx *gin.Context, req *zone_third_partner_proto.OpUpdateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeZoneThirdPartnerSrvOk // 1.业务校验 - result := businessvalidator.NewAuthBusinessValidator(ctx, req). - EnsureZoneThirdPartnerSharingRatioIsNotTooLarge(req.ZoneThirdPartner.GetSharingRatio()). - EnsureZoneThirdPartnerSharingRatioIsEnough(func(ctx *gin.Context, zid int64) ([]*dbstruct.ZoneCollaborator, error) { + validator := businessvalidator.NewAuthBusinessValidator(ctx, req). + EnsureZoneThirdPartnerSharingRatioIsNotTooLarge(req.ZoneThirdPartner.GetSharingRatio()) + // 若不更新代运营,则确保代运营分成比例足够 + if req.ZoneThirdPartner.ThirdPartnerMid == nil { + validator.EnsureZoneThirdPartnerSharingRatioIsEnough(func(ctx *gin.Context, zid int64) ([]*dbstruct.ZoneCollaborator, error) { return _DefaultZoneCollaborator.OpList(ctx, &zone_collaborator_proto.OpListReq{ Zid: goproto.Int64(zid), }) - }, req.ZoneThirdPartner.GetZid(), req.ZoneThirdPartner.GetSharingRatio()). + }, req.ZoneThirdPartner.GetZid(), req.ZoneThirdPartner.GetSharingRatio()) + } + result := validator. Validate(). Collect() if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { diff --git a/app/mix/service/service.go b/app/mix/service/service.go index e7491cda..1d56a429 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -4442,6 +4442,35 @@ func (s *Service) OpUpdateZoneThirdPartner(ctx *gin.Context, req *zone_third_par return } + zid := req.ZoneThirdPartner.GetZid() + // 如果更新代运营,则删除旧代运营及协作者团队 + if req.ZoneThirdPartner.ThirdPartnerMid != nil { + _, err := _DefaultZoneThirdPartner.OpDeleteByZid(ctx, zid) + if err != nil { + logger.Error("OpDelete fail, id: %v, err: %v", zid, err) + ec = errcode.ErrCodeZoneThirdPartnerSrvFail + return + } + + zclist, err := _DefaultZoneCollaborator.OpList(ctx, &zone_collaborator_proto.OpListReq{ + Zid: goproto.Int64(zid), + }) + if err != nil { + logger.Error("OpList fail, id: %v, err: %v", zid, err) + ec = errcode.ErrCodeZoneCollaboratorSrvFail + return + } + + for _, zc := range zclist { + err := _DefaultZoneCollaborator.OpDelete(ctx, zc.GetId()) + if err != nil { + logger.Error("OpDelete fail, id: %v, err: %v", zid, err) + ec = errcode.ErrCodeZoneCollaboratorSrvFail + return + } + } + } + err := _DefaultZoneThirdPartner.OpUpdateByZid(ctx, req) if err == qmgo.ErrNoSuchDocuments { ec = errcode.ErrCodeZoneThirdPartnerNotExist @@ -4454,6 +4483,14 @@ func (s *Service) OpUpdateZoneThirdPartner(ctx *gin.Context, req *zone_third_par return } + // 若更新代运营,则新代运营加入空间 + if req.ZoneThirdPartner.ThirdPartnerMid != nil { + _err := _DefaultVas.ZoneFreeJoinThirdPartner(ctx, req.ZoneThirdPartner.GetThirdPartnerMid(), req.ZoneThirdPartner.GetZid()) + if _err != nil { + logger.Error("ZoneFreeJoinThirdPartner fail, mid: %v, zid: %v, err: %v", req.ZoneThirdPartner.GetThirdPartnerMid(), req.ZoneThirdPartner.GetZid(), _err) + } + } + return } From 99e9c625cd752a410b7b0c17418ef9a32edd0130 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Tue, 6 Aug 2024 18:03:59 +0800 Subject: [PATCH 2/3] 1 --- app/mix/service/service.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 1d56a429..02f2ac0f 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -4443,15 +4443,8 @@ func (s *Service) OpUpdateZoneThirdPartner(ctx *gin.Context, req *zone_third_par } zid := req.ZoneThirdPartner.GetZid() - // 如果更新代运营,则删除旧代运营及协作者团队 + // 如果更新代运营,则移除协作者团队 if req.ZoneThirdPartner.ThirdPartnerMid != nil { - _, err := _DefaultZoneThirdPartner.OpDeleteByZid(ctx, zid) - if err != nil { - logger.Error("OpDelete fail, id: %v, err: %v", zid, err) - ec = errcode.ErrCodeZoneThirdPartnerSrvFail - return - } - zclist, err := _DefaultZoneCollaborator.OpList(ctx, &zone_collaborator_proto.OpListReq{ Zid: goproto.Int64(zid), }) From c46ef272881c2adb95fd00551c35370ead7f3f05 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Tue, 6 Aug 2024 18:06:05 +0800 Subject: [PATCH 3/3] 1 --- app/mix/service/opservice_business_validation.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/mix/service/opservice_business_validation.go b/app/mix/service/opservice_business_validation.go index f6c02ff4..e885ed86 100644 --- a/app/mix/service/opservice_business_validation.go +++ b/app/mix/service/opservice_business_validation.go @@ -1403,6 +1403,7 @@ func (s *Service) OpUpdateZoneThirdPartnerBusinessValidate(ctx *gin.Context, req ec = errcode.ErrCodeZoneThirdPartnerSrvOk // 1.业务校验 validator := businessvalidator.NewAuthBusinessValidator(ctx, req). + EnsureZoneThirdPartnerIsNotZoneCreater(_DefaultZone.GetById, req.ZoneThirdPartner.GetZid(), req.ZoneThirdPartner.GetThirdPartnerMid()). EnsureZoneThirdPartnerSharingRatioIsNotTooLarge(req.ZoneThirdPartner.GetSharingRatio()) // 若不更新代运营,则确保代运营分成比例足够 if req.ZoneThirdPartner.ThirdPartnerMid == nil {