|
@@ -114,59 +114,54 @@ export class MemberService {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
if (landingDomainRecord) {
|
|
if (landingDomainRecord) {
|
|
|
- // 如果找到落地域名记录,使用对应的团队ID
|
|
|
|
|
- teamId = landingDomainRecord.teamId
|
|
|
|
|
- // 根据 teamId 查找团队,获取 userId 作为 parentId
|
|
|
|
|
- const foundTeam = await manager.findOne(Team, { where: { id: teamId } })
|
|
|
|
|
- if (foundTeam) {
|
|
|
|
|
- parentId = foundTeam.userId
|
|
|
|
|
|
|
+ // 如果落地域名绑定到团队成员(userId不为空),使用teamMember的userId作为parentId
|
|
|
|
|
+ // 这样在分润时可以从teamMember向上查找到team
|
|
|
|
|
+ if (landingDomainRecord.userId) {
|
|
|
|
|
+ const teamMember = await manager.findOne(TeamMembers, { where: { userId: landingDomainRecord.userId } })
|
|
|
|
|
+ if (teamMember) {
|
|
|
|
|
+ parentId = teamMember.userId
|
|
|
|
|
+ teamId = teamMember.teamId
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果落地域名只绑定到团队,使用team的userId作为parentId
|
|
|
|
|
+ teamId = landingDomainRecord.teamId
|
|
|
|
|
+ const foundTeam = await manager.findOne(Team, { where: { id: teamId } })
|
|
|
|
|
+ if (foundTeam) {
|
|
|
|
|
+ parentId = foundTeam.userId
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 4. 如果以上都没有找到有效注册信息,统一分给当天注册最多的域名
|
|
|
|
|
|
|
+ // 4. 如果以上都没有找到有效注册信息,统一分给当天注册最多的渠道(排除team0和team1)
|
|
|
if (parentId === 1 && teamId === 0) {
|
|
if (parentId === 1 && teamId === 0) {
|
|
|
- // 查询当天注册最多的域名
|
|
|
|
|
|
|
+ // 查询当天注册最多的渠道(teamId)
|
|
|
const today = new Date()
|
|
const today = new Date()
|
|
|
today.setHours(0, 0, 0, 0)
|
|
today.setHours(0, 0, 0, 0)
|
|
|
const tomorrow = new Date(today)
|
|
const tomorrow = new Date(today)
|
|
|
tomorrow.setDate(tomorrow.getDate() + 1)
|
|
tomorrow.setDate(tomorrow.getDate() + 1)
|
|
|
|
|
|
|
|
- // 统计当天每个域名的注册数量
|
|
|
|
|
- const domainCounts = await manager
|
|
|
|
|
|
|
+ // 统计当天每个渠道(teamId)的注册数量,排除teamId为0或1的渠道
|
|
|
|
|
+ const teamCounts = await manager
|
|
|
.createQueryBuilder(Member, 'member')
|
|
.createQueryBuilder(Member, 'member')
|
|
|
- .select('member.domainId', 'domainId')
|
|
|
|
|
|
|
+ .select('member.teamId', 'teamId')
|
|
|
.addSelect('COUNT(member.id)', 'count')
|
|
.addSelect('COUNT(member.id)', 'count')
|
|
|
.where('member.createdAt >= :today', { today })
|
|
.where('member.createdAt >= :today', { today })
|
|
|
.andWhere('member.createdAt < :tomorrow', { tomorrow })
|
|
.andWhere('member.createdAt < :tomorrow', { tomorrow })
|
|
|
- .andWhere('member.domainId > 0')
|
|
|
|
|
- .groupBy('member.domainId')
|
|
|
|
|
|
|
+ .andWhere('member.teamId > 1') // 排除team0和team1
|
|
|
|
|
+ .groupBy('member.teamId')
|
|
|
.orderBy('count', 'DESC')
|
|
.orderBy('count', 'DESC')
|
|
|
.limit(1)
|
|
.limit(1)
|
|
|
.getRawMany()
|
|
.getRawMany()
|
|
|
|
|
|
|
|
- if (domainCounts.length > 0 && domainCounts[0].domainId) {
|
|
|
|
|
- const mostRegisteredDomainId = domainCounts[0].domainId
|
|
|
|
|
- const teamDomain = await manager.findOne(TeamDomain, { where: { id: mostRegisteredDomainId } })
|
|
|
|
|
-
|
|
|
|
|
- if (teamDomain) {
|
|
|
|
|
- domainId = mostRegisteredDomainId
|
|
|
|
|
-
|
|
|
|
|
- // 如果域名绑定到团队成员
|
|
|
|
|
- if (teamDomain.teamMemberId) {
|
|
|
|
|
- const teamMember = await manager.findOne(TeamMembers, { where: { id: teamDomain.teamMemberId } })
|
|
|
|
|
- if (teamMember) {
|
|
|
|
|
- parentId = teamMember.userId
|
|
|
|
|
- teamId = teamMember.teamId
|
|
|
|
|
- }
|
|
|
|
|
- } else if (teamDomain.teamId) {
|
|
|
|
|
- // 如果域名只绑定到团队
|
|
|
|
|
- const foundTeam = await manager.findOne(Team, { where: { id: teamDomain.teamId } })
|
|
|
|
|
- if (foundTeam) {
|
|
|
|
|
- parentId = foundTeam.userId
|
|
|
|
|
- teamId = foundTeam.id
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (teamCounts.length > 0 && teamCounts[0].teamId) {
|
|
|
|
|
+ const mostRegisteredTeamId = teamCounts[0].teamId
|
|
|
|
|
+ // 根据teamId查找团队,获取userId作为parentId
|
|
|
|
|
+ const foundTeam = await manager.findOne(Team, { where: { id: mostRegisteredTeamId } })
|
|
|
|
|
+ if (foundTeam) {
|
|
|
|
|
+ parentId = foundTeam.userId
|
|
|
|
|
+ teamId = foundTeam.id
|
|
|
|
|
+ domainId = 0
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -495,12 +490,21 @@ export class MemberService {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
if (landingDomainRecord) {
|
|
if (landingDomainRecord) {
|
|
|
- // 如果找到落地域名记录,使用对应的团队ID
|
|
|
|
|
- teamId = landingDomainRecord.teamId
|
|
|
|
|
- // 根据 teamId 查找团队,获取 userId 作为 parentId
|
|
|
|
|
- const foundTeam = await manager.findOne(Team, { where: { id: teamId } })
|
|
|
|
|
- if (foundTeam) {
|
|
|
|
|
- parentId = foundTeam.userId
|
|
|
|
|
|
|
+ // 如果落地域名绑定到团队成员(userId不为空),使用teamMember的userId作为parentId
|
|
|
|
|
+ // 这样在分润时可以从teamMember向上查找到team
|
|
|
|
|
+ if (landingDomainRecord.userId) {
|
|
|
|
|
+ const teamMember = await manager.findOne(TeamMembers, { where: { userId: landingDomainRecord.userId } })
|
|
|
|
|
+ if (teamMember) {
|
|
|
|
|
+ parentId = teamMember.userId
|
|
|
|
|
+ teamId = teamMember.teamId
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果落地域名只绑定到团队,使用team的userId作为parentId
|
|
|
|
|
+ teamId = landingDomainRecord.teamId
|
|
|
|
|
+ const foundTeam = await manager.findOne(Team, { where: { id: teamId } })
|
|
|
|
|
+ if (foundTeam) {
|
|
|
|
|
+ parentId = foundTeam.userId
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -546,49 +550,35 @@ export class MemberService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 4. 如果以上都没有找到有效注册信息,统一分给当天注册最多的域名
|
|
|
|
|
|
|
+ // 4. 如果以上都没有找到有效注册信息,统一分给当天注册最多的渠道(排除team0和team1)
|
|
|
if (parentId === 1 && teamId === 0) {
|
|
if (parentId === 1 && teamId === 0) {
|
|
|
- // 查询当天注册最多的域名
|
|
|
|
|
|
|
+ // 查询当天注册最多的渠道(teamId)
|
|
|
const today = new Date()
|
|
const today = new Date()
|
|
|
today.setHours(0, 0, 0, 0)
|
|
today.setHours(0, 0, 0, 0)
|
|
|
const tomorrow = new Date(today)
|
|
const tomorrow = new Date(today)
|
|
|
tomorrow.setDate(tomorrow.getDate() + 1)
|
|
tomorrow.setDate(tomorrow.getDate() + 1)
|
|
|
|
|
|
|
|
- // 统计当天每个域名的注册数量
|
|
|
|
|
- const domainCounts = await manager
|
|
|
|
|
|
|
+ // 统计当天每个渠道(teamId)的注册数量,排除teamId为0或1的渠道
|
|
|
|
|
+ const teamCounts = await manager
|
|
|
.createQueryBuilder(Member, 'member')
|
|
.createQueryBuilder(Member, 'member')
|
|
|
- .select('member.domainId', 'domainId')
|
|
|
|
|
|
|
+ .select('member.teamId', 'teamId')
|
|
|
.addSelect('COUNT(member.id)', 'count')
|
|
.addSelect('COUNT(member.id)', 'count')
|
|
|
.where('member.createdAt >= :today', { today })
|
|
.where('member.createdAt >= :today', { today })
|
|
|
.andWhere('member.createdAt < :tomorrow', { tomorrow })
|
|
.andWhere('member.createdAt < :tomorrow', { tomorrow })
|
|
|
- .andWhere('member.domainId > 0')
|
|
|
|
|
- .groupBy('member.domainId')
|
|
|
|
|
|
|
+ .andWhere('member.teamId > 1') // 排除team0和team1
|
|
|
|
|
+ .groupBy('member.teamId')
|
|
|
.orderBy('count', 'DESC')
|
|
.orderBy('count', 'DESC')
|
|
|
.limit(1)
|
|
.limit(1)
|
|
|
.getRawMany()
|
|
.getRawMany()
|
|
|
|
|
|
|
|
- if (domainCounts.length > 0 && domainCounts[0].domainId) {
|
|
|
|
|
- const mostRegisteredDomainId = domainCounts[0].domainId
|
|
|
|
|
- const teamDomain = await manager.findOne(TeamDomain, { where: { id: mostRegisteredDomainId } })
|
|
|
|
|
-
|
|
|
|
|
- if (teamDomain) {
|
|
|
|
|
- domainId = mostRegisteredDomainId
|
|
|
|
|
-
|
|
|
|
|
- // 如果域名绑定到团队成员
|
|
|
|
|
- if (teamDomain.teamMemberId) {
|
|
|
|
|
- const teamMember = await manager.findOne(TeamMembers, { where: { id: teamDomain.teamMemberId } })
|
|
|
|
|
- if (teamMember) {
|
|
|
|
|
- parentId = teamMember.userId
|
|
|
|
|
- teamId = teamMember.teamId
|
|
|
|
|
- }
|
|
|
|
|
- } else if (teamDomain.teamId) {
|
|
|
|
|
- // 如果域名只绑定到团队
|
|
|
|
|
- const foundTeam = await manager.findOne(Team, { where: { id: teamDomain.teamId } })
|
|
|
|
|
- if (foundTeam) {
|
|
|
|
|
- parentId = foundTeam.userId
|
|
|
|
|
- teamId = foundTeam.id
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (teamCounts.length > 0 && teamCounts[0].teamId) {
|
|
|
|
|
+ const mostRegisteredTeamId = teamCounts[0].teamId
|
|
|
|
|
+ // 根据teamId查找团队,获取userId作为parentId
|
|
|
|
|
+ const foundTeam = await manager.findOne(Team, { where: { id: mostRegisteredTeamId } })
|
|
|
|
|
+ if (foundTeam) {
|
|
|
|
|
+ parentId = foundTeam.userId
|
|
|
|
|
+ teamId = foundTeam.id
|
|
|
|
|
+ domainId = 0
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|