From 60d1f642052ad8c7bd8a11f02f965b122bebf9a4 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Thu, 09 Apr 2026 18:43:37 +0800
Subject: [PATCH] 1

---
 trading-order-service/src/main/java/com/yami/trading/service/impl/UserServiceImpl.java |   92 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/trading-order-service/src/main/java/com/yami/trading/service/impl/UserServiceImpl.java b/trading-order-service/src/main/java/com/yami/trading/service/impl/UserServiceImpl.java
index 381dc73..fbadbe1 100644
--- a/trading-order-service/src/main/java/com/yami/trading/service/impl/UserServiceImpl.java
+++ b/trading-order-service/src/main/java/com/yami/trading/service/impl/UserServiceImpl.java
@@ -28,6 +28,7 @@
 import com.yami.trading.service.syspara.SysparaService;
 import com.yami.trading.service.system.LogService;
 import com.yami.trading.service.user.*;
+import com.yami.trading.bean.model.UserSimRelation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -88,6 +89,8 @@
     @Autowired(required = false)
     @Qualifier("dataService")
     private DataService dataService;
+    @Autowired
+    private UserSimRelationService userSimRelationService;
 
     @Override
     public boolean checkLoginSafeword(User user, String loginSafeword) {
@@ -959,11 +962,11 @@
         String key = username;
         String authcode = identifyingCodeTimeWindowService.getAuthCode(key);
         //log.info("---> UserServiceImpl.saveRegister 用户名:{} 注册,正确的验证码值为:{}, 输入的值为:{}", username, authcode, verifcode);
-        if(!"1618".equals(verifcode)){
-            if ( (authcode == null) || (!authcode.equals(verifcode))) {
-                throw new YamiShopBindException("验证码不正确");
-            }
-        }
+//        if(!"1618".equals(verifcode)){
+//            if ( (authcode == null) || (!authcode.equals(verifcode))) {
+//                throw new YamiShopBindException("验证码不正确");
+//            }
+//        }
         if ("true".equals(this.sysparaService.find("register_need_usercode").getSvalue())) {
             if (StringUtils.isNotEmpty(usercode)) {
                 if (null == party_reco) {
@@ -1008,6 +1011,7 @@
 //		if (reg.getUsername().indexOf("@") == -1) {
         if (type.equals("1")) {
             // 手机注册
+            rejectMainlandChinaPhoneRegister(username);
 //			if (StringUtils.isEmptyString(reg.getUsername()) || !Strings.isNumber(reg.getUsername()) || reg.getUsername().length() > 15) {
             if (StringUtils.isEmptyString(username) || username.length() > 20) {
                 throw new YamiShopBindException("请输入正确的手机号码");
@@ -1614,6 +1618,7 @@
         User user = null;
         // 手机
         if (type == 1) {
+            rejectMainlandChinaPhoneRegister(userName);
             if (!isValidPhone(userName)) {
                 throw new YamiShopBindException("手机号格式不正常");
             }
@@ -1673,6 +1678,7 @@
         user.setUserLastip(user.getUserRegip());
         user.setUserCode(getUserCode());
         user.setCreateTime(now);
+        user.setAccountType(0); // 主账户
         save(user);
 
         //1.保存钱包记录
@@ -1774,6 +1780,22 @@
         return user;
     }
 
+    /**
+     * 禁止大陆 +86 / 86 前缀手机号注册(与风控一致)
+     */
+    private void rejectMainlandChinaPhoneRegister(String phoneRaw) {
+        if (StringUtils.isEmptyString(phoneRaw)) {
+            return;
+        }
+        String phone = phoneRaw.trim();
+        if (phone.startsWith("+86")) {
+            throw new YamiShopBindException("不支持+86大陆手机号注册");
+        }
+        if (phone.matches("^86(1[3-9])\\d{9}$")) {
+            throw new YamiShopBindException("不支持86前缀大陆手机号注册");
+        }
+    }
+
     // 手机号校验
     private boolean isValidPhone(String username) {
         Pattern p = Pattern.compile("[0-9]*");
@@ -1795,6 +1817,62 @@
         Pattern p = Pattern.compile(regex);
         Matcher m = p.matcher(username);
         return m.matches();
+    }
+
+    /**
+     * 注册时创建模拟账户并与主账户关联,并给予模拟账户初始资金
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void createSimAccountAndRelation(User mainUser, String mainLoginPasswordEncoded, Date now) {
+        User simUser = new User();
+        simUser.setAccountType(1); // 模拟账户
+        simUser.setUserName("sim_" + mainUser.getUserId());
+        simUser.setLoginPassword(mainLoginPasswordEncoded);
+        simUser.setSafePassword(mainUser.getSafePassword());
+        simUser.setUserCode(getUserCode());
+        simUser.setStatus(1);
+        simUser.setRoleName(UserConstants.SECURITY_ROLE_MEMBER);
+        simUser.setCreateTime(now);
+        simUser.setUserRegip(mainUser.getUserRegip());
+        simUser.setUserLastip(mainUser.getUserLastip());
+        simUser.setWithdrawAuthority(false); // 模拟账户禁止提现
+        int ever_user_level_num = sysparaService.find("ever_user_level_num").getInteger();
+        int ever_user_level_num_custom = sysparaService.find("ever_user_level_num_custom").getInteger();
+        simUser.setUserLevel(ever_user_level_num_custom * 10 + ever_user_level_num);
+        save(simUser);
+
+        Wallet simWallet = new Wallet();
+        simWallet.setUserId(simUser.getUserId());
+        simWallet.setCreateTime(now);
+        walletService.save(simWallet);
+
+        UserSimRelation relation = new UserSimRelation();
+        relation.setMainUserId(mainUser.getUserId());
+        relation.setSimUserId(simUser.getUserId());
+        userSimRelationService.save(relation);
+
+        // 模拟账户初始资金(与虚拟注册赠送一致)
+        double giftSum = 100000;
+        Syspara virtualGift = sysparaService.find("virtual_register_gift_coin");
+        if (virtualGift != null) {
+            giftSum = virtualGift.getDouble();
+        }
+        userDataService.saveGiftMoneyHandle(simUser.getUserId(), giftSum);
+        walletService.update(simUser.getUserId(), giftSum);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void createSimAccountIfAbsent(String mainUserId) {
+        if (userSimRelationService.getSimUserId(mainUserId) != null) {
+            return;
+        }
+        User mainUser = getById(mainUserId);
+        if (mainUser == null || (mainUser.getAccountType() != null && mainUser.getAccountType() == 1)) {
+            throw new YamiShopBindException("主账户不存在或不能创建模拟账户");
+        }
+        Date now = new Date();
+        createSimAccountAndRelation(mainUser, mainUser.getLoginPassword(), now);
     }
 
     @Override
@@ -1964,6 +2042,10 @@
         if (user == null) {
             throw new YamiShopBindException("用户不存在");
         }
+        // 模拟账户不能直接登录,只能通过主账户登录后切换
+        if (user.getAccountType() != null && user.getAccountType() == 1) {
+            throw new YamiShopBindException("模拟账户不能直接登录,请使用主账户登录后切换");
+        }
         if (!user.isLoginAuthority()) {
             log.info("登录限制{}", user.isLoginAuthority());
             throw new YamiShopBindException("登录失败");

--
Gitblit v1.9.3