lutong 2 өдөр өмнө
parent
commit
5fb64101aa

+ 2 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LifeUserVo.java

@@ -1,5 +1,6 @@
 package shop.alien.entity.store.vo;
 
+import com.fasterxml.jackson.annotation.JsonAlias;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -66,5 +67,6 @@ public class LifeUserVo extends LifeUser {
     private String accountName;
 
     @ApiModelProperty(value = "验证码")
+    @JsonAlias("code")
     private String verificationCode;
 }

+ 31 - 10
alien-store/src/main/java/shop/alien/store/controller/LifeUserController.java

@@ -14,8 +14,8 @@ import shop.alien.entity.store.LifeUser;
 import shop.alien.entity.store.dto.LifeFansFollowOutcome;
 import shop.alien.entity.store.vo.LifeUserVo;
 import shop.alien.mapper.LifeUserMapper;
-import shop.alien.store.config.BaseRedisService;
 import shop.alien.store.service.LifeUserService;
+import shop.alien.store.util.ali.AliSms;
 import shop.alien.util.common.FileUpload;
 import shop.alien.util.common.RandomCreateUtil;
 
@@ -41,7 +41,7 @@ public class LifeUserController {
 
     private final LifeUserMapper lifeUserMapper;
 
-    private final BaseRedisService baseRedisService;
+    private final AliSms aliSms;
 
     @ApiOperation("查询用户信息")
     @ApiOperationSupport(order = 2)
@@ -168,16 +168,37 @@ public class LifeUserController {
     @ApiOperation("用户端注销用户")
     @PostMapping("/liftCancelAccount")
     public R<Boolean> liftCancelAccount(@RequestBody LifeUserVo user) {
-        log.info("StoreUserController.liftCancelAccount?LifeUserVo={}", user.toString());
-        // 2025-11-04 验证码-用户端注销账号
-        String cacheCode = baseRedisService.getString("verification_user_cancel_account_" + user.getUserPhone());
-        if (null == cacheCode) {
-            return R.fail("验证码过期或未发送");
+        log.info("LifeUserController.liftCancelAccount?LifeUserVo={}", user);
+        if (user.getId() == null) {
+            return R.fail("用户id不能为空");
         }
-        if (!cacheCode.trim().equals(user.getVerificationCode().trim())) {
-            return R.fail("验证码错误");
+        LifeUser lifeUser = lifeUserMapper.selectById(user.getId());
+        if (lifeUser == null) {
+            return R.fail("用户不存在");
+        }
+        if (lifeUser.getLogoutFlag() != null && lifeUser.getLogoutFlag() == 1) {
+            return R.fail("账号已在注销中");
+        }
+        if (!StringUtils.hasText(lifeUser.getUserPhone())) {
+            return R.fail("用户手机号不存在");
+        }
+        if (!StringUtils.hasText(user.getVerificationCode())) {
+            return R.fail("验证码不能为空");
+        }
+        int code;
+        try {
+            code = Integer.parseInt(user.getVerificationCode().trim());
+        } catch (NumberFormatException e) {
+            return R.fail("验证码格式错误");
+        }
+        if (!aliSms.checkSmsCode(lifeUser.getUserPhone(), 0, 5, code)) {
+            return R.fail("验证码错误或已过期");
+        }
+        try {
+            service.liftCancelAccount(user);
+        } catch (IllegalArgumentException e) {
+            return R.fail(e.getMessage());
         }
-        service.liftCancelAccount(user);
         return R.success("注销成功");
     }
 

+ 10 - 7
alien-store/src/main/java/shop/alien/store/service/LifeUserService.java

@@ -475,15 +475,18 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
     }
 
     public void liftCancelAccount(LifeUser user) {
-        // 通过id获取当前用户账号信息
-        LambdaQueryWrapper<LifeUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
-        lambdaQueryWrapper.eq(LifeUser::getId, user.getId());
-        LifeUser lifeUser = lifeUserMapper.selectOne(lambdaQueryWrapper);
-        // 修改注销标记为1
+        if (user == null || user.getId() == null) {
+            throw new IllegalArgumentException("用户id不能为空");
+        }
+        LifeUser lifeUser = lifeUserMapper.selectById(user.getId());
+        if (lifeUser == null) {
+            throw new IllegalArgumentException("用户不存在");
+        }
+        if (lifeUser.getLogoutFlag() != null && lifeUser.getLogoutFlag() == 1) {
+            throw new IllegalArgumentException("账号已在注销中");
+        }
         lifeUser.setLogoutFlag(1);
-        // 添加注销原因
         lifeUser.setLogoutReason(user.getLogoutReason());
-        // 添加注销申请时间
         lifeUser.setLogoutTime(new Date());
         lifeUserMapper.updateById(lifeUser);
     }