feat(auth): 实现用户注册地址提交及审核状态管理
- 新增提交注册地址接口,支持录入及提交用户注册地址信息并标记待审核状态 - 新增获取当前用户审核状态接口,返回审核结果和驳回原因 - 用户实体新增审核状态和驳回原因字段,用于注册审核流程 - 管理端新增用户审核接口,支持通过或拒绝用户注册及填写驳回原因 - 下单流程中添加审核状态校验,未通过审核用户禁止下单 - 新增用户注册时审核状态字段,支持前端控制是否走审核流程 - 完善数据库表结构,新增审核状态及驳回原因字段,支持注册审核功能
This commit is contained in:
7
sql/add_user_audit_status.sql
Normal file
7
sql/add_user_audit_status.sql
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
-- 注册审核功能:用户表新增审核状态字段
|
||||||
|
-- 执行前请备份数据库
|
||||||
|
-- 执行时间: 2026-07-11
|
||||||
|
|
||||||
|
ALTER TABLE sys_user
|
||||||
|
ADD COLUMN audit_status INT DEFAULT NULL COMMENT '审核状态: 0待审核, 1已通过, 2已拒绝',
|
||||||
|
ADD COLUMN reject_reason VARCHAR(500) DEFAULT NULL COMMENT '审核驳回原因';
|
||||||
@@ -352,6 +352,48 @@ public class MainController extends BaseController {
|
|||||||
return fail("保存失败", null);
|
return fail("保存失败", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('sys:auth:user')")
|
||||||
|
@OperationLog
|
||||||
|
@Operation(summary = "提交注册地址(注册审核)")
|
||||||
|
@PostMapping("/auth/submitAddress")
|
||||||
|
public ApiResult<User> submitAddress(@RequestBody User param) {
|
||||||
|
Integer userId = getLoginUserId();
|
||||||
|
if (userId == null) {
|
||||||
|
return fail("用户未登录", null);
|
||||||
|
}
|
||||||
|
if (StrUtil.hasBlank(param.getProvince(), param.getCity(), param.getRegion(), param.getAddress())) {
|
||||||
|
return fail("请填写完整的地址信息", null);
|
||||||
|
}
|
||||||
|
User update = new User();
|
||||||
|
update.setUserId(userId);
|
||||||
|
update.setCountry("中国");
|
||||||
|
update.setProvince(param.getProvince());
|
||||||
|
update.setCity(param.getCity());
|
||||||
|
update.setRegion(param.getRegion());
|
||||||
|
update.setAddress(param.getAddress());
|
||||||
|
update.setAuditStatus(0); // 提交地址后标记为待审核
|
||||||
|
update.setRejectReason(null); // 清除之前的驳回原因
|
||||||
|
if (userService.updateById(update)) {
|
||||||
|
return success("提交成功", userService.getByIdRel(userId));
|
||||||
|
}
|
||||||
|
return fail("提交失败", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "查询当前用户审核状态")
|
||||||
|
@GetMapping("/auth/auditStatus")
|
||||||
|
public ApiResult<java.util.Map<String, Object>> getAuditStatus() {
|
||||||
|
Integer userId = getLoginUserId();
|
||||||
|
if (userId == null) {
|
||||||
|
return fail("未登录", null);
|
||||||
|
}
|
||||||
|
User user = userService.getByIdRel(userId);
|
||||||
|
java.util.Map<String, Object> result = new java.util.HashMap<>();
|
||||||
|
result.put("auditStatus", user.getAuditStatus());
|
||||||
|
result.put("rejectReason", user.getRejectReason());
|
||||||
|
result.put("hasAddress", StrUtil.isNotBlank(user.getProvince()) && StrUtil.isNotBlank(user.getAddress()));
|
||||||
|
return success(result);
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:auth:password')")
|
@PreAuthorize("hasAuthority('sys:auth:password')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@Operation(summary = "修改自己密码")
|
@Operation(summary = "修改自己密码")
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.gxwebsoft.common.system.param.OrderParam;
|
|||||||
import com.gxwebsoft.common.system.service.MenuService;
|
import com.gxwebsoft.common.system.service.MenuService;
|
||||||
import com.gxwebsoft.common.system.service.OrderGoodsService;
|
import com.gxwebsoft.common.system.service.OrderGoodsService;
|
||||||
import com.gxwebsoft.common.system.service.OrderService;
|
import com.gxwebsoft.common.system.service.OrderService;
|
||||||
|
import com.gxwebsoft.common.system.service.UserService;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@@ -47,6 +48,18 @@ public class OrderController extends BaseController {
|
|||||||
private MenuService menuService;
|
private MenuService menuService;
|
||||||
@Resource
|
@Resource
|
||||||
private MenuMapper menuMapper;
|
private MenuMapper menuMapper;
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
/** 检查用户审核状态:auditStatus==null(老用户)或1(已通过)返回true,否则false */
|
||||||
|
private boolean checkUserAuditStatus(User loginUser) {
|
||||||
|
if (loginUser == null) return false;
|
||||||
|
User user = userService.getByIdRel(loginUser.getUserId());
|
||||||
|
if (user == null) return false;
|
||||||
|
Integer auditStatus = user.getAuditStatus();
|
||||||
|
// auditStatus == null 表示老用户(功能上线前注册的),默认放行
|
||||||
|
return auditStatus == null || auditStatus == 1;
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "分页查询订单")
|
@Operation(summary = "分页查询订单")
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@@ -94,6 +107,9 @@ public class OrderController extends BaseController {
|
|||||||
if(loginUser == null){
|
if(loginUser == null){
|
||||||
return fail("请先登录");
|
return fail("请先登录");
|
||||||
}
|
}
|
||||||
|
if (!checkUserAuditStatus(loginUser)) {
|
||||||
|
return fail("您的账号尚未通过审核,暂时无法下单");
|
||||||
|
}
|
||||||
if (ObjectUtil.isEmpty(order.getType())) {
|
if (ObjectUtil.isEmpty(order.getType())) {
|
||||||
return fail("订单类型不能为空");
|
return fail("订单类型不能为空");
|
||||||
}
|
}
|
||||||
@@ -184,6 +200,9 @@ public class OrderController extends BaseController {
|
|||||||
// 记录当前登录用户id
|
// 记录当前登录用户id
|
||||||
User loginUser = getLoginUser();
|
User loginUser = getLoginUser();
|
||||||
if (loginUser != null) {
|
if (loginUser != null) {
|
||||||
|
if (!checkUserAuditStatus(loginUser)) {
|
||||||
|
return fail("您的账号尚未通过审核,暂时无法下单");
|
||||||
|
}
|
||||||
// 封装订单数据
|
// 封装订单数据
|
||||||
final Order order = new Order();
|
final Order order = new Order();
|
||||||
order.setType(cart.getType());
|
order.setType(cart.getType());
|
||||||
|
|||||||
@@ -304,6 +304,34 @@ public class UserController extends BaseController {
|
|||||||
return fail("修改失败");
|
return fail("修改失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('sys:user:update')")
|
||||||
|
@OperationLog
|
||||||
|
@Operation(summary = "审核用户注册(通过/拒绝)")
|
||||||
|
@PutMapping("/audit")
|
||||||
|
public ApiResult<?> auditUser(@RequestBody User user) {
|
||||||
|
if (user.getUserId() == null || user.getAuditStatus() == null
|
||||||
|
|| !Arrays.asList(0, 1, 2).contains(user.getAuditStatus())) {
|
||||||
|
return fail("参数不正确");
|
||||||
|
}
|
||||||
|
User update = new User();
|
||||||
|
update.setUserId(user.getUserId());
|
||||||
|
update.setAuditStatus(user.getAuditStatus());
|
||||||
|
// 拒绝时必须填写驳回原因
|
||||||
|
if (user.getAuditStatus() == 2) {
|
||||||
|
if (StrUtil.isBlank(user.getRejectReason())) {
|
||||||
|
return fail("驳回时请填写原因");
|
||||||
|
}
|
||||||
|
update.setRejectReason(user.getRejectReason());
|
||||||
|
} else {
|
||||||
|
// 通过或重新设为待审核时清除驳回原因
|
||||||
|
update.setRejectReason(null);
|
||||||
|
}
|
||||||
|
if (userService.updateById(update)) {
|
||||||
|
return success(user.getAuditStatus() == 1 ? "审核通过" : "已拒绝");
|
||||||
|
}
|
||||||
|
return fail("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:user:update')")
|
@PreAuthorize("hasAuthority('sys:user:update')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@Operation(summary = "修改推荐状态")
|
@Operation(summary = "修改推荐状态")
|
||||||
|
|||||||
@@ -517,6 +517,8 @@ public class WxLoginController extends BaseController {
|
|||||||
User addUser = new User();
|
User addUser = new User();
|
||||||
// 注册用户
|
// 注册用户
|
||||||
addUser.setStatus(0);
|
addUser.setStatus(0);
|
||||||
|
// 默认审核通过;前端传 auditStatus=0 时走审核流程,传其他值则按前端值
|
||||||
|
addUser.setAuditStatus(userParam.getAuditStatus() != null ? userParam.getAuditStatus() : 1);
|
||||||
addUser.setUsername(createUsername("wx_"));
|
addUser.setUsername(createUsername("wx_"));
|
||||||
addUser.setNickname("微信用户");
|
addUser.setNickname("微信用户");
|
||||||
addUser.setPlatform(MP_WEIXIN);
|
addUser.setPlatform(MP_WEIXIN);
|
||||||
|
|||||||
@@ -222,6 +222,12 @@ public class User implements UserDetails {
|
|||||||
@Schema(description = "专家角色")
|
@Schema(description = "专家角色")
|
||||||
private Integer expertType;
|
private Integer expertType;
|
||||||
|
|
||||||
|
@Schema(description = "审核状态: 0待审核, 1已通过, 2已拒绝")
|
||||||
|
private Integer auditStatus;
|
||||||
|
|
||||||
|
@Schema(description = "审核驳回原因")
|
||||||
|
private String rejectReason;
|
||||||
|
|
||||||
@Schema(description = "状态, 0正常, 1冻结")
|
@Schema(description = "状态, 0正常, 1冻结")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ public class UserParam extends BaseParam {
|
|||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
@Schema(description = "审核状态: 0待审核, 1已通过, 2已拒绝(前端传值决定注册是否走审核流程)")
|
||||||
|
private Integer auditStatus;
|
||||||
|
|
||||||
@Schema(description = "是否删除, 0否, 1是")
|
@Schema(description = "是否删除, 0否, 1是")
|
||||||
@TableLogic
|
@TableLogic
|
||||||
private Integer deleted;
|
private Integer deleted;
|
||||||
|
|||||||
Reference in New Issue
Block a user