From 0e85c2fd23af7e385e17d00f686882785f226ec8 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 26 Dec 2025 07:20:22 -0800 Subject: [PATCH] =?UTF-8?q?fix(wallet-service):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E6=9D=83=E7=9B=8A=E6=A0=B9=E6=8D=AE=20target?= =?UTF-8?q?Id=20=E6=AD=A3=E7=A1=AE=E5=88=86=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:社区权益(COMMUNITY_RIGHT)无论 targetId 是什么,都强制分配到 总部账户 S0000000001,导致社区授权人无法在流水明细中看到社区权益。 修复: - 将 allocateToHeadquartersCommunity 方法重命名为 allocateCommunityRight - 根据 targetId 判断分配目标: - D 开头(用户账户): 分配到社区授权人账户 - S 开头或 '1'(系统账户): 分配到总部社区账户 - 更新流水备注以区分用户分配和总部分配 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../services/wallet-application.service.ts | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) 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}`, ); }