|
|
@@ -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;
|
|
|
}
|
|
|
|
|
|
/**
|