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