新增排查自己的逻辑
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m53s

This commit is contained in:
2026-05-09 15:22:29 +08:00
parent 09cf0be86e
commit ebaf112c80
3 changed files with 16 additions and 8 deletions

View File

@@ -229,25 +229,32 @@ func (s *ShopStore) GetByIDs(ctx context.Context, ids []uint) ([]*model.Shop, er
return shops, nil
}
// ListForCascade 联级查询店铺(支持按名称模糊查询按上级ID过滤
func (s *ShopStore) ListForCascade(ctx context.Context, shopName string, parentID *uint) ([]*model.Shop, error) {
// ListForCascade 联级查询店铺(支持按名称模糊查询按上级ID过滤和排除自身
func (s *ShopStore) ListForCascade(ctx context.Context, shopName string, parentID *uint, excludeSelf bool) ([]*model.Shop, error) {
query := s.db.WithContext(ctx).Model(&model.Shop{})
query = middleware.ApplyShopIDFilter(ctx, query)
currentShopID := middleware.GetShopIDFromContext(ctx)
if parentID != nil {
query = query.Where("parent_id = ?", *parentID)
} else if middleware.GetUserTypeFromContext(ctx) == constants.UserTypeAgent {
shopID := middleware.GetShopIDFromContext(ctx)
if shopID == 0 {
if currentShopID == 0 {
query = query.Where("1 = 0")
} else if excludeSelf {
// 排除自身时,代理账号的级联根节点从自身下级开始。
query = query.Where("parent_id = ?", currentShopID)
} else {
// 代理账号的级联根节点是自己的店铺,避免默认根查询落到平台顶级店铺。
query = query.Where("id = ?", shopID)
query = query.Where("id = ?", currentShopID)
}
} else {
query = query.Where("parent_id IS NULL")
}
if excludeSelf && currentShopID > 0 {
query = query.Where("id <> ?", currentShopID)
}
if shopName != "" {
query = query.Where("shop_name LIKE ?", "%"+shopName+"%")
}