fix(wallet-service): 社区权益按 targetId 分配到正确账户
修复社区权益分配逻辑: - 之前所有 COMMUNITY_RIGHT 都直接进入总部账户 S0000000001 - 现在根据 targetId 判断: - targetId 为 '1' 或 'S0000000001' → 进入总部社区账户 - targetId 为用户账户(D开头)→ 进入该用户可结算余额 这样当用户获取社区授权且伞下认种达到10棵后, 社区权益会正确分配到该用户账户,而不是总部。 🤖 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
3f3309e62f
commit
43a0e5f5e1
|
|
@ -980,7 +980,7 @@ 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 分配(用户账户或总部)
|
||||
*/
|
||||
private async allocateToUserWallet(
|
||||
allocation: FundAllocationItem,
|
||||
|
|
@ -989,9 +989,17 @@ export class WalletApplicationService {
|
|||
const amount = Money.USDT(allocation.amount);
|
||||
const allocationType = allocation.allocationType;
|
||||
|
||||
// 社区权益直接进入总部社区账户 S0000000001
|
||||
// 社区权益:根据 targetId 判断分配目标
|
||||
// - targetId 为 '1' 或 'S0000000001' 时进入总部社区账户
|
||||
// - targetId 为用户账户(D开头)时进入该用户账户
|
||||
if (allocationType === 'COMMUNITY_RIGHT') {
|
||||
await this.allocateToHeadquartersCommunity(allocation, orderId);
|
||||
const targetId = allocation.targetId;
|
||||
if (targetId === '1' || targetId === 'S0000000001') {
|
||||
await this.allocateToHeadquartersCommunity(allocation, orderId);
|
||||
} else {
|
||||
// 分配到具体用户的社区权益
|
||||
await this.allocateCommunityRightToUser(allocation, orderId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1081,6 +1089,49 @@ export class WalletApplicationService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 社区权益分配给具体用户(社区授权达标后)
|
||||
* 直接进入用户的可结算余额
|
||||
*/
|
||||
private async allocateCommunityRightToUser(
|
||||
allocation: FundAllocationItem,
|
||||
orderId: string,
|
||||
): Promise<void> {
|
||||
const targetId = allocation.targetId;
|
||||
const wallet = await this.walletRepo.findByAccountSequence(targetId);
|
||||
if (!wallet) {
|
||||
this.logger.warn(`Failed to find wallet for community right allocation: ${targetId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const amount = Money.USDT(allocation.amount);
|
||||
|
||||
// 社区权益直接进入可结算余额(与分享权益的处理类似但不进 pending)
|
||||
wallet.addSettleableReward(amount, Hashpower.create(0));
|
||||
await this.walletRepo.save(wallet);
|
||||
|
||||
// 记录流水
|
||||
const ledgerEntry = LedgerEntry.create({
|
||||
accountSequence: wallet.accountSequence,
|
||||
userId: wallet.userId,
|
||||
entryType: LedgerEntryType.REWARD_TO_SETTLEABLE,
|
||||
amount,
|
||||
refOrderId: orderId,
|
||||
memo: `${allocation.allocationType} allocation (direct settleable)`,
|
||||
payloadJson: {
|
||||
allocationType: allocation.allocationType,
|
||||
metadata: allocation.metadata,
|
||||
},
|
||||
});
|
||||
await this.ledgerRepo.save(ledgerEntry);
|
||||
|
||||
await this.walletCacheService.invalidateWallet(wallet.userId.value);
|
||||
|
||||
this.logger.debug(
|
||||
`Allocated ${allocation.amount} USDT to user ${targetId} for ${allocation.allocationType} (community right)`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 社区权益直接进入总部社区账户 S0000000001
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue