From f71719bf3e2b433b790cfaa83265611faf1f1a1c Mon Sep 17 00:00:00 2001 From: tj <1378534974@qq.com> Date: 星期五, 11 四月 2025 17:38:06 +0800 Subject: [PATCH] 1.账户注销等 --- src/main/java/com/mzl/flower/web/login/CustomerLoginController.java | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 53 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/mzl/flower/web/login/CustomerLoginController.java b/src/main/java/com/mzl/flower/web/login/CustomerLoginController.java index 29a6bce..7bf98ed 100644 --- a/src/main/java/com/mzl/flower/web/login/CustomerLoginController.java +++ b/src/main/java/com/mzl/flower/web/login/CustomerLoginController.java @@ -8,6 +8,7 @@ import com.mzl.flower.base.cache.StringCacheClient; import com.mzl.flower.config.exception.BaseException; import com.mzl.flower.config.exception.ValidationException; +import com.mzl.flower.config.security.SecurityUtils; import com.mzl.flower.config.security.token.PhoneAuthenticationToken; import com.mzl.flower.config.security.token.UserIdAuthenticationToken; import com.mzl.flower.config.security.token.WebAuthenticationToken; @@ -17,6 +18,8 @@ import com.mzl.flower.dto.request.UserPhoneLoginDTO; import com.mzl.flower.dto.response.customer.CustomerDTO; import com.mzl.flower.dto.response.wx.WxUserVO; +import com.mzl.flower.dto.security.UserDTO; +import com.mzl.flower.entity.customer.Customer; import com.mzl.flower.entity.system.User; import com.mzl.flower.mapper.customer.CustomerMapper; import com.mzl.flower.service.customer.CustomerService; @@ -28,6 +31,7 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.AuthenticationDetailsSource; @@ -311,6 +315,8 @@ if (currentCustomer.getIsEnabled() == false) { throw new ValidationException("用户已禁用,请联系管理员"); } + + tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + user.getId()); if (StringUtils.isNotBlank(tokenCache)) { //强制删除token,下线 @@ -333,4 +339,50 @@ throw new BaseException(R.RUNTIME_EXCEPTION.getCode(),"登录错误"); } } -} + + + @PostMapping("/account/close") + @ApiOperation(value = "账户注销", notes = "账户注销") + public ResponseEntity<ReturnDataDTO<Boolean>> accountClose() { + + String userId = SecurityUtils.getUserId(); + + if(StringUtils.isNotBlank(userId)){ + // + CustomerDTO currentCustomer = customerMapper.getCurrentCustomer(userId); + if(null==currentCustomer){ + throw new BaseException(R.RUNTIME_EXCEPTION.getCode(),"用户不存在"); + } + + currentCustomer.setIsClosed(true); + + User user=userService.getUserById(userId); + + + if (StringUtils.isNotBlank(user.getLoginName())) { + currentCustomer.setName("智信-" + user.getLoginName().substring(user.getLoginName().length() - 4)); + + } + currentCustomer.setCover("https://hmy-flower.oss-cn-shanghai.aliyuncs.com/8f/8f205ea4618b4ce48d5bd204ae73f075tmp_f0c47a66148245dc17d74563c5939e764273ba583619664d.jpg"); + + Customer customer=new Customer(); + BeanUtils.copyProperties(currentCustomer,customer); + + // 会员注销 + customer.setIsMember(false); + // 会员过期时间设置为空 + customer.setMemberOvertime(null); + + customerMapper.updateById(customer); + + return returnData(R.SUCCESS.getCode(),true); + + }else{ + throw new BaseException(R.RUNTIME_EXCEPTION.getCode(),"用户ID不能为空"); + } + + + } + + + } -- Gitblit v1.9.3