|
|
@@ -62,8 +62,31 @@ export class TeamDomainController {
|
|
|
}
|
|
|
|
|
|
if (user.role === UserRole.PROMOTER) {
|
|
|
- const teamMembers = await this.teamMembersService.findByUserId(user.id)
|
|
|
- request.query.teamId = teamMembers.teamId
|
|
|
+ // 推广用户只能查看自己绑定的域名
|
|
|
+ try {
|
|
|
+ const teamMembers = await this.teamMembersService.findByUserId(user.id)
|
|
|
+ const teamDomains = await this.teamDomainService.findByTeamMemberId(teamMembers.id)
|
|
|
+
|
|
|
+ // 直接返回推广用户绑定的域名,不通过通用查询
|
|
|
+ return reply.send({
|
|
|
+ content: teamDomains,
|
|
|
+ metadata: {
|
|
|
+ total: teamDomains.length,
|
|
|
+ page: Number(request.query.page) || 0,
|
|
|
+ size: Number(request.query.size) || 20
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ // 如果推广用户没有团队成员记录,返回空列表
|
|
|
+ return reply.send({
|
|
|
+ content: [],
|
|
|
+ metadata: {
|
|
|
+ total: 0,
|
|
|
+ page: Number(request.query.page) || 0,
|
|
|
+ size: Number(request.query.size) || 20
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
} else if (user.role === UserRole.TEAM) {
|
|
|
const team = await this.teamService.findByUserId(user.id)
|
|
|
request.query.teamId = team.id
|
|
|
@@ -156,15 +179,26 @@ export class TeamDomainController {
|
|
|
const { domain } = request.query
|
|
|
let result = await this.teamDomainService.getDailyStatistics(domain)
|
|
|
|
|
|
- // 如果是团队用户,只返回该团队的域名统计
|
|
|
- if (user.role === UserRole.TEAM) {
|
|
|
+ if (user.role === UserRole.PROMOTER) {
|
|
|
+ // 推广用户只能查看自己绑定的域名统计
|
|
|
+ try {
|
|
|
+ const teamMembers = await this.teamMembersService.findByUserId(user.id)
|
|
|
+ const teamDomains = await this.teamDomainService.findByTeamMemberId(teamMembers.id)
|
|
|
+ const teamDomainIds = teamDomains.map(d => d.id)
|
|
|
+
|
|
|
+ // 过滤结果,只保留推广用户绑定的域名统计
|
|
|
+ result = result.filter(stat => teamDomainIds.includes(stat.id))
|
|
|
+ } catch (error) {
|
|
|
+ // 如果推广用户没有团队成员记录,返回空统计
|
|
|
+ result = []
|
|
|
+ }
|
|
|
+ } else if (user.role === UserRole.TEAM) {
|
|
|
+ // 团队用户只能查看该团队的域名统计
|
|
|
const team = await this.teamService.findByUserId(user.id)
|
|
|
if (team) {
|
|
|
- // 获取该团队的所有域名
|
|
|
const teamDomains = await this.teamDomainService.findByTeamId(team.id)
|
|
|
const teamDomainIds = teamDomains.map(d => d.id)
|
|
|
|
|
|
- // 过滤结果,只保留该团队的域名统计
|
|
|
result = result.filter(stat => teamDomainIds.includes(stat.id))
|
|
|
} else {
|
|
|
result = []
|
|
|
@@ -187,15 +221,26 @@ export class TeamDomainController {
|
|
|
const { domain } = request.query
|
|
|
let result = await this.teamDomainService.getAllStatistics(domain)
|
|
|
|
|
|
- // 如果是团队用户,只返回该团队的域名统计
|
|
|
- if (user.role === UserRole.TEAM) {
|
|
|
+ if (user.role === UserRole.PROMOTER) {
|
|
|
+ // 推广用户只能查看自己绑定的域名统计
|
|
|
+ try {
|
|
|
+ const teamMembers = await this.teamMembersService.findByUserId(user.id)
|
|
|
+ const teamDomains = await this.teamDomainService.findByTeamMemberId(teamMembers.id)
|
|
|
+ const teamDomainIds = teamDomains.map(d => d.id)
|
|
|
+
|
|
|
+ // 过滤结果,只保留推广用户绑定的域名统计
|
|
|
+ result = result.filter(stat => teamDomainIds.includes(stat.id))
|
|
|
+ } catch (error) {
|
|
|
+ // 如果推广用户没有团队成员记录,返回空统计
|
|
|
+ result = []
|
|
|
+ }
|
|
|
+ } else if (user.role === UserRole.TEAM) {
|
|
|
+ // 团队用户只能查看该团队的域名统计
|
|
|
const team = await this.teamService.findByUserId(user.id)
|
|
|
if (team) {
|
|
|
- // 获取该团队的所有域名
|
|
|
const teamDomains = await this.teamDomainService.findByTeamId(team.id)
|
|
|
const teamDomainIds = teamDomains.map(d => d.id)
|
|
|
|
|
|
- // 过滤结果,只保留该团队的域名统计
|
|
|
result = result.filter(stat => teamDomainIds.includes(stat.id))
|
|
|
} else {
|
|
|
result = []
|