mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-13 12:13:43 +08:00
v-4.0.0 开源可二开源码
This commit is contained in:
39
dist/modules/user/user.controller.js
vendored
39
dist/modules/user/user.controller.js
vendored
@@ -19,7 +19,6 @@ const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const queryAllUser_dto_1 = require("./dto/queryAllUser.dto");
|
||||
const queryInviteRecord_dto_1 = require("./dto/queryInviteRecord.dto");
|
||||
const queryOne_dto_1 = require("./dto/queryOne.dto");
|
||||
const resetUserPass_dto_1 = require("./dto/resetUserPass.dto");
|
||||
const updateUser_dto_1 = require("./dto/updateUser.dto");
|
||||
@@ -33,15 +32,6 @@ let UserController = class UserController {
|
||||
async update(body, req) {
|
||||
return await this.userService.updateInfo(body, req);
|
||||
}
|
||||
async genInviteCode(req) {
|
||||
return await this.userService.genInviteCode(req);
|
||||
}
|
||||
async getInviteRecord(req, query) {
|
||||
return await this.userService.getInviteRecord(req, query);
|
||||
}
|
||||
async inviteLink(code) {
|
||||
return await this.userService.inviteLink(code);
|
||||
}
|
||||
async userRecharge(body) {
|
||||
return await this.userService.userRecharge(body);
|
||||
}
|
||||
@@ -69,35 +59,6 @@ __decorate([
|
||||
__metadata("design:paramtypes", [updateUser_dto_1.UpdateUserDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "update", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('genInviteCode'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '生成邀请码' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "genInviteCode", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('inviteRecord'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '获取我的邀请记录' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, queryInviteRecord_dto_1.queryInviteRecordDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "getInviteRecord", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('inviteLink'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '邀请链接被点击' }),
|
||||
__param(0, (0, common_1.Query)('code')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], UserController.prototype, "inviteLink", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('recharge'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户充值' }),
|
||||
|
||||
8
dist/modules/user/user.entity.js
vendored
8
dist/modules/user/user.entity.js
vendored
@@ -101,6 +101,14 @@ __decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户违规记录次数', default: 0 }),
|
||||
__metadata("design:type", Number)
|
||||
], UserEntity.prototype, "violationCount", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '真实姓名', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "realName", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '身份证号', nullable: true }),
|
||||
__metadata("design:type", String)
|
||||
], UserEntity.prototype, "idCard", void 0);
|
||||
UserEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'users' })
|
||||
], UserEntity);
|
||||
|
||||
4
dist/modules/user/user.module.js
vendored
4
dist/modules/user/user.module.js
vendored
@@ -14,9 +14,7 @@ const chatLog_entity_1 = require("../chatLog/chatLog.entity");
|
||||
const cramiPackage_entity_1 = require("../crami/cramiPackage.entity");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const mailer_service_1 = require("../mailer/mailer.service");
|
||||
const midjourney_entity_1 = require("../midjourney/midjourney.entity");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
const salesUsers_entity_1 = require("../sales/salesUsers.entity");
|
||||
const accountLog_entity_1 = require("../userBalance/accountLog.entity");
|
||||
const balance_entity_1 = require("../userBalance/balance.entity");
|
||||
const fingerprint_entity_1 = require("../userBalance/fingerprint.entity");
|
||||
@@ -41,11 +39,9 @@ UserModule = __decorate([
|
||||
config_entity_1.ConfigEntity,
|
||||
cramiPackage_entity_1.CramiPackageEntity,
|
||||
userBalance_entity_1.UserBalanceEntity,
|
||||
salesUsers_entity_1.SalesUsersEntity,
|
||||
fingerprint_entity_1.FingerprintLogEntity,
|
||||
chatLog_entity_1.ChatLogEntity,
|
||||
chatGroup_entity_1.ChatGroupEntity,
|
||||
midjourney_entity_1.MidjourneyEntity,
|
||||
]),
|
||||
],
|
||||
controllers: [user_controller_1.UserController],
|
||||
|
||||
125
dist/modules/user/user.service.js
vendored
125
dist/modules/user/user.service.js
vendored
@@ -39,15 +39,7 @@ let UserService = class UserService {
|
||||
this.configEntity = configEntity;
|
||||
}
|
||||
async createUserAndVerifycation(user, req) {
|
||||
const { username, email, password, invitedBy, client = 0 } = user;
|
||||
if (invitedBy) {
|
||||
const b = await this.userEntity.findOne({
|
||||
where: { inviteCode: invitedBy },
|
||||
});
|
||||
if (!b) {
|
||||
throw new common_1.HttpException('无效的邀请码!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
const { username, email, password, client = 0 } = user;
|
||||
const where = [{ username }, { email }];
|
||||
const u = await this.userEntity.findOne({ where: where });
|
||||
if (u && u.status !== user_constant_1.UserStatusEnum.PENDING) {
|
||||
@@ -101,13 +93,9 @@ let UserService = class UserService {
|
||||
console.log(`尝试发送邮件到: ${email}`);
|
||||
}
|
||||
else {
|
||||
const { username, email, id, invitedBy } = n;
|
||||
const { id } = n;
|
||||
await this.updateUserStatus(id, user_constant_1.UserStatusEnum.ACTIVE);
|
||||
let inviteUser;
|
||||
if (invitedBy) {
|
||||
inviteUser = await this.qureyUserInfoByInviteCode(invitedBy);
|
||||
}
|
||||
await this.userBalanceService.addBalanceToNewUser(id, inviteUser === null || inviteUser === void 0 ? void 0 : inviteUser.id);
|
||||
await this.userBalanceService.addBalanceToNewUser(id);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
@@ -196,7 +184,6 @@ let UserService = class UserService {
|
||||
'role',
|
||||
'email',
|
||||
'sign',
|
||||
'inviteCode',
|
||||
'openId',
|
||||
'consecutiveDays',
|
||||
],
|
||||
@@ -256,73 +243,6 @@ let UserService = class UserService {
|
||||
throw new common_1.HttpException('修改密码失败、请重新试试吧。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async genInviteCode(req) {
|
||||
const { id } = req.user;
|
||||
const u = await this.userEntity.findOne({ where: { id } });
|
||||
if (!u || u.inviteCode) {
|
||||
throw new common_1.HttpException('已生成过邀请码、请勿重复生成', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const inviteCode = (0, utils_1.generateRandomString)();
|
||||
const user = await this.userEntity.findOne({ where: { inviteCode } });
|
||||
if (user) {
|
||||
throw new common_1.HttpException('生成邀请码失败,请重新试一次吧!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const r = await this.userEntity.update({ id }, { inviteCode });
|
||||
if (r.affected <= 0) {
|
||||
throw new common_1.HttpException('生成邀请码失败,请重新试一次吧!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return inviteCode;
|
||||
}
|
||||
async getInviteRecord(req, query) {
|
||||
try {
|
||||
const { id } = req.user;
|
||||
const { page = 1, size = 10 } = query;
|
||||
const u = await this.userEntity.findOne({ where: { id } });
|
||||
const { inviteCode } = u;
|
||||
if (!inviteCode)
|
||||
return [];
|
||||
const invitedBy = inviteCode;
|
||||
const [rows, count] = await this.userEntity.findAndCount({
|
||||
where: { invitedBy },
|
||||
order: { id: 'DESC' },
|
||||
select: [
|
||||
'username',
|
||||
'email',
|
||||
'createdAt',
|
||||
'status',
|
||||
'avatar',
|
||||
'updatedAt',
|
||||
],
|
||||
take: size,
|
||||
skip: (page - 1) * size,
|
||||
});
|
||||
(0, utils_1.formatCreateOrUpdateDate)(rows).map((t) => {
|
||||
t.email = (0, utils_1.maskEmail)(t.email);
|
||||
return t;
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
throw new common_1.HttpException('获取邀请记录失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async inviteLink(code) {
|
||||
const u = await this.userEntity.findOne({ where: { inviteCode: code } });
|
||||
if (!u)
|
||||
return 1;
|
||||
const { inviteLinkCount = 0 } = u;
|
||||
const res = await this.userEntity.update({ inviteCode: code }, { inviteLinkCount: inviteLinkCount + 1 });
|
||||
if (res.affected) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
async qureyUserInfoByInviteCode(inviteCode) {
|
||||
return await this.userEntity.findOne({ where: { inviteCode } });
|
||||
}
|
||||
async userRecharge(body) {
|
||||
const { userId, model3Count = 0, model4Count = 0, drawMjCount = 0 } = body;
|
||||
await this.userBalanceService.addBalanceToUser(userId, {
|
||||
@@ -363,7 +283,6 @@ let UserService = class UserService {
|
||||
select: [
|
||||
'username',
|
||||
'avatar',
|
||||
'inviteCode',
|
||||
'role',
|
||||
'sign',
|
||||
'status',
|
||||
@@ -372,6 +291,8 @@ let UserService = class UserService {
|
||||
'createdAt',
|
||||
'lastLoginIp',
|
||||
'phone',
|
||||
'realName',
|
||||
'idCard',
|
||||
],
|
||||
});
|
||||
const ids = rows.map((t) => t.id);
|
||||
@@ -388,7 +309,7 @@ let UserService = class UserService {
|
||||
async queryOne({ id }) {
|
||||
return await this.userEntity.findOne({
|
||||
where: { id },
|
||||
select: ['username', 'avatar', 'inviteCode', 'role', 'sign', 'status'],
|
||||
select: ['username', 'avatar', 'role', 'sign', 'status'],
|
||||
});
|
||||
}
|
||||
async updateStatus(body) {
|
||||
@@ -429,15 +350,13 @@ let UserService = class UserService {
|
||||
async getUserFromOpenId(openId, sceneStr) {
|
||||
const user = await this.userEntity.findOne({ where: { openId } });
|
||||
if (!user) {
|
||||
const inviteCode = sceneStr ? sceneStr.split(':')[1] : '';
|
||||
const inviteUser = await this.qureyUserInfoByInviteCode(inviteCode);
|
||||
const user = await this.createUserFromOpenId(openId, inviteCode);
|
||||
await this.userBalanceService.addBalanceToNewUser(user.id, inviteCode ? inviteUser === null || inviteUser === void 0 ? void 0 : inviteUser.id : null);
|
||||
const user = await this.createUserFromOpenId(openId);
|
||||
await this.userBalanceService.addBalanceToNewUser(user.id);
|
||||
return user;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
async createUserFromOpenId(openId, invitedBy) {
|
||||
async createUserFromOpenId(openId) {
|
||||
const userDefautlAvatar = await this.globalConfigService.getConfigs([
|
||||
'userDefautlAvatar',
|
||||
]);
|
||||
@@ -447,14 +366,13 @@ let UserService = class UserService {
|
||||
status: user_constant_1.UserStatusEnum.ACTIVE,
|
||||
sex: 0,
|
||||
email: `${(0, utils_1.createRandomUid)()}@default.com`,
|
||||
invitedBy,
|
||||
openId,
|
||||
};
|
||||
const user = await this.userEntity.save(userInfo);
|
||||
return user;
|
||||
}
|
||||
async createUserFromContact(params) {
|
||||
const { username, email, phone, invitedBy } = params;
|
||||
const { username, email, phone } = params;
|
||||
const userDefautlAvatar = await this.globalConfigService.getConfigs([
|
||||
'userDefautlAvatar',
|
||||
]);
|
||||
@@ -473,9 +391,6 @@ let UserService = class UserService {
|
||||
if (phone) {
|
||||
userInfo.phone = phone;
|
||||
}
|
||||
if (invitedBy) {
|
||||
userInfo.invitedBy = invitedBy;
|
||||
}
|
||||
const user = await this.userEntity.save(userInfo);
|
||||
return user;
|
||||
}
|
||||
@@ -572,6 +487,26 @@ let UserService = class UserService {
|
||||
async createUser(userInfo) {
|
||||
return await this.userEntity.save(userInfo);
|
||||
}
|
||||
async saveRealNameInfo(userId, realName, idCard) {
|
||||
const user = await this.userEntity.findOne({ where: { id: userId } });
|
||||
if (!user) {
|
||||
common_1.Logger.error('用户不存在');
|
||||
}
|
||||
await this.userEntity.update({ id: userId }, { realName, idCard });
|
||||
return;
|
||||
}
|
||||
async updateUserPhone(userId, phone, username, password) {
|
||||
const user = await this.userEntity.findOne({ where: { id: userId } });
|
||||
const hashedPassword = bcrypt.hashSync(password, 10);
|
||||
if (!user) {
|
||||
common_1.Logger.error('用户不存在');
|
||||
}
|
||||
if (!phone || !username || !hashedPassword) {
|
||||
throw new common_1.HttpException('参数错误!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.userEntity.update({ id: userId }, { phone, username, password: hashedPassword });
|
||||
return;
|
||||
}
|
||||
};
|
||||
UserService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
|
||||
Reference in New Issue
Block a user