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:
parent
7add51f5a3
commit
0e85c2fd23
|
|
@ -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<void> {
|
||||
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}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue