Quellcode durchsuchen

fix 手机号唯一

zoujiajian vor 3 Jahren
Ursprung
Commit
1fc3a74a5e

+ 10 - 0
netflix-web/src/main/java/com/cyksj/web/controller/market/TaskFrontController.java

@@ -81,6 +81,11 @@ public class TaskFrontController {
 	@NoSubmit
 	public Result<String> bindPhone(@RequestBody LoginPhoneReq phoneReq) {
 		Long userId = StpUserUtil.getLoginIdAsLong();
+		UserBindPhone other = userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
+				.eq(UserBindPhone::getPhone, phoneReq.getPhone()).ne(UserBindPhone::getUserId, userId).select(UserBindPhone::getId).last("limit 1"));
+		if (other != null) {
+			throw BusinessRuntimeException.getInstance("该手机号已被绑定");
+		}
 		UserBindPhone bindPhone = userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
 				.eq(UserBindPhone::getUserId, userId).last("limit 1"));
 		if (bindPhone != null) {
@@ -114,6 +119,11 @@ public class TaskFrontController {
 		if (bindPhone == null) {
 			throw BusinessRuntimeException.getInstance("您未绑定手机号");
 		}
+		UserBindPhone other = userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
+				.eq(UserBindPhone::getPhone, phoneReq.getPhone()).ne(UserBindPhone::getUserId, userId).select(UserBindPhone::getId).last("limit 1"));
+		if (other != null) {
+			throw BusinessRuntimeException.getInstance("该手机号已被绑定");
+		}
 		phoneCodeService.checkPhone(phoneReq.getPhone(), phoneReq.getCode());
 		bindPhone.setPhone(phoneReq.getPhone());
 		userBindPhoneMapper.updateById(bindPhone);