|
|
@@ -1,5 +1,6 @@
|
|
|
package org.springblade.gateway.shop_gateway.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
@@ -8,13 +9,17 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.springblade.common.enums.ResCode;
|
|
|
+import org.springblade.common.enums.ShopEnum;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.core.tool.utils.DigestUtil;
|
|
|
import org.springblade.gateway.shop_gateway.entity.dto.AppAccountDto;
|
|
|
import org.springblade.ldt.account.entity.Account;
|
|
|
import org.springblade.ldt.account.service.IAccountService;
|
|
|
+import org.springblade.ldt.shop.entity.Shop;
|
|
|
+import org.springblade.ldt.shop.service.IShopService;
|
|
|
import org.springblade.modules.resource.utils.SmsUtil;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
@@ -23,7 +28,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author cy-computer
|
|
|
@@ -35,35 +42,42 @@ import java.util.Objects;
|
|
|
public class AppAccountController {
|
|
|
|
|
|
private IAccountService accountService;
|
|
|
+ private IShopService shopService;
|
|
|
|
|
|
@PostMapping("login")
|
|
|
- @ApiOperation(value = "商户商场登录")
|
|
|
+ @ApiOperation(value = "商户登录")
|
|
|
@SneakyThrows
|
|
|
- public R login(@RequestBody @Valid Account account) throws ServiceException {
|
|
|
-
|
|
|
+ public R login(@RequestBody @Valid Account account) throws ServiceException {
|
|
|
Account user = accountService.getOne(new QueryWrapper<Account>().lambda().eq(Account::getPhone, account.getPhone()));
|
|
|
- Assert.notNull(user,() ->{throw new ServiceException(ResCode.USER_NOT_FOUNT);});
|
|
|
- Assert.isTrue(Objects.equals(user.getSecret(), DigestUtil.hex(account.getSecret())),() -> {
|
|
|
+ Assert.notNull(user, () -> {
|
|
|
+ throw new ServiceException(ResCode.USER_NOT_FOUNT);
|
|
|
+ });
|
|
|
+ Assert.isTrue(Objects.equals(user.getSecret(), DigestUtil.hex(account.getSecret())), () -> {
|
|
|
throw new ServiceException(ResCode.USER_PWS_ERROR);
|
|
|
});
|
|
|
- return R.data(user);
|
|
|
+ List<Shop> list = shopService.list(Condition.getQueryWrapper(new Shop()).lambda().eq(Shop::getPersonTel, account.getPhone()));
|
|
|
+ return R.data(list);
|
|
|
}
|
|
|
|
|
|
@PostMapping("register")
|
|
|
@ApiOperation(value = "注册账号")
|
|
|
@SneakyThrows
|
|
|
- public R register(@RequestBody @Valid AppAccountDto appAccountDto) {
|
|
|
+ public R register(@RequestBody @Valid AppAccountDto appAccountDto) {
|
|
|
+ Account isExit = accountService.getOne(Condition.getQueryWrapper(new Account()).lambda().eq(Account::getPhone, appAccountDto.getPhone()));
|
|
|
+ Assert.isNull(isExit, "该手机号已注册");
|
|
|
|
|
|
- Assert.isTrue(SmsUtil.validateMessage(null,appAccountDto.getSmsId(),appAccountDto.getValue(),appAccountDto.getPhone()),
|
|
|
- ()->{ throw new ServiceException(ResCode.VALIDATE_FAIL); });
|
|
|
+ Assert.isTrue(SmsUtil.validateMessage(null, appAccountDto.getSmsId(), appAccountDto.getValue(), appAccountDto.getPhone()),
|
|
|
+ () -> {
|
|
|
+ throw new ServiceException(ResCode.VALIDATE_FAIL);
|
|
|
+ });
|
|
|
Account account = new Account();
|
|
|
- BeanUtil.copyProperties(appAccountDto,account);
|
|
|
+ BeanUtil.copyProperties(appAccountDto, account);
|
|
|
account.setSecret(DigestUtil.hex(account.getSecret()));
|
|
|
- Assert.isTrue(accountService.saveOrUpdate(account),()->{
|
|
|
+ Assert.isTrue(accountService.saveOrUpdate(account), () -> {
|
|
|
throw new ServiceException(ResCode.SHOP_REGISTER_ERROR);
|
|
|
});
|
|
|
return R.data(account);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|