瀏覽代碼

Merge remote-tracking branch 'origin/master'

lianghanqiang 4 年之前
父節點
當前提交
593ec153fd

+ 19 - 0
src/main/java/org/springblade/common/enums/AppConstant.java

@@ -0,0 +1,19 @@
+package org.springblade.common.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author cy-computer
+ */
+public interface AppConstant {
+
+	@Getter
+	@AllArgsConstructor
+	enum PLATFORM{
+		MALL("MALL"),
+		SHOP("SHOP"),
+		;
+		String name;
+	}
+}

+ 46 - 2
src/main/java/org/springblade/gateway/shop_gateway/controller/AppAccountController.java

@@ -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;
+	}
 
 }

+ 12 - 3
src/main/java/org/springblade/gateway/shop_gateway/entity/dto/AppAccountDto.java

@@ -11,10 +11,17 @@ import javax.validation.constraints.NotBlank;
  */
 
 @Data
-@EqualsAndHashCode(callSuper = true)
-public class AppAccountDto extends Account {
-	private static final long serialVersionUID = 1L;
+public class AppAccountDto {
 
+	/**
+	 * 手机号
+	 */
+	@NotBlank
+	private String phone;
+	/**
+	 * 密码
+	 */
+	private String Secret;
 	/**
 	 * 验证码
 	 */
@@ -26,4 +33,6 @@ public class AppAccountDto extends Account {
 	 * */
 	@NotBlank
 	private String smsId;
+
+
 }

+ 2 - 2
src/main/java/org/springblade/ldt/account/entity/Account.java

@@ -53,9 +53,9 @@ public class Account implements Serializable {
 		@ApiModelProperty(value = "密码")
 		private String secret;
 	/**
-	* 账户类型,商家,商场
+	* 账户类型枚举,商家SHOP,商场MALL
 	*/
-		@ApiModelProperty(value = "账户类型,商家,商场")
+		@ApiModelProperty(value = "账户类型枚举,商家SHOP,商场MALL")
 		private String type;
 	/**
 	* 注册时间