feat: 完成 NestJS 后端核心底座开发 (M1-M6) 和 Ant Design Vue 前端迁移
主要更新: 1. 后端核心底座完成 (M1-M6): - 健康检查、指标监控、分布式锁 - 事件总线、队列系统、事务管理 - 安全守卫、多租户隔离、存储适配器 - 审计日志、配置管理、多语言支持 2. 前端迁移到 Ant Design Vue: - 从 Element Plus 迁移到 Ant Design Vue - 完善 system 模块 (role/menu/dept) - 修复依赖和配置问题 3. 文档完善: - AI 开发工作流文档 - 架构约束和开发规范 - 项目进度跟踪 4. 其他改进: - 修复编译错误和类型问题 - 完善测试用例 - 优化项目结构
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { Injectable, BadRequestException, UnauthorizedException } from '@nestjs/common';
|
||||
import {
|
||||
Injectable,
|
||||
BadRequestException,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository, Not } from 'typeorm';
|
||||
import { CoreMemberService } from '../core/CoreMemberService';
|
||||
@@ -24,20 +28,26 @@ export class MemberService {
|
||||
*/
|
||||
async register(registerDto: any): Promise<any> {
|
||||
// 检查用户名是否已存在
|
||||
const existingUser = await this.memberCoreService.findByUsername(registerDto.username);
|
||||
const existingUser = await this.memberCoreService.findByUsername(
|
||||
registerDto.username,
|
||||
);
|
||||
if (existingUser) {
|
||||
throw new BadRequestException('用户名已存在');
|
||||
}
|
||||
|
||||
// 检查手机号是否已存在
|
||||
const existingMobile = await this.memberCoreService.findByMobile(registerDto.mobile);
|
||||
const existingMobile = await this.memberCoreService.findByMobile(
|
||||
registerDto.mobile,
|
||||
);
|
||||
if (existingMobile) {
|
||||
throw new BadRequestException('手机号已存在');
|
||||
}
|
||||
|
||||
// 检查邮箱是否已存在
|
||||
if (registerDto.email) {
|
||||
const existingEmail = await this.memberCoreService.findByEmail(registerDto.email);
|
||||
const existingEmail = await this.memberCoreService.findByEmail(
|
||||
registerDto.email,
|
||||
);
|
||||
if (existingEmail) {
|
||||
throw new BadRequestException('邮箱已存在');
|
||||
}
|
||||
@@ -45,7 +55,7 @@ export class MemberService {
|
||||
|
||||
// 创建会员
|
||||
const member = await this.memberCoreService.create(registerDto);
|
||||
|
||||
|
||||
// 返回注册成功信息(不包含密码)
|
||||
const { password, ...result } = member;
|
||||
return result;
|
||||
@@ -56,7 +66,7 @@ export class MemberService {
|
||||
*/
|
||||
async login(loginDto: any): Promise<any> {
|
||||
const { username, password } = loginDto;
|
||||
|
||||
|
||||
// 查找会员
|
||||
const member = await this.memberCoreService.findByUsername(username);
|
||||
if (!member) {
|
||||
@@ -64,7 +74,10 @@ export class MemberService {
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
const isValidPassword = await this.memberCoreService.validatePassword(member, password);
|
||||
const isValidPassword = await this.memberCoreService.validatePassword(
|
||||
member,
|
||||
password,
|
||||
);
|
||||
if (!isValidPassword) {
|
||||
throw new UnauthorizedException('用户名或密码错误');
|
||||
}
|
||||
@@ -91,7 +104,7 @@ export class MemberService {
|
||||
*/
|
||||
async getProfile(memberId: number): Promise<any> {
|
||||
const member = await this.memberCoreService.findById(memberId);
|
||||
|
||||
|
||||
// 返回会员信息(不包含密码)
|
||||
const { password, ...result } = member;
|
||||
return result;
|
||||
@@ -111,7 +124,10 @@ export class MemberService {
|
||||
|
||||
// 检查用户名是否重复
|
||||
if (updateDto.username) {
|
||||
const exists = await this.memberCoreService.isUsernameExists(updateDto.username, memberId);
|
||||
const exists = await this.memberCoreService.isUsernameExists(
|
||||
updateDto.username,
|
||||
memberId,
|
||||
);
|
||||
if (exists) {
|
||||
throw new BadRequestException('用户名已存在');
|
||||
}
|
||||
@@ -119,7 +135,10 @@ export class MemberService {
|
||||
|
||||
// 检查手机号是否重复
|
||||
if (updateDto.mobile) {
|
||||
const exists = await this.memberCoreService.isMobileExists(updateDto.mobile, memberId);
|
||||
const exists = await this.memberCoreService.isMobileExists(
|
||||
updateDto.mobile,
|
||||
memberId,
|
||||
);
|
||||
if (exists) {
|
||||
throw new BadRequestException('手机号已存在');
|
||||
}
|
||||
@@ -127,7 +146,10 @@ export class MemberService {
|
||||
|
||||
// 检查邮箱是否重复
|
||||
if (updateDto.email) {
|
||||
const exists = await this.memberCoreService.isEmailExists(updateDto.email, memberId);
|
||||
const exists = await this.memberCoreService.isEmailExists(
|
||||
updateDto.email,
|
||||
memberId,
|
||||
);
|
||||
if (exists) {
|
||||
throw new BadRequestException('邮箱已存在');
|
||||
}
|
||||
@@ -140,13 +162,19 @@ export class MemberService {
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
async changePassword(memberId: number, changePasswordDto: any): Promise<void> {
|
||||
async changePassword(
|
||||
memberId: number,
|
||||
changePasswordDto: any,
|
||||
): Promise<void> {
|
||||
const { oldPassword, newPassword } = changePasswordDto;
|
||||
|
||||
|
||||
const member = await this.memberCoreService.findById(memberId);
|
||||
|
||||
|
||||
// 验证旧密码
|
||||
const isValidPassword = await this.memberCoreService.validatePassword(member, oldPassword);
|
||||
const isValidPassword = await this.memberCoreService.validatePassword(
|
||||
member,
|
||||
oldPassword,
|
||||
);
|
||||
if (!isValidPassword) {
|
||||
throw new BadRequestException('原密码错误');
|
||||
}
|
||||
@@ -161,7 +189,7 @@ export class MemberService {
|
||||
*/
|
||||
async resetPassword(resetDto: any): Promise<void> {
|
||||
const { mobile, verifyCode, newPassword } = resetDto;
|
||||
|
||||
|
||||
// 验证手机号
|
||||
const member = await this.memberCoreService.findByMobile(mobile);
|
||||
if (!member) {
|
||||
@@ -172,13 +200,15 @@ export class MemberService {
|
||||
if (!verifyCode) {
|
||||
throw new Error('验证码不能为空');
|
||||
}
|
||||
|
||||
|
||||
// 这里应该验证验证码的有效性
|
||||
// 可以从缓存中获取验证码进行比较
|
||||
|
||||
// 更新密码
|
||||
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
||||
await this.memberCoreService.update(member.member_id, { password: hashedPassword });
|
||||
await this.memberCoreService.update(member.member_id, {
|
||||
password: hashedPassword,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,8 +221,8 @@ export class MemberService {
|
||||
where: {
|
||||
member_id: memberId,
|
||||
sign_date: today,
|
||||
is_del: 0
|
||||
}
|
||||
is_del: 0,
|
||||
},
|
||||
});
|
||||
|
||||
if (existingSign) {
|
||||
@@ -202,16 +232,18 @@ export class MemberService {
|
||||
// 2. 计算连续签到天数
|
||||
const yesterday = new Date(today);
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
|
||||
const yesterdaySign = await this.memberSignRepository.findOne({
|
||||
where: {
|
||||
member_id: memberId,
|
||||
sign_date: yesterday,
|
||||
is_del: 0
|
||||
}
|
||||
is_del: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const continuousDays = yesterdaySign ? yesterdaySign.continuous_days + 1 : 1;
|
||||
const continuousDays = yesterdaySign
|
||||
? yesterdaySign.continuous_days + 1
|
||||
: 1;
|
||||
|
||||
// 3. 分配积分(根据连续签到天数计算)
|
||||
const signPoints = this.calculateSignPoints(continuousDays);
|
||||
@@ -226,7 +258,7 @@ export class MemberService {
|
||||
sign_ip: signInfo.ip,
|
||||
sign_address: signInfo.address,
|
||||
sign_device: signInfo.device,
|
||||
status: 1
|
||||
status: 1,
|
||||
});
|
||||
|
||||
await this.memberSignRepository.save(signRecord);
|
||||
@@ -239,7 +271,7 @@ export class MemberService {
|
||||
message: '签到成功',
|
||||
continuous_days: continuousDays,
|
||||
sign_point: signPoints,
|
||||
total_points: await this.getMemberTotalPoints(memberId)
|
||||
total_points: await this.getMemberTotalPoints(memberId),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -247,8 +279,8 @@ export class MemberService {
|
||||
* 计算签到积分
|
||||
*/
|
||||
private calculateSignPoints(continuousDays: number): number {
|
||||
if (continuousDays >= 7) return 20; // 连续7天以上
|
||||
if (continuousDays >= 3) return 15; // 连续3天以上
|
||||
if (continuousDays >= 7) return 20; // 连续7天以上
|
||||
if (continuousDays >= 3) return 15; // 连续3天以上
|
||||
return 10; // 基础积分
|
||||
}
|
||||
|
||||
@@ -265,24 +297,26 @@ export class MemberService {
|
||||
*/
|
||||
async getPointsHistory(memberId: number, queryDto: any): Promise<any> {
|
||||
const { page = 1, limit = 20 } = queryDto;
|
||||
|
||||
|
||||
// 查询积分变动记录
|
||||
const [records, total] = await this.memberAccountLogRepository.findAndCount({
|
||||
where: {
|
||||
member_id: memberId,
|
||||
account_type: 'point'
|
||||
const [records, total] = await this.memberAccountLogRepository.findAndCount(
|
||||
{
|
||||
where: {
|
||||
member_id: memberId,
|
||||
account_type: 'point',
|
||||
},
|
||||
order: { create_time: 'DESC' },
|
||||
skip: (page - 1) * limit,
|
||||
take: limit,
|
||||
},
|
||||
order: { create_time: 'DESC' },
|
||||
skip: (page - 1) * limit,
|
||||
take: limit
|
||||
});
|
||||
);
|
||||
|
||||
return {
|
||||
list: records,
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
total_pages: Math.ceil(total / limit)
|
||||
total_pages: Math.ceil(total / limit),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -291,24 +325,26 @@ export class MemberService {
|
||||
*/
|
||||
async getBalanceHistory(memberId: number, queryDto: any): Promise<any> {
|
||||
const { page = 1, limit = 20 } = queryDto;
|
||||
|
||||
|
||||
// 查询余额变动记录
|
||||
const [records, total] = await this.memberAccountLogRepository.findAndCount({
|
||||
where: {
|
||||
member_id: memberId,
|
||||
account_type: 'balance'
|
||||
const [records, total] = await this.memberAccountLogRepository.findAndCount(
|
||||
{
|
||||
where: {
|
||||
member_id: memberId,
|
||||
account_type: 'balance',
|
||||
},
|
||||
order: { create_time: 'DESC' },
|
||||
skip: (page - 1) * limit,
|
||||
take: limit,
|
||||
},
|
||||
order: { create_time: 'DESC' },
|
||||
skip: (page - 1) * limit,
|
||||
take: limit
|
||||
});
|
||||
);
|
||||
|
||||
return {
|
||||
list: records,
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
total_pages: Math.ceil(total / limit)
|
||||
total_pages: Math.ceil(total / limit),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -336,7 +372,7 @@ export class MemberService {
|
||||
if (addressDto.is_default) {
|
||||
await this.memberAddressRepository.update(
|
||||
{ member_id: memberId, is_default: 1 },
|
||||
{ is_default: 0 }
|
||||
{ is_default: 0 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -344,7 +380,7 @@ export class MemberService {
|
||||
...addressDto,
|
||||
member_id: memberId,
|
||||
site_id: addressDto.site_id || 0,
|
||||
status: 1
|
||||
status: 1,
|
||||
});
|
||||
|
||||
return this.memberAddressRepository.save(addressDto);
|
||||
@@ -353,10 +389,14 @@ export class MemberService {
|
||||
/**
|
||||
* 更新会员地址
|
||||
*/
|
||||
async updateAddress(memberId: number, addressId: number, addressDto: any): Promise<void> {
|
||||
async updateAddress(
|
||||
memberId: number,
|
||||
addressId: number,
|
||||
addressDto: any,
|
||||
): Promise<void> {
|
||||
// 验证地址是否属于当前会员
|
||||
const address = await this.memberAddressRepository.findOne({
|
||||
where: { id: addressId, member_id: memberId }
|
||||
where: { id: addressId, member_id: memberId },
|
||||
});
|
||||
|
||||
if (!address) {
|
||||
@@ -367,7 +407,7 @@ export class MemberService {
|
||||
if (addressDto.is_default) {
|
||||
await this.memberAddressRepository.update(
|
||||
{ member_id: memberId, is_default: 1, id: Not(addressId) },
|
||||
{ is_default: 0 }
|
||||
{ is_default: 0 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -380,7 +420,7 @@ export class MemberService {
|
||||
async deleteAddress(memberId: number, addressId: number): Promise<void> {
|
||||
// 验证地址是否属于当前会员
|
||||
const address = await this.memberAddressRepository.findOne({
|
||||
where: { id: addressId, member_id: memberId }
|
||||
where: { id: addressId, member_id: memberId },
|
||||
});
|
||||
|
||||
if (!address) {
|
||||
@@ -397,7 +437,7 @@ export class MemberService {
|
||||
async setDefaultAddress(memberId: number, addressId: number): Promise<void> {
|
||||
// 验证地址是否属于当前会员
|
||||
const address = await this.memberAddressRepository.findOne({
|
||||
where: { id: addressId, member_id: memberId }
|
||||
where: { id: addressId, member_id: memberId },
|
||||
});
|
||||
|
||||
if (!address) {
|
||||
@@ -406,8 +446,8 @@ export class MemberService {
|
||||
|
||||
// 先取消其他默认地址
|
||||
await this.memberAddressRepository.update(
|
||||
{ member_id: memberId, is_default: 1, id: Not(addressId) },
|
||||
{ is_default: 0 }
|
||||
{ member_id: memberId, is_default: 1, id: Not(addressId) },
|
||||
{ is_default: 0 },
|
||||
);
|
||||
|
||||
// 设置当前地址为默认
|
||||
@@ -417,12 +457,14 @@ export class MemberService {
|
||||
/**
|
||||
* 会员登出
|
||||
*/
|
||||
async logout(memberId: number): Promise<{ success: boolean; message: string }> {
|
||||
async logout(
|
||||
memberId: number,
|
||||
): Promise<{ success: boolean; message: string }> {
|
||||
// 这里可以清除会员的登录状态、token 等
|
||||
// 暂时返回成功状态
|
||||
return {
|
||||
success: true,
|
||||
message: '登出成功'
|
||||
message: '登出成功',
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user