From 424594ba024da68b974b3268e9b5bb43b8396ea9 Mon Sep 17 00:00:00 2001 From: zhx Date: Wed, 1 Jul 2026 18:44:06 +0800 Subject: [PATCH] fix: allow agency search by parent bd display id --- .../user-service/internal/service/host/service_test.go | 7 +++++++ .../user-service/internal/storage/mysql/host/queries.go | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/services/user-service/internal/service/host/service_test.go b/services/user-service/internal/service/host/service_test.go index 742328ce..c8a9e770 100644 --- a/services/user-service/internal/service/host/service_test.go +++ b/services/user-service/internal/service/host/service_test.go @@ -867,6 +867,13 @@ func TestAdminCreateAgencyControlsAppSearch(t *testing.T) { if len(agencies) != 1 || agencies[0].AgencyID != created.Agency.AgencyID { t.Fatalf("created agency should be searchable by owner display id: %+v", agencies) } + agencies, err = svc.SearchAgencies(ctx, 902, displayID(900), 20) + if err != nil { + t.Fatalf("SearchAgencies by parent BD display id failed: %v", err) + } + if len(agencies) != 1 || agencies[0].AgencyID != created.Agency.AgencyID { + t.Fatalf("created agency should be searchable by parent BD display id: %+v", agencies) + } disabledJoin, err := svc.SetAgencyJoinEnabled(ctx, hostservice.SetAgencyJoinEnabledInput{ CommandID: "admin-disable-agency-join-901", diff --git a/services/user-service/internal/storage/mysql/host/queries.go b/services/user-service/internal/storage/mysql/host/queries.go index 893610e3..d3fd240f 100644 --- a/services/user-service/internal/storage/mysql/host/queries.go +++ b/services/user-service/internal/storage/mysql/host/queries.go @@ -42,6 +42,8 @@ func (r *Repository) SearchAgencies(ctx context.Context, command hostservice.Sea FROM agencies a INNER JOIN users owner ON owner.app_code = a.app_code AND owner.user_id = a.owner_user_id + LEFT JOIN users parent_bd + ON parent_bd.app_code = a.app_code AND parent_bd.user_id = a.parent_bd_user_id LEFT JOIN agency_memberships active_member ON active_member.app_code = a.app_code AND active_member.agency_id = a.agency_id @@ -55,8 +57,9 @@ func (r *Repository) SearchAgencies(ctx context.Context, command hostservice.Sea args := []any{hostdomain.MembershipStatusActive, appcode.FromContext(ctx), country, hostdomain.AgencyStatusActive} if strings.TrimSpace(command.Keyword) != "" { keyword := strings.TrimSpace(command.Keyword) - query += ` AND (a.name LIKE ? OR a.agency_id = ? OR owner.current_display_user_id = ?)` - args = append(args, "%"+keyword+"%", int64FromKeyword(keyword), keyword) + // Host 申请页里运营常按 BD 短号找“这个 BD 下面的公会”,因此关键字同时匹配 owner 和 parent BD。 + query += ` AND (a.name LIKE ? OR a.agency_id = ? OR owner.current_display_user_id = ? OR parent_bd.current_display_user_id = ?)` + args = append(args, "%"+keyword+"%", int64FromKeyword(keyword), keyword, keyword) } query += ` GROUP BY