feat: 新增店铺联级查询接口
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m3s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m3s
- 新增 GET /api/admin/shops/cascade 接口,支持按店铺名模糊查询和上级ID过滤
- Store 层新增 ListForCascade(支持数据权限过滤)和 GetParentIDsWithChildren 方法
- Service 层新增 ListCascade,批量判断 has_children 避免 N+1 查询
- 返回格式:[{id, shop_name, has_children}]
💘 Generated with Crush
Assisted-by: Claude Sonnet 4.6 via Crush <crush@charm.land>
This commit is contained in:
@@ -350,6 +350,44 @@ func (s *Service) List(ctx context.Context, opts *store.QueryOptions, filters ma
|
||||
return s.shopStore.List(ctx, opts, filters)
|
||||
}
|
||||
|
||||
// ListCascade 联级查询店铺,用于新增店铺或其他场景选择上级店铺
|
||||
func (s *Service) ListCascade(ctx context.Context, req *dto.ShopCascadeRequest) ([]*dto.ShopCascadeItem, error) {
|
||||
shops, err := s.shopStore.ListForCascade(ctx, req.ShopName, req.ParentID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(errors.CodeInternalError, err, "查询店铺失败")
|
||||
}
|
||||
|
||||
if len(shops) == 0 {
|
||||
return []*dto.ShopCascadeItem{}, nil
|
||||
}
|
||||
|
||||
ids := make([]uint, 0, len(shops))
|
||||
for _, shop := range shops {
|
||||
ids = append(ids, shop.ID)
|
||||
}
|
||||
|
||||
childParentIDs, err := s.shopStore.GetParentIDsWithChildren(ctx, ids)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(errors.CodeInternalError, err, "查询下级店铺失败")
|
||||
}
|
||||
|
||||
hasChildrenSet := make(map[uint]bool, len(childParentIDs))
|
||||
for _, pid := range childParentIDs {
|
||||
hasChildrenSet[pid] = true
|
||||
}
|
||||
|
||||
result := make([]*dto.ShopCascadeItem, 0, len(shops))
|
||||
for _, shop := range shops {
|
||||
result = append(result, &dto.ShopCascadeItem{
|
||||
ID: shop.ID,
|
||||
ShopName: shop.ShopName,
|
||||
HasChildren: hasChildrenSet[shop.ID],
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Service) Delete(ctx context.Context, id uint) error {
|
||||
currentUserID := middleware.GetUserIDFromContext(ctx)
|
||||
if currentUserID == 0 {
|
||||
|
||||
Reference in New Issue
Block a user