zhangchen 7 ore fa
parent
commit
b9057ac46d

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/LifeUser.java

@@ -201,4 +201,8 @@ public class LifeUser implements Serializable {
     @TableField("is_popup")
     private Integer isPopup;
 
+    @ApiModelProperty(value = "注销其他原因")
+    @TableField("logout_context")
+    private String logoutContext;
+
 }

+ 35 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LifeUserCancelAccountResultVo.java

@@ -0,0 +1,35 @@
+package shop.alien.entity.store.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * C 端用户申请注销接口返回体
+ */
+@Data
+@JsonInclude
+@ApiModel(value = "LifeUserCancelAccountResultVo", description = "用户端申请注销返回")
+public class LifeUserCancelAccountResultVo {
+
+    /** 0-注销成功 */
+    public static final int STATUS_SUCCESS = 0;
+    /** 1-验证码错误 */
+    public static final int STATUS_SMS_ERROR = 1;
+    /** 2-业务校验信息 */
+    public static final int STATUS_BUSINESS = 2;
+
+    @ApiModelProperty(value = "状态:0-注销成功,1-验证码错误,2-业务校验信息")
+    private Integer status;
+
+    @ApiModelProperty(value = "具体提示:注销成功 / 验证码错误文案 / 业务校验拦截文案")
+    private String message;
+
+    public static LifeUserCancelAccountResultVo of(int status, String message) {
+        LifeUserCancelAccountResultVo vo = new LifeUserCancelAccountResultVo();
+        vo.setStatus(status);
+        vo.setMessage(message);
+        return vo;
+    }
+}

+ 27 - 11
alien-store/src/main/java/shop/alien/store/controller/LifeUserController.java

@@ -12,6 +12,7 @@ import shop.alien.entity.result.R;
 import shop.alien.entity.store.LifeFans;
 import shop.alien.entity.store.LifeUser;
 import shop.alien.entity.store.dto.LifeFansFollowOutcome;
+import shop.alien.entity.store.vo.LifeUserCancelAccountResultVo;
 import shop.alien.entity.store.vo.LifeUserVo;
 import shop.alien.mapper.LifeUserMapper;
 import shop.alien.store.service.LifeUserService;
