|
|
@@ -8,6 +8,7 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
+import org.springblade.common.enums.AppConstant;
|
|
|
import org.springblade.common.enums.ResCode;
|
|
|
import org.springblade.common.enums.ShopEnum;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
@@ -47,8 +48,12 @@ public class AppAccountController {
|
|
|
@PostMapping("login")
|
|
|
@ApiOperation(value = "商户登录")
|
|
|
@SneakyThrows
|
|
|
- public R login(@RequestBody @Valid Account account) throws ServiceException {
|
|
|
- Account user = accountService.getOne(new QueryWrapper<Account>().lambda().eq(Account::getPhone, account.getPhone()));
|
|
|
+ public R login(@RequestBody Account account) throws ServiceException {
|
|
|
+ Assert.notNull(account.getPhone(), "手机号不能为空");
|
|
|
+ Assert.notNull(account.getSecret(), "密码不能为空");
|
|
|
+ Account user = accountService.getOne(new QueryWrapper<Account>().lambda()
|
|
|
+ .eq(Account::getPhone, account.getPhone())
|
|
|
+ .eq(Account::getType, AppConstant.PLATFORM.SHOP.name()));
|
|
|
Assert.notNull(user, () -> {
|
|
|
throw new ServiceException(ResCode.USER_NOT_FOUNT);
|
|
|
});
|
|
|
@@ -63,6 +68,7 @@ public class AppAccountController {
|
|
|
@ApiOperation(value = "注册账号")
|
|
|
@SneakyThrows
|
|
|
public R register(@RequestBody @Valid AppAccountDto appAccountDto) {
|
|
|
+ Assert.notNull(appAccountDto.getSecret(), "密码不能为空");
|
|
|
Account isExit = accountService.getOne(Condition.getQueryWrapper(new Account()).lambda().eq(Account::getPhone, appAccountDto.getPhone()));
|
|
|
Assert.isNull(isExit, "该手机号已注册");
|
|
|
|
|
|
@@ -72,6 +78,7 @@ public class AppAccountController {
|
|
|
});
|
|
|
Account account = new Account();
|
|
|
BeanUtil.copyProperties(appAccountDto, account);
|
|
|
+ account.setType(AppConstant.PLATFORM.SHOP.name());
|
|
|
account.setSecret(DigestUtil.hex(account.getSecret()));
|
|
|
Assert.isTrue(accountService.saveOrUpdate(account), () -> {
|
|
|
throw new ServiceException(ResCode.SHOP_REGISTER_ERROR);
|
|
|
@@ -79,5 +86,42 @@ public class AppAccountController {
|
|
|
return R.data(account);
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("phoneLogin")
|
|
|
+ @ApiOperation(value = "手机号登录")
|
|
|
+ @SneakyThrows
|
|
|
+ public R phoneLogin(@RequestBody @Valid AppAccountDto appAccountDto) {
|
|
|
+ this.VerifyCode(appAccountDto);
|
|
|
+ List<Shop> list = shopService.list(Condition.getQueryWrapper(new Shop()).lambda().eq(Shop::getPersonTel, appAccountDto.getPhone()));
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("forgetPsw")
|
|
|
+ @ApiOperation(value = "忘记密码")
|
|
|
+ @SneakyThrows
|
|
|
+ public R forgetPsw(@RequestBody @Valid AppAccountDto appAccountDto) {
|
|
|
+ Assert.notNull(appAccountDto.getSecret(), "新密码不能为空");
|
|
|
+ Account account = this.VerifyCode(appAccountDto);
|
|
|
+ account.setSecret(DigestUtil.hex(appAccountDto.getSecret()));
|
|
|
+ return R.data(accountService.updateById(account));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证验证码
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Account VerifyCode(AppAccountDto appAccountDto) {
|
|
|
+ Account account = accountService.getOne(new QueryWrapper<Account>().lambda()
|
|
|
+ .eq(Account::getPhone, appAccountDto.getPhone())
|
|
|
+ .eq(Account::getType, AppConstant.PLATFORM.SHOP.name()));
|
|
|
+ Assert.notNull(account, () -> {
|
|
|
+ throw new ServiceException(ResCode.USER_NOT_FOUNT);
|
|
|
+ });
|
|
|
+ Assert.isTrue(SmsUtil.validateMessage(null, appAccountDto.getSmsId(), appAccountDto.getValue(), appAccountDto.getPhone()),
|
|
|
+ () -> {
|
|
|
+ throw new ServiceException(ResCode.VALIDATE_FAIL);
|
|
|
+ });
|
|
|
+ return account;
|
|
|
+ }
|
|
|
|
|
|
}
|