fix(reward): 修复 accountSequence 转 userId 时字母前缀导致的 BigInt 转换失败
问题描述: - 社区权益激活后,用户收不到奖励 - 错误: SyntaxError: Cannot convert D25121400002 to a BigInt - 原因: accountSequence 格式为 D25121400002 (D+日期+序号),直接 BigInt() 转换失败 修改方案: - 新增 parseAccountSequenceToUserId() 辅助方法 - 如果 accountSequence 以字母开头,去掉第一个字符后再转 BigInt - 影响 5 个方法: calculateProvinceTeamRight, calculateProvinceAreaRight, calculateCityTeamRight, calculateCityAreaRight, calculateCommunityRight 技术背景: - accountSequence 格式: D25121400002 (用户) / S0000000001 (固定系统账户) / 9440000 (省系统) - 省市系统账户在 authorization-service 动态创建,identity-service 中不存在 - reward-service 的 userId 字段实际业务中不被使用 (查询用 accountSequence) 潜在隐患: 1. userId 字段存储的不是 identity-service 中的真实 userId - D25121400002 -> 25121400002 (不是真实的自增 userId) - S0000000001 -> 1 (恰好匹配固定系统账户) - 9440000 -> 9440000 (省系统账户,本无字母前缀) 2. 如果未来 reward-service 需要与 identity-service 关联查询,可能出现问题 3. 建议后续考虑: 将 userId 改为可选字段,或完全移除该字段依赖 🤖 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
c7d54da49f
commit
090c8b747e
|
|
@ -66,6 +66,16 @@ const SHARE_RIGHT_POOL_USER_ID = BigInt(-5);
|
||||||
export class RewardCalculationService {
|
export class RewardCalculationService {
|
||||||
private readonly logger = new Logger(RewardCalculationService.name);
|
private readonly logger = new Logger(RewardCalculationService.name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 accountSequence 转换为 userId
|
||||||
|
* accountSequence 格式: D25121400002 (用户) / S0000000001 (系统) / 9440000 (省系统)
|
||||||
|
* 如果以字母开头,去掉第一个字符后转为 BigInt
|
||||||
|
*/
|
||||||
|
private parseAccountSequenceToUserId(accountSequence: string): bigint {
|
||||||
|
const numericPart = /^[a-zA-Z]/i.test(accountSequence) ? accountSequence.slice(1) : accountSequence;
|
||||||
|
return BigInt(numericPart);
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(REFERRAL_SERVICE_CLIENT)
|
@Inject(REFERRAL_SERVICE_CLIENT)
|
||||||
private readonly referralService: IReferralServiceClient,
|
private readonly referralService: IReferralServiceClient,
|
||||||
|
|
@ -432,7 +442,7 @@ export class RewardCalculationService {
|
||||||
|
|
||||||
rewards.push(
|
rewards.push(
|
||||||
RewardLedgerEntry.createSettleable({
|
RewardLedgerEntry.createSettleable({
|
||||||
userId: BigInt(item.accountSequence),
|
userId: this.parseAccountSequenceToUserId(item.accountSequence),
|
||||||
accountSequence: item.accountSequence,
|
accountSequence: item.accountSequence,
|
||||||
rewardSource,
|
rewardSource,
|
||||||
usdtAmount: itemUsdtAmount,
|
usdtAmount: itemUsdtAmount,
|
||||||
|
|
@ -488,7 +498,7 @@ export class RewardCalculationService {
|
||||||
|
|
||||||
rewards.push(
|
rewards.push(
|
||||||
RewardLedgerEntry.createSettleable({
|
RewardLedgerEntry.createSettleable({
|
||||||
userId: BigInt(item.accountSequence),
|
userId: this.parseAccountSequenceToUserId(item.accountSequence),
|
||||||
accountSequence: item.accountSequence,
|
accountSequence: item.accountSequence,
|
||||||
rewardSource,
|
rewardSource,
|
||||||
usdtAmount: itemUsdtAmount,
|
usdtAmount: itemUsdtAmount,
|
||||||
|
|
@ -544,7 +554,7 @@ export class RewardCalculationService {
|
||||||
|
|
||||||
rewards.push(
|
rewards.push(
|
||||||
RewardLedgerEntry.createSettleable({
|
RewardLedgerEntry.createSettleable({
|
||||||
userId: BigInt(item.accountSequence),
|
userId: this.parseAccountSequenceToUserId(item.accountSequence),
|
||||||
accountSequence: item.accountSequence,
|
accountSequence: item.accountSequence,
|
||||||
rewardSource,
|
rewardSource,
|
||||||
usdtAmount: itemUsdtAmount,
|
usdtAmount: itemUsdtAmount,
|
||||||
|
|
@ -600,7 +610,7 @@ export class RewardCalculationService {
|
||||||
|
|
||||||
rewards.push(
|
rewards.push(
|
||||||
RewardLedgerEntry.createSettleable({
|
RewardLedgerEntry.createSettleable({
|
||||||
userId: BigInt(item.accountSequence),
|
userId: this.parseAccountSequenceToUserId(item.accountSequence),
|
||||||
accountSequence: item.accountSequence,
|
accountSequence: item.accountSequence,
|
||||||
rewardSource,
|
rewardSource,
|
||||||
usdtAmount: itemUsdtAmount,
|
usdtAmount: itemUsdtAmount,
|
||||||
|
|
@ -656,7 +666,7 @@ export class RewardCalculationService {
|
||||||
|
|
||||||
rewards.push(
|
rewards.push(
|
||||||
RewardLedgerEntry.createSettleable({
|
RewardLedgerEntry.createSettleable({
|
||||||
userId: BigInt(item.accountSequence),
|
userId: this.parseAccountSequenceToUserId(item.accountSequence),
|
||||||
accountSequence: item.accountSequence,
|
accountSequence: item.accountSequence,
|
||||||
rewardSource,
|
rewardSource,
|
||||||
usdtAmount: itemUsdtAmount,
|
usdtAmount: itemUsdtAmount,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue