From 85bef83752b3027f8fa654ef679fc1e53d058526 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 24 Apr 2026 16:33:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/service/device/service.go | 16 ++++++++-------- internal/service/iot_card/service.go | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/service/device/service.go b/internal/service/device/service.go index ebffad7..e034e98 100644 --- a/internal/service/device/service.go +++ b/internal/service/device/service.go @@ -255,7 +255,7 @@ func (s *Service) GetCardByICCID(ctx context.Context, iccid string) (*model.IotC // AllocateDevices 批量分配设备 func (s *Service) AllocateDevices(ctx context.Context, req *dto.AllocateDevicesRequest, operatorID uint, operatorShopID *uint) (*dto.AllocateDevicesResponse, error) { - // 验证目标店铺是否为直属下级 + // 代理仅可分配给直属下级;平台/超级管理员可跨级分配 if err := s.validateDirectSubordinate(ctx, operatorShopID, req.TargetShopID); err != nil { return nil, err } @@ -470,14 +470,14 @@ func (s *Service) validateDirectSubordinate(ctx context.Context, operatorShopID return err } + // 平台/超级管理员可跨级分配到任意店铺(前置已校验目标店铺存在) if operatorShopID == nil { - if targetShop.ParentID != nil { - return errors.ErrNotDirectSubordinate - } - } else { - if targetShop.ParentID == nil || *targetShop.ParentID != *operatorShopID { - return errors.ErrNotDirectSubordinate - } + return nil + } + + // 代理仅允许分配给直属下级店铺 + if targetShop.ParentID == nil || *targetShop.ParentID != *operatorShopID { + return errors.ErrNotDirectSubordinate } return nil diff --git a/internal/service/iot_card/service.go b/internal/service/iot_card/service.go index 9900d1e..10a3e59 100644 --- a/internal/service/iot_card/service.go +++ b/internal/service/iot_card/service.go @@ -613,14 +613,14 @@ func (s *Service) validateDirectSubordinate(ctx context.Context, operatorShopID return err } + // 平台/超级管理员可跨级分配到任意店铺(前置已校验目标店铺存在) if operatorShopID == nil { - if targetShop.ParentID != nil { - return errors.ErrNotDirectSubordinate - } - } else { - if targetShop.ParentID == nil || *targetShop.ParentID != *operatorShopID { - return errors.ErrNotDirectSubordinate - } + return nil + } + + // 代理仅允许分配给直属下级店铺 + if targetShop.ParentID == nil || *targetShop.ParentID != *operatorShopID { + return errors.ErrNotDirectSubordinate } return nil