修复一些问题,个人账号功能完善,注册功能完善,收藏,购物车功能完善,初版基本完成,投入测试
This commit is contained in:
@@ -78,12 +78,11 @@ public class TagController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有标签
|
||||
* 查询所有标签(公开接口,不需要权限)
|
||||
*
|
||||
* @return 标签VO列表
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<List<TagVO>> listAllTags() {
|
||||
List<TagVO> tagVOs = tagService.listAllTags();
|
||||
return Result.success(tagVOs);
|
||||
|
||||
@@ -10,6 +10,8 @@ import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.SendVerificationCodeRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UpdatePhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import com.xiaowang.yuminailcore.service.MinioService;
|
||||
@@ -39,6 +41,7 @@ public class UserController {
|
||||
private final UserService userService;
|
||||
private final MinioService minioService;
|
||||
private final VerificationCodeService verificationCodeService;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
@@ -326,6 +329,46 @@ public class UserController {
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销账号
|
||||
*
|
||||
* @param request 请求对象
|
||||
* @return 是否注销成功
|
||||
*/
|
||||
@DeleteMapping("/deactivate")
|
||||
public Result<Boolean> deactivateAccount(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
|
||||
// 获取用户信息
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO == null) {
|
||||
return Result.error("用户不存在");
|
||||
}
|
||||
|
||||
// 管理员账号无法注销
|
||||
if (userDO.getType() == 4) {
|
||||
return Result.error("管理员账号无法注销");
|
||||
}
|
||||
|
||||
// 在删除前先重命名账号和手机号,添加删除时间戳
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String newAccount = userDO.getAccount() + "_deleted_" + timestamp;
|
||||
String newPhone = userDO.getPhone() + "_deleted_" + timestamp;
|
||||
|
||||
try {
|
||||
UserDTO updateDTO = new UserDTO();
|
||||
updateDTO.setAccount(newAccount);
|
||||
updateDTO.setPhone(newPhone);
|
||||
userService.updateUser(userId, updateDTO);
|
||||
} catch (Exception e) {
|
||||
System.out.println("重命名账号和手机号失败: " + e.getMessage());
|
||||
// 重命名失败也继续删除流程
|
||||
}
|
||||
|
||||
boolean success = userService.deleteUser(userId);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PasswordDTO {
|
||||
private String password;
|
||||
|
||||
@@ -16,4 +16,6 @@ public class LoginRequestDTO {
|
||||
private String password;
|
||||
|
||||
private Boolean rememberMe;
|
||||
|
||||
private Long shopId;
|
||||
}
|
||||
@@ -20,4 +20,6 @@ public class PhoneLoginRequestDTO {
|
||||
@NotBlank(message = "验证码不能为空")
|
||||
@Pattern(regexp = "^\\d{6}$", message = "验证码必须是6位数字")
|
||||
private String verificationCode;
|
||||
|
||||
private Long shopId;
|
||||
}
|
||||
+44
-6
@@ -162,6 +162,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
"tag:view", "tag:create", "tag:edit", "tag:assign",
|
||||
"coupon:view", "coupon:assign", "order:view", "order:process")
|
||||
);
|
||||
} else if (userType == 0) { // 普通用户
|
||||
// 分配普通用户默认权限
|
||||
// 首页的查看权限
|
||||
// 仪表盘的查看权限
|
||||
// 商品查看权限
|
||||
// 标签查看权限
|
||||
// 店铺查看权限
|
||||
// 订单查看权限
|
||||
permissions = permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
.in(PermissionDO::getPermissionCode, "home:view", "dashboard:view",
|
||||
"product:view", "tag:view", "shop:view", "order:view")
|
||||
);
|
||||
}
|
||||
|
||||
if (permissions != null && !permissions.isEmpty()) {
|
||||
@@ -379,6 +393,16 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
throw new RuntimeException("密码错误");
|
||||
}
|
||||
|
||||
// 检查是否需要设置店铺
|
||||
if (userDO.getShopId() == null || userDO.getShopId() == 0) {
|
||||
if (loginRequestDTO.getShopId() == null || loginRequestDTO.getShopId() == 0) {
|
||||
throw new RuntimeException("请选择店铺");
|
||||
}
|
||||
userDO.setShopId(loginRequestDTO.getShopId());
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
userMapper.updateById(userDO);
|
||||
}
|
||||
|
||||
String accessToken = jwtUtil.generateAccessToken(userDO.getId(), userDO.getAccount());
|
||||
String refreshToken = jwtUtil.generateRefreshToken(userDO.getId(), userDO.getAccount());
|
||||
|
||||
@@ -411,7 +435,19 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
);
|
||||
|
||||
if (userDO == null) {
|
||||
userDO = registerByPhone(phoneLoginRequestDTO.getPhone());
|
||||
if (phoneLoginRequestDTO.getShopId() == null || phoneLoginRequestDTO.getShopId() == 0) {
|
||||
throw new RuntimeException("首次登录需要选择店铺");
|
||||
}
|
||||
userDO = registerByPhone(phoneLoginRequestDTO.getPhone(), phoneLoginRequestDTO.getShopId());
|
||||
} else {
|
||||
if (userDO.getShopId() == null || userDO.getShopId() == 0) {
|
||||
if (phoneLoginRequestDTO.getShopId() == null || phoneLoginRequestDTO.getShopId() == 0) {
|
||||
throw new RuntimeException("请选择店铺");
|
||||
}
|
||||
userDO.setShopId(phoneLoginRequestDTO.getShopId());
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
userMapper.updateById(userDO);
|
||||
}
|
||||
}
|
||||
|
||||
String accessToken = jwtUtil.generateAccessToken(userDO.getId(), userDO.getAccount());
|
||||
@@ -430,7 +466,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userInfo.setCreateTime(userDO.getCreateTime());
|
||||
responseVO.setUserInfo(userInfo);
|
||||
|
||||
// 设置是否需要设置密码
|
||||
responseVO.setNeedSetPassword(ENCODED_UNSET_PASSWORD.equals(userDO.getPassword()));
|
||||
|
||||
return responseVO;
|
||||
@@ -440,7 +475,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
private static final String UNSET_PASSWORD_MARKER = "__UNSET_PASSWORD__";
|
||||
private static final String ENCODED_UNSET_PASSWORD = "$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW"; // 加密后的特殊标识
|
||||
|
||||
private UserDO registerByPhone(String phone) {
|
||||
private UserDO registerByPhone(String phone, Long shopId) {
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setAccount(phone);
|
||||
userDO.setPhone(phone);
|
||||
@@ -448,12 +483,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setNickname("用户" + phone.substring(7));
|
||||
userDO.setType(0);
|
||||
userDO.setLevel("普通");
|
||||
userDO.setShopId(0L);
|
||||
userDO.setShopId(shopId);
|
||||
userDO.setIsDelete(0);
|
||||
userDO.setStatus(1);
|
||||
userDO.setCreateTime(LocalDateTime.now());
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
// 设置未设置密码的特殊标识
|
||||
userDO.setPassword(ENCODED_UNSET_PASSWORD);
|
||||
|
||||
userMapper.insert(userDO);
|
||||
@@ -511,7 +545,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
);
|
||||
|
||||
if (existingUser != null) {
|
||||
throw new RuntimeException("账号已存在");
|
||||
if (existingUser.getIsDelete() == 0) {
|
||||
throw new RuntimeException("账号已存在");
|
||||
} else {
|
||||
throw new RuntimeException("该账号已被注销,请使用手机号验证码登录");
|
||||
}
|
||||
}
|
||||
|
||||
UserDO existingPhoneUser = userMapper.selectOne(
|
||||
|
||||
@@ -235,7 +235,7 @@ create table t_user
|
||||
shop_id bigint unsigned default 0 null comment '所属店铺ID,关联店铺表主键(0表示无所属店铺)',
|
||||
nickname varchar(50) not null comment '用户昵称',
|
||||
account varchar(50) not null comment '用户账号(登录用)',
|
||||
phone varchar(20) null comment '手机号',
|
||||
phone varchar(50) null comment '手机号',
|
||||
email varchar(100) null comment '邮箱',
|
||||
phone_verified tinyint unsigned default 0 null comment '手机号是否已验证:0-未验证,1-已验证',
|
||||
email_verified tinyint unsigned default 0 null comment '邮箱是否已验证:0-未验证,1-已验证',
|
||||
@@ -576,4 +576,25 @@ create table t_order_item
|
||||
) comment '订单商品表';
|
||||
|
||||
create index idx_order_id
|
||||
on t_order_item (order_id) comment '按订单查询商品的索引';
|
||||
on t_order_item (order_id) comment '按订单查询商品的索引';
|
||||
|
||||
|
||||
-- 商品收藏表
|
||||
create table t_wishlist
|
||||
(
|
||||
id bigint unsigned auto_increment comment '收藏记录唯一主键ID'
|
||||
primary key comment '商品收藏主键索引',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
product_id bigint unsigned not null comment '关联商品表主键',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删除,1-已删除',
|
||||
constraint uk_user_product
|
||||
unique (user_id, product_id) comment '用户-商品唯一索引'
|
||||
) comment '商品收藏表';
|
||||
|
||||
create index idx_user_id
|
||||
on t_wishlist (user_id) comment '按用户查询收藏的索引';
|
||||
|
||||
create index idx_product_id
|
||||
on t_wishlist (product_id) comment '按商品查询收藏的索引';
|
||||
|
||||
Reference in New Issue
Block a user