diff --git a/backend/services/wallet-service/src/application/services/wallet-application.service.ts b/backend/services/wallet-service/src/application/services/wallet-application.service.ts index d94adf60..71d450fd 100644 --- a/backend/services/wallet-service/src/application/services/wallet-application.service.ts +++ b/backend/services/wallet-service/src/application/services/wallet-application.service.ts @@ -980,7 +980,9 @@ export class WalletApplicationService { * 分配规则: * - SHARE_RIGHT (分享权益): 写入 pending_rewards 表,24小时待领取 * - PROVINCE_TEAM_RIGHT, PROVINCE_AREA_RIGHT, CITY_TEAM_RIGHT, CITY_AREA_RIGHT: 直接到账 - * - COMMUNITY_RIGHT (社区权益): 进入总部社区账户 S0000000001,直接到账 + * - COMMUNITY_RIGHT (社区权益): 根据 targetId 分配 + * - D 开头(用户账户): 分配到社区授权人账户,直接到账 + * - S 开头或 '1'(系统账户): 分配到总部社区账户 S0000000001 */ private async allocateToUserWallet( allocation: FundAllocationItem, @@ -989,9 +991,9 @@ export class WalletApplicationService { const amount = Money.USDT(allocation.amount); const allocationType = allocation.allocationType; - // 社区权益直接进入总部社区账户 S0000000001 + // 社区权益根据 targetId 分配 if (allocationType === 'COMMUNITY_RIGHT') { - await this.allocateToHeadquartersCommunity(allocation, orderId); + await this.allocateCommunityRight(allocation, orderId); return; } @@ -1082,17 +1084,36 @@ export class WalletApplicationService { } /** - * 社区权益直接进入总部社区账户 S0000000001 + * 社区权益分配 + * 根据 targetId 决定分配目标: + * - D 开头(用户账户): 分配到社区授权人账户 + * - S 开头或 '1'(系统账户): 分配到总部社区账户 S0000000001 */ - private async allocateToHeadquartersCommunity( + private async allocateCommunityRight( allocation: FundAllocationItem, orderId: string, ): Promise { - const headquartersAccountSequence = 'S0000000001'; - const wallet = await this.walletRepo.findByAccountSequence(headquartersAccountSequence); - if (!wallet) { - this.logger.error(`Headquarters community account not found: ${headquartersAccountSequence}`); - return; + const targetId = allocation.targetId; + let wallet: WalletAccount | null; + let isUserAccount = false; + + // 判断 targetId 类型 + if (targetId.startsWith('D')) { + // 用户账户(D+日期+序号): 社区授权人 + wallet = await this.walletRepo.findByAccountSequence(targetId); + if (!wallet) { + this.logger.error(`User wallet not found for community right allocation: ${targetId}`); + return; + } + isUserAccount = true; + } else { + // 系统账户(S 开头或 '1'): 总部社区 + const headquartersAccountSequence = 'S0000000001'; + wallet = await this.walletRepo.findByAccountSequence(headquartersAccountSequence); + if (!wallet) { + this.logger.error(`Headquarters community account not found: ${headquartersAccountSequence}`); + return; + } } const amount = Money.USDT(allocation.amount); @@ -1106,7 +1127,9 @@ export class WalletApplicationService { entryType: LedgerEntryType.SYSTEM_ALLOCATION, amount, refOrderId: orderId, - memo: `${allocation.allocationType} - headquarters community allocation`, + memo: isUserAccount + ? `${allocation.allocationType} - community authorization allocation` + : `${allocation.allocationType} - headquarters community allocation`, payloadJson: { allocationType: allocation.allocationType, metadata: allocation.metadata, @@ -1117,7 +1140,7 @@ export class WalletApplicationService { await this.walletCacheService.invalidateWallet(wallet.userId.value); this.logger.debug( - `Allocated ${allocation.amount} USDT to headquarters community ${headquartersAccountSequence} for ${allocation.allocationType}`, + `Allocated ${allocation.amount} USDT to ${isUserAccount ? 'community user' : 'headquarters'} ${wallet.accountSequence} for ${allocation.allocationType}`, ); }