From f60d4eac878de40006693efd8284dd965dcd33ee Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 12 Dec 2025 03:04:55 -0800 Subject: [PATCH] feat(authorization): remove region matching requirement for team rewards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 省团队(AUTH_PROVINCE_COMPANY)和市团队(AUTH_CITY_COMPANY)收益分配不再要求 认种者选择的省市与被授权用户的省市一致,只要在推荐链上有授权即可获得收益。 省区域(PROVINCE_COMPANY)和市区域(CITY_COMPANY)收益仍保持省市匹配要求。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../authorization-application.service.ts | 8 ++-- .../authorization-role.repository.ts | 12 ++++++ .../authorization-role.repository.impl.ts | 40 +++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/backend/services/authorization-service/src/application/services/authorization-application.service.ts b/backend/services/authorization-service/src/application/services/authorization-application.service.ts index c6739859..0302de81 100644 --- a/backend/services/authorization-service/src/application/services/authorization-application.service.ts +++ b/backend/services/authorization-service/src/application/services/authorization-application.service.ts @@ -1128,9 +1128,9 @@ export class AuthorizationApplicationService { } // 2. 查找祖先链中所有授权省公司(包括 benefitActive=false) - const ancestorAuthProvinces = await this.authorizationRepository.findAuthProvinceByAccountSequencesAndRegion( + // 注意:省团队收益不再要求省份匹配,只要推荐链上有省团队授权即可获得收益 + const ancestorAuthProvinces = await this.authorizationRepository.findAuthProvinceByAccountSequences( ancestorAccountSequences.map((seq) => BigInt(seq)), - provinceCode, ) if (ancestorAuthProvinces.length === 0) { @@ -1430,9 +1430,9 @@ export class AuthorizationApplicationService { } // 2. 查找祖先链中所有授权市公司(包括 benefitActive=false) - const ancestorAuthCities = await this.authorizationRepository.findAuthCityByAccountSequencesAndRegion( + // 注意:市团队收益不再要求城市匹配,只要推荐链上有市团队授权即可获得收益 + const ancestorAuthCities = await this.authorizationRepository.findAuthCityByAccountSequences( ancestorAccountSequences.map((seq) => BigInt(seq)), - cityCode, ) if (ancestorAuthCities.length === 0) { diff --git a/backend/services/authorization-service/src/domain/repositories/authorization-role.repository.ts b/backend/services/authorization-service/src/domain/repositories/authorization-role.repository.ts index a5db54dd..da4fe71f 100644 --- a/backend/services/authorization-service/src/domain/repositories/authorization-role.repository.ts +++ b/backend/services/authorization-service/src/domain/repositories/authorization-role.repository.ts @@ -50,6 +50,7 @@ export interface IAuthorizationRoleRepository { /** * 批量查询指定 accountSequence 列表中具有授权省公司授权的用户(包括 benefitActive=false) * 用于省团队权益分配计算 + * @deprecated 使用 findAuthProvinceByAccountSequences 替代,省团队收益不再要求省份匹配 */ findAuthProvinceByAccountSequencesAndRegion( accountSequences: bigint[], @@ -58,11 +59,22 @@ export interface IAuthorizationRoleRepository { /** * 批量查询指定 accountSequence 列表中具有授权市公司授权的用户(包括 benefitActive=false) * 用于市团队权益分配计算 + * @deprecated 使用 findAuthCityByAccountSequences 替代,市团队收益不再要求城市匹配 */ findAuthCityByAccountSequencesAndRegion( accountSequences: bigint[], cityCode: string, ): Promise + /** + * 批量查询指定 accountSequence 列表中具有授权省公司(省团队)授权的用户(包括 benefitActive=false) + * 用于省团队权益分配计算,不要求省份匹配 + */ + findAuthProvinceByAccountSequences(accountSequences: bigint[]): Promise + /** + * 批量查询指定 accountSequence 列表中具有授权市公司(市团队)授权的用户(包括 benefitActive=false) + * 用于市团队权益分配计算,不要求城市匹配 + */ + findAuthCityByAccountSequences(accountSequences: bigint[]): Promise /** * 查找指定省份的正式省公司授权(用于省区域权益分配) */ diff --git a/backend/services/authorization-service/src/infrastructure/persistence/repositories/authorization-role.repository.impl.ts b/backend/services/authorization-service/src/infrastructure/persistence/repositories/authorization-role.repository.impl.ts index 4ff9c4f2..d6852c2e 100644 --- a/backend/services/authorization-service/src/infrastructure/persistence/repositories/authorization-role.repository.impl.ts +++ b/backend/services/authorization-service/src/infrastructure/persistence/repositories/authorization-role.repository.impl.ts @@ -299,6 +299,46 @@ export class AuthorizationRoleRepositoryImpl implements IAuthorizationRoleReposi return records.map((record) => this.toDomain(record)) } + async findAuthProvinceByAccountSequences( + accountSequences: bigint[], + ): Promise { + if (accountSequences.length === 0) { + return [] + } + + const records = await this.prisma.authorizationRole.findMany({ + where: { + accountSequence: { in: accountSequences }, + roleType: RoleType.AUTH_PROVINCE_COMPANY, + status: AuthorizationStatus.AUTHORIZED, + // 注意:不过滤 benefitActive,用于计算省团队权益分配 + // 注意:不过滤 regionCode,省团队收益不要求省份匹配 + }, + orderBy: { accountSequence: 'asc' }, + }) + return records.map((record) => this.toDomain(record)) + } + + async findAuthCityByAccountSequences( + accountSequences: bigint[], + ): Promise { + if (accountSequences.length === 0) { + return [] + } + + const records = await this.prisma.authorizationRole.findMany({ + where: { + accountSequence: { in: accountSequences }, + roleType: RoleType.AUTH_CITY_COMPANY, + status: AuthorizationStatus.AUTHORIZED, + // 注意:不过滤 benefitActive,用于计算市团队权益分配 + // 注意:不过滤 regionCode,市团队收益不要求城市匹配 + }, + orderBy: { accountSequence: 'asc' }, + }) + return records.map((record) => this.toDomain(record)) + } + async findProvinceCompanyByRegion(provinceCode: string): Promise { const record = await this.prisma.authorizationRole.findFirst({ where: {