feat: 添加 GENESIS 系统种子用户用于初始推荐码
- 在 identity-service 中添加 GENESIS 用户 (userId=5, code=GENESIS) - 创建 referral-service seed.ts 同步 GENESIS 推荐关系 - 新用户注册时可使用 GENESIS 推荐码进行注册 - GENESIS 用户作为根节点,便于追踪无推荐人的用户 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9102a2a6d7
commit
c58cc351d0
|
|
@ -49,6 +49,13 @@ const SYSTEM_ACCOUNTS = [
|
||||||
referralCode: 'POOL0004',
|
referralCode: 'POOL0004',
|
||||||
status: 'SYSTEM',
|
status: 'SYSTEM',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
userId: BigInt(5),
|
||||||
|
accountSequence: 'S0000000005', // GENESIS种子用户
|
||||||
|
nickname: 'GENESIS种子用户',
|
||||||
|
referralCode: 'GENESIS',
|
||||||
|
status: 'SYSTEM',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
@ -114,7 +121,7 @@ async function main() {
|
||||||
|
|
||||||
console.log('Database seeded successfully!');
|
console.log('Database seeded successfully!');
|
||||||
console.log(`- Initialized account sequence generator for date ${dateKey}`);
|
console.log(`- Initialized account sequence generator for date ${dateKey}`);
|
||||||
console.log(`- Created ${SYSTEM_ACCOUNTS.length} system accounts (S0000000001-S0000000004)`);
|
console.log(`- Created ${SYSTEM_ACCOUNTS.length} system accounts (S0000000001-S0000000005)`);
|
||||||
console.log(`- Created ${ADMIN_ACCOUNTS.length} admin accounts`);
|
console.log(`- Created ${ADMIN_ACCOUNTS.length} admin accounts`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@
|
||||||
"prisma:generate": "prisma generate",
|
"prisma:generate": "prisma generate",
|
||||||
"prisma:migrate": "prisma migrate dev",
|
"prisma:migrate": "prisma migrate dev",
|
||||||
"prisma:migrate:prod": "prisma migrate deploy",
|
"prisma:migrate:prod": "prisma migrate deploy",
|
||||||
"prisma:studio": "prisma studio"
|
"prisma:studio": "prisma studio",
|
||||||
|
"prisma:seed": "ts-node prisma/seed.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/axios": "^3.0.0",
|
"@nestjs/axios": "^3.0.0",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// GENESIS 系统种子用户
|
||||||
|
// 用于为未来的注册用户提供初始推荐码
|
||||||
|
// ============================================
|
||||||
|
const GENESIS_USER = {
|
||||||
|
userId: BigInt(5),
|
||||||
|
accountSequence: 'S0000000005',
|
||||||
|
myReferralCode: 'GENESIS',
|
||||||
|
usedReferralCode: null, // 根节点无推荐人
|
||||||
|
referrerId: null, // 根节点
|
||||||
|
rootUserId: null,
|
||||||
|
ancestorPath: [], // 空数组 = 根节点
|
||||||
|
depth: 0, // 深度 0 = 根节点
|
||||||
|
directReferralCount: 0,
|
||||||
|
activeDirectCount: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
console.log('Seeding referral-service database...');
|
||||||
|
|
||||||
|
// 创建 GENESIS 推荐关系
|
||||||
|
await prisma.referralRelationship.upsert({
|
||||||
|
where: { userId: GENESIS_USER.userId },
|
||||||
|
update: GENESIS_USER,
|
||||||
|
create: GENESIS_USER,
|
||||||
|
});
|
||||||
|
console.log(' - Created GENESIS referral relationship (userId=5, code=GENESIS)');
|
||||||
|
|
||||||
|
// 创建 GENESIS 的团队统计
|
||||||
|
await prisma.teamStatistics.upsert({
|
||||||
|
where: { userId: GENESIS_USER.userId },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
userId: GENESIS_USER.userId,
|
||||||
|
directReferralCount: 0,
|
||||||
|
totalTeamCount: 0,
|
||||||
|
selfPlantingCount: 0,
|
||||||
|
selfPlantingAmount: 0,
|
||||||
|
directPlantingCount: 0,
|
||||||
|
totalTeamPlantingCount: 0,
|
||||||
|
totalTeamPlantingAmount: 0,
|
||||||
|
maxSingleTeamPlantingCount: 0,
|
||||||
|
effectivePlantingCountForRanking: 0,
|
||||||
|
ownProvinceTeamCount: 0,
|
||||||
|
ownCityTeamCount: 0,
|
||||||
|
provinceTeamPercentage: 0,
|
||||||
|
cityTeamPercentage: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(' - Created GENESIS team statistics');
|
||||||
|
|
||||||
|
console.log('Database seeded successfully!');
|
||||||
|
console.log('- Created 1 GENESIS seed user for initial referrals');
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
})
|
||||||
|
.finally(async () => {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue