mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-01-10 11:48:14 +08:00
手机号重复注册验证
This commit is contained in:
parent
a02d930f11
commit
7dcb922041
@ -11,7 +11,7 @@
|
||||
Target Server Version : 50726
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 02/03/2022 10:30:12
|
||||
Date: 02/03/2022 11:35:11
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
@ -29,13 +29,15 @@ CREATE TABLE `user_info` (
|
||||
`telephone` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`register_mode` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '通过手机号注册,通过微信注册,通过支付宝注册',
|
||||
`third_party_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `telephone_unique_index`(`telephone`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of user_info
|
||||
-- ----------------------------
|
||||
INSERT INTO `user_info` VALUES (1, 'admin', 2, 18, '110', 'phone', '');
|
||||
INSERT INTO `user_info` VALUES (2, 'user-1wk6xq-59489', 1, 49, '18900000001', 'phone', '');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for user_password
|
||||
@ -48,11 +50,12 @@ CREATE TABLE `user_password` (
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `user_id`(`user_id`) USING BTREE,
|
||||
CONSTRAINT `user_password_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of user_password
|
||||
-- ----------------------------
|
||||
INSERT INTO `user_password` VALUES (1, '21232f297a57a5a743894a0e4a801fc3', 1);
|
||||
INSERT INTO `user_password` VALUES (2, 'bnW2mQTNe40qWH3b5atFWw==', 2);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
@ -11,6 +11,7 @@ import com.cxyxiaomo.flashsale.service.model.UserModel;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -50,7 +51,11 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
// 实现 model -> dataobject 方法
|
||||
UserDO userDO = convertFormModel(userModel);
|
||||
userDOMapper.insertSelective(userDO);
|
||||
try {
|
||||
userDOMapper.insertSelective(userDO);
|
||||
} catch (DuplicateKeyException ex) {
|
||||
throw new BusinessException(EmBusinessError.PARAMETER_VALIDATION_ERROR, "手机号已被注册");
|
||||
}
|
||||
|
||||
userModel.setId(userDO.getId());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user