fix(wallet-service): 修复社区权益根据 targetId 正确分配

问题:社区权益(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 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-26 07:20:22 -08:00
parent 7add51f5a3
commit 0e85c2fd23
1 changed files with 35 additions and 12 deletions

View File

@ -980,7 +980,9 @@ export class WalletApplicationService {
* *
* - SHARE_RIGHT (): pending_rewards 24 * - SHARE_RIGHT (): pending_rewards 24
* - PROVINCE_TEAM_RIGHT, PROVINCE_AREA_RIGHT, CITY_TEAM_RIGHT, CITY_AREA_RIGHT: 直接到账 * - 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( private async allocateToUserWallet(
allocation: FundAllocationItem, allocation: FundAllocationItem,
@ -989,9 +991,9 @@ export class WalletApplicationService {
const amount = Money.USDT(allocation.amount); const amount = Money.USDT(allocation.amount);
const allocationType = allocation.allocationType; const allocationType = allocation.allocationType;
// 社区权益直接进入总部社区账户 S0000000001 // 社区权益根据 targetId 分配
if (allocationType === 'COMMUNITY_RIGHT') { if (allocationType === 'COMMUNITY_RIGHT') {
await this.allocateToHeadquartersCommunity(allocation, orderId); await this.allocateCommunityRight(allocation, orderId);
return; return;
} }
@ -1082,17 +1084,36 @@ export class WalletApplicationService {
} }
/** /**
* S0000000001 *
* targetId
* - D :
* - S '1': S0000000001
*/ */
private async allocateToHeadquartersCommunity( private async allocateCommunityRight(
allocation: FundAllocationItem, allocation: FundAllocationItem,
orderId: string, orderId: string,
): Promise<void> { ): Promise<void> {
const headquartersAccountSequence = 'S0000000001'; const targetId = allocation.targetId;
const wallet = await this.walletRepo.findByAccountSequence(headquartersAccountSequence); let wallet: WalletAccount | null;
if (!wallet) { let isUserAccount = false;
this.logger.error(`Headquarters community account not found: ${headquartersAccountSequence}`);
return; // 判断 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); const amount = Money.USDT(allocation.amount);
@ -1106,7 +1127,9 @@ export class WalletApplicationService {
entryType: LedgerEntryType.SYSTEM_ALLOCATION, entryType: LedgerEntryType.SYSTEM_ALLOCATION,
amount, amount,
refOrderId: orderId, refOrderId: orderId,
memo: `${allocation.allocationType} - headquarters community allocation`, memo: isUserAccount
? `${allocation.allocationType} - community authorization allocation`
: `${allocation.allocationType} - headquarters community allocation`,
payloadJson: { payloadJson: {
allocationType: allocation.allocationType, allocationType: allocation.allocationType,
metadata: allocation.metadata, metadata: allocation.metadata,
@ -1117,7 +1140,7 @@ export class WalletApplicationService {
await this.walletCacheService.invalidateWallet(wallet.userId.value); await this.walletCacheService.invalidateWallet(wallet.userId.value);
this.logger.debug( 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}`,
); );
} }