@@ -167,39 +168,54 @@ public class LifeUserController {
      */
     @ApiOperation("用户端注销用户")
     @PostMapping("/liftCancelAccount")
-    public R<Boolean> liftCancelAccount(@RequestBody LifeUserVo user) {
+    public R<LifeUserCancelAccountResultVo> liftCancelAccount(@RequestBody LifeUserVo user) {
         log.info("LifeUserController.liftCancelAccount?LifeUserVo={}", user);
         if (user.getId() == null) {
-            return R.fail("用户id不能为空");
+            return cancelAccountFail(LifeUserCancelAccountResultVo.STATUS_BUSINESS, "用户id不能为空");
         }
         LifeUser lifeUser = lifeUserMapper.selectById(user.getId());
         if (lifeUser == null) {
-            return R.fail("用户不存在");
+            return cancelAccountFail(LifeUserCancelAccountResultVo.STATUS_BUSINESS, "用户不存在");
         }
-        if (lifeUser.getLogoutFlag() != null && lifeUser.getLogoutFlag() == 1) {
-            return R.fail("账号已在注销中");
+        if (lifeUser.getLogoutFlag() != null
+                && (lifeUser.getLogoutFlag() == LifeUser.LOGOUT_FLAG_DONE
+                || lifeUser.getLogoutFlag() == LifeUser.LOGOUT_FLAG_COOLING)) {
+            return cancelAccountFail(LifeUserCancelAccountResultVo.STATUS_BUSINESS, "账号已在注销中");
         }
         if (!StringUtils.hasText(lifeUser.getUserPhone())) {
-            return R.fail("用户手机号不存在");
+            return cancelAccountFail(LifeUserCancelAccountResultVo.STATUS_BUSINESS, "用户手机号不存在");
         }
         if (!StringUtils.hasText(user.getVerificationCode())) {
-            return R.fail("验证码不能为空");
+            return cancelAccountFail(LifeUserCancelAccountResultVo.STATUS_SMS_ERROR, "验证码不能为空");
         }
         int code;
         try {
             code = Integer.parseInt(user.getVerificationCode().trim());
         } catch (NumberFormatException e) {
-            return R.fail("验证码格式错误");
+            return cancelAccountFail(LifeUserCancelAccountResultVo.STATUS_SMS_ERROR, "验证码格式错误");
         }
         if (!aliSms.checkSmsCode(lifeUser.getUserPhone(), 0, 5, code)) {
-            return R.fail("验证码错误或已过期");
+            return cancelAccountFail(LifeUserCancelAccountResultVo.STATUS_SMS_ERROR, "验证码错误或已过期");
         }
         try {
             service.liftCancelAccount(user);
         } catch (IllegalArgumentException e) {
-            return R.fail(e.getMessage());
+            return cancelAccountFail(LifeUserCancelAccountResultVo.STATUS_BUSINESS, e.getMessage());
         }
-        return R.success("注销成功");
+        return cancelAccountSuccess("注销成功");
+    }
+
+    private R<LifeUserCancelAccountResultVo> cancelAccountSuccess(String message) {
+        LifeUserCancelAccountResultVo body = LifeUserCancelAccountResultVo.of(
+                LifeUserCancelAccountResultVo.STATUS_SUCCESS, message);
+        return R.data(body, message);
+    }
+
+    private R<LifeUserCancelAccountResultVo> cancelAccountFail(int status, String message) {
+        LifeUserCancelAccountResultVo body = LifeUserCancelAccountResultVo.of(status, message);
+        R<LifeUserCancelAccountResultVo> result = R.data(body, message);
+        result.setSuccess(false);
+        return result;
     }
 
     /**

+ 13 - 0
alien-store/src/main/java/shop/alien/store/controller/LifeUserPasswordController.java

@@ -1,6 +1,8 @@
 package shop.alien.store.controller;
 
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperationSupport;
 import lombok.RequiredArgsConstructor;
@@ -35,4 +37,15 @@ public class LifeUserPasswordController {
                 userLoginInfo == null ? null : userLoginInfo.getUserId());
         return lifeUserPasswordService.setPassword(userLoginInfo, dto);
     }
+
+    @ApiOperation("根据用户id查询是否已设置登录密码")
+    @ApiOperationSupport(order = 2)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/hasLoginPassword")
+    public R<Boolean> hasLoginPassword(@RequestParam("userId") Integer userId) {
+        log.info("LifeUserPasswordController.hasLoginPassword?userId={}", userId);
+        return lifeUserPasswordService.hasLoginPassword(userId);
+    }
 }

+ 5 - 0
alien-store/src/main/java/shop/alien/store/service/LifeUserPasswordService.java

@@ -7,4 +7,9 @@ import shop.alien.entity.store.dto.LifeUserPasswordDto;
 public interface LifeUserPasswordService {
 
     R<String> setPassword(UserLoginInfo login, LifeUserPasswordDto dto);
+
+    /**
+     * 根据用户 id 查询是否已设置登录密码
+     */
+    R<Boolean> hasLoginPassword(Integer userId);
 }

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

@@ -558,6 +558,7 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
         // 设置成2,注销冷静期
         lifeUser.setLogoutFlag(2);
         lifeUser.setLogoutReason(user.getLogoutReason());
+        lifeUser.setLogoutContext(user.getLogoutContext());
         lifeUser.setLogoutTime(new Date());
         lifeUserMapper.updateById(lifeUser);
     }
@@ -628,10 +629,12 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
         if (!logoutFlagCooling && !isLifeUserInLogoutCoolingPeriod(lifeUser)) {
             throw new IllegalArgumentException(CANCEL_REVOKE_NOT_IN_COOLING_MSG);
         }
-        lifeUser.setLogoutFlag(0);
-        lifeUser.setLogoutReason(null);
-        lifeUser.setLogoutTime(null);
-        lifeUserMapper.updateById(lifeUser);
+        lifeUserMapper.update(null, new LambdaUpdateWrapper<LifeUser>()
+                .eq(LifeUser::getId, id)
+                .set(LifeUser::getLogoutFlag, LifeUser.LOGOUT_FLAG_NORMAL)
+                .set(LifeUser::getLogoutReason, null)
+                .set(LifeUser::getLogoutContext, null)
+                .set(LifeUser::getLogoutTime, null));
     }
 
     /**

+ 12 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LifeUserPasswordServiceImpl.java

@@ -47,4 +47,16 @@ public class LifeUserPasswordServiceImpl implements LifeUserPasswordService {
         }
         return R.success("设置密码成功");
     }
+
+    @Override
+    public R<Boolean> hasLoginPassword(Integer userId) {
+        if (userId == null) {
+            return R.fail("用户id不能为空");
+        }
+        LifeUser user = lifeUserMapper.selectById(userId);
+        if (user == null) {
+            return R.fail("用户不存在");
+        }
+        return R.data(StringUtils.isNotBlank(user.getPassword()));
+    }
 }