1
zyy
4 days ago d3f9065046909468ef0089a48bb927fba645ddb3
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) {
@@ -975,6 +978,8 @@
                if (!party_reco.isEnabled()) {
                    throw new YamiShopBindException("推荐人无权限推荐");
                }
            } else {
                throw new YamiShopBindException("请填写推荐码");
            }
        }
//        if ("true".equals(this.sysparaService.find("register_need_usercode_turn").getSvalue())) {
@@ -1673,6 +1678,7 @@
        user.setUserLastip(user.getUserRegip());
        user.setUserCode(getUserCode());
        user.setCreateTime(now);
        user.setAccountType(0); // 主账户
        save(user);
        //1.保存钱包记录
@@ -1795,6 +1801,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 +2026,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("登录失败");