跨级
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m7s

This commit is contained in:
2026-04-24 16:33:13 +08:00
parent bc344f892c
commit 85bef83752
2 changed files with 15 additions and 15 deletions

View File

@@ -255,7 +255,7 @@ func (s *Service) GetCardByICCID(ctx context.Context, iccid string) (*model.IotC
// AllocateDevices 批量分配设备 // AllocateDevices 批量分配设备
func (s *Service) AllocateDevices(ctx context.Context, req *dto.AllocateDevicesRequest, operatorID uint, operatorShopID *uint) (*dto.AllocateDevicesResponse, error) { 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 { if err := s.validateDirectSubordinate(ctx, operatorShopID, req.TargetShopID); err != nil {
return nil, err return nil, err
} }
@@ -470,14 +470,14 @@ func (s *Service) validateDirectSubordinate(ctx context.Context, operatorShopID
return err return err
} }
// 平台/超级管理员可跨级分配到任意店铺(前置已校验目标店铺存在)
if operatorShopID == nil { if operatorShopID == nil {
if targetShop.ParentID != nil { return nil
return errors.ErrNotDirectSubordinate }
}
} else { // 代理仅允许分配给直属下级店铺
if targetShop.ParentID == nil || *targetShop.ParentID != *operatorShopID { if targetShop.ParentID == nil || *targetShop.ParentID != *operatorShopID {
return errors.ErrNotDirectSubordinate return errors.ErrNotDirectSubordinate
}
} }
return nil return nil

View File

@@ -613,14 +613,14 @@ func (s *Service) validateDirectSubordinate(ctx context.Context, operatorShopID
return err return err
} }
// 平台/超级管理员可跨级分配到任意店铺(前置已校验目标店铺存在)
if operatorShopID == nil { if operatorShopID == nil {
if targetShop.ParentID != nil { return nil
return errors.ErrNotDirectSubordinate }
}
} else { // 代理仅允许分配给直属下级店铺
if targetShop.ParentID == nil || *targetShop.ParentID != *operatorShopID { if targetShop.ParentID == nil || *targetShop.ParentID != *operatorShopID {
return errors.ErrNotDirectSubordinate return errors.ErrNotDirectSubordinate
}
} }
return nil return nil