Browse Source

修改游客注册代码,添加配置

wilhelm wong 1 tháng trước cách đây
mục cha
commit
b346b3eda3
2 tập tin đã thay đổi với 65 bổ sung70 xóa
  1. 5 0
      .env
  2. 60 70
      src/services/member.service.ts

+ 5 - 0
.env

@@ -8,6 +8,11 @@ DB_PORT=3306
 DB_USERNAME=zouma
 DB_PASSWORD='2wsx@WSX#EDC'
 DB_DATABASE=junma_test
+# DB_HOST=8.210.167.152
+# DB_PORT=3306
+# DB_USERNAME=root
+# DB_PASSWORD='tYYf%BC7pqQJ8$v!'
+# DB_DATABASE=junma
 REDIS_HOST=localhost
 REDIS_PORT=6379
 

+ 60 - 70
src/services/member.service.ts

@@ -114,59 +114,54 @@ export class MemberService {
         })
         
         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) {
-        // 查询当天注册最多的域名
+        // 查询当天注册最多的渠道(teamId)
         const today = new Date()
         today.setHours(0, 0, 0, 0)
         const tomorrow = new Date(today)
         tomorrow.setDate(tomorrow.getDate() + 1)
         
-        // 统计当天每个域名的注册数量
-        const domainCounts = await manager
+        // 统计当天每个渠道(teamId)的注册数量,排除teamId为0或1的渠道
+        const teamCounts = await manager
           .createQueryBuilder(Member, 'member')
-          .select('member.domainId', 'domainId')
+          .select('member.teamId', 'teamId')
           .addSelect('COUNT(member.id)', 'count')
           .where('member.createdAt >= :today', { today })
           .andWhere('member.createdAt < :tomorrow', { tomorrow })
-          .andWhere('member.domainId > 0')
-          .groupBy('member.domainId')
+          .andWhere('member.teamId > 1') // 排除team0和team1
+          .groupBy('member.teamId')
           .orderBy('count', 'DESC')
           .limit(1)
           .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) {
-          // 如果找到落地域名记录,使用对应的团队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) {
-        // 查询当天注册最多的域名
+        // 查询当天注册最多的渠道(teamId)
         const today = new Date()
         today.setHours(0, 0, 0, 0)
         const tomorrow = new Date(today)
         tomorrow.setDate(tomorrow.getDate() + 1)
         
-        // 统计当天每个域名的注册数量
-        const domainCounts = await manager
+        // 统计当天每个渠道(teamId)的注册数量,排除teamId为0或1的渠道
+        const teamCounts = await manager
           .createQueryBuilder(Member, 'member')
-          .select('member.domainId', 'domainId')
+          .select('member.teamId', 'teamId')
           .addSelect('COUNT(member.id)', 'count')
           .where('member.createdAt >= :today', { today })
           .andWhere('member.createdAt < :tomorrow', { tomorrow })
-          .andWhere('member.domainId > 0')
-          .groupBy('member.domainId')
+          .andWhere('member.teamId > 1') // 排除team0和team1
+          .groupBy('member.teamId')
           .orderBy('count', 'DESC')
           .limit(1)
           .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
           }
         }
       }