| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2024-06-17 19:19:20 |
| 4 | * @LastEditTime: 2025-05-06 15:50:54 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: 用户推广路由 |
| 7 | */ |
| 8 | import { Controller, Get } from '@nestjs/common'; |
| 9 | import { ApiOperation, ApiTags } from '@nestjs/swagger'; |
| 10 | import { TokenInfo } from '../auth/interfaces/auth.interfaces'; |
| 11 | import { UserService } from './user.service'; |
| 12 | import { ErrHttpBack } from '../filters/http-exception.back-code'; |
| 13 | import { AppHttpException } from '../filters/http-exception.filter'; |
| 14 | import { GetToken } from '../auth/auth.guard'; |
| 15 | import { UserStatus } from 'src/db/schema/user.schema'; |
| 16 | |
| 17 | @ApiTags('用户推广') |
| 18 | @Controller('user/pop') |
| 19 | export class UserPopController { |
| 20 | constructor(private readonly userService: UserService) {} |
| 21 | |
| 22 | @ApiOperation({ |
| 23 | summary: '生成并获取自己的推广码', |
| 24 | }) |
| 25 | @Get('code') |
| 26 | async generateUsePopularizeCode(@GetToken() token: TokenInfo) { |
| 27 | const userInfo = await this.userService.getUserInfoById(token.id); |
| 28 | if (!userInfo) throw new AppHttpException(ErrHttpBack.err_user_no_had); |
| 29 | if (userInfo.status === UserStatus.STOP) |
| 30 | throw new AppHttpException(ErrHttpBack.err_no_power_login); |
| 31 | |
| 32 | if (!!userInfo.popularizeCode) return userInfo.popularizeCode; |
| 33 | |
| 34 | if (!token.phone) |
| 35 | throw new AppHttpException(ErrHttpBack.err_user_phone_null); |
| 36 | const res = await this.userService.generateUsePopularizeCode( |
| 37 | token.id, |
| 38 | token.phone, |
| 39 | ); |
| 40 | return res; |
| 41 | } |
| 42 | } |
| 43 |