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 e1bde6e1..566e8358 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -4444,6 +4444,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 @@ -4456,6 +4485,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 }