新版仿ok交易所-后端
1
zj
2025-10-14 7ff2bf07924915fc12612c9fd8cae5915dca2560
1
13 files modified
153 ■■■■■ changed files
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiUserController.java 23 ●●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWalletController.java 8 ●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWithdrawController.java 11 ●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiExchangeApplyOrderController.java 19 ●●●●● patch | view | raw | blame | history
trading-order-admin/src/main/resources/application-prod.yml 6 ●●●● patch | view | raw | blame | history
trading-order-bean/src/main/java/com/yami/trading/bean/user/dto/UserDto.java 6 ●●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/contract/ContractApplyOrderService.java 10 ●●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/exchange/impl/ExchangeApplyOrderServiceImpl.java 14 ●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/impl/RechargeBlockchainOrderServiceImpl.java 9 ●●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/impl/UserServiceImpl.java 3 ●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/impl/WithdrawServiceImpl.java 26 ●●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/user/UserService.java 2 ●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/user/impl/UserStatisticsServiceImpl.java 16 ●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiUserController.java
@@ -140,14 +140,17 @@
        return Result.succeed(data);
    }
    private String validateParam(String username, String verifcode, String password, String type) {
    private String validateParam(String phone,String username, String verifcode, String password,String usercode, String type) {
        if (StringUtils.isEmptyString(username)) {
            return "用户名不能为空";
        }
//        if (StringUtils.isEmptyString(verifcode)) {
//            return "验证码不能为空";
//        }
        if (StringUtils.isEmptyString(phone)) {
            return "手机号不能为空";
        }
        if (StringUtils.isEmptyString(verifcode)) {
            return "验证码不能为空";
        }
        if (StringUtils.isEmptyString(password)) {
            return "登录密码不能为空";
        }
@@ -160,9 +163,9 @@
//            // 只能输入数字
//            return "登陆密码不符合设定";
//        }
//        if (StringUtils.isEmptyString(this.usercode)) {
//            return "推荐码不能为空";
//        }
        if (StringUtils.isEmptyString(usercode)) {
            return "推荐码不能为空";
        }
        if (StringUtils.isEmptyString(type) || !Arrays.asList("1", "2").contains(type)) {
            return "类型不能为空";
        }
@@ -173,9 +176,9 @@
     * 手机/邮箱注册接口
     */
    @RequestMapping("register")
    public Object register(String username, String password, String safeword, String verifcode, String usercode, String type) {
    public Object register(String username, String password, String phone,String safeword, String verifcode, String usercode, String type) {
        // 注册类型:1/手机;2/邮箱;
        String error = this.validateParam(username, verifcode, password, type);
        String error = this.validateParam(phone,username, verifcode, password, usercode,type);
        if (!StringUtils.isNullOrEmpty(error)) {
            throw new YamiShopBindException(error);
        }
@@ -185,7 +188,7 @@
        if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
            throw new YamiShopBindException("资金密码不符合设定");
        }
        userService.saveRegister(username, password, usercode, safeword, verifcode, type);
        userService.saveRegister(username, password,phone, usercode, safeword, verifcode, type);
        User secUser = userService.findByUserName(username);
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_SECURITY);
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWalletController.java
@@ -215,13 +215,13 @@
        df2.setRoundingMode(RoundingMode.FLOOR);
        // String partyId ="dcc0dd35a49c383dadabc4dc030afe70";
        String partyId = SecurityUtils.getCurrentUserId();
        CapitaltWallet usdt = null;
        Wallet usdt = null;
        if (StringUtils.isNotEmpty(partyId)) {
//            usdt = this.walletService.saveWalletByPartyId(partyId);
            usdt = capitaltWalletService.getUserIdWallet(partyId);
            usdt = this.walletService.saveWalletByPartyId(partyId);
//            usdt = capitaltWalletService.getUserIdWallet(partyId);
        }
        if (null == usdt) {
            usdt = new CapitaltWallet();
            usdt = new Wallet();
            usdt.setMoney(new BigDecimal(0));
            usdt.setLockMoney(new BigDecimal(0));
            usdt.setFreezeMoney(new BigDecimal(0));
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWithdrawController.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.trading.bean.model.CapitaltWallet;
import com.yami.trading.bean.model.Wallet;
import com.yami.trading.bean.model.Withdraw;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.domain.Result;
@@ -12,6 +13,7 @@
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.service.CapitaltWalletService;
import com.yami.trading.service.SessionTokenService;
import com.yami.trading.service.WalletService;
import com.yami.trading.service.WithdrawService;
import com.yami.trading.service.syspara.SysparaService;
import com.yami.trading.service.user.UserService;
@@ -49,7 +51,8 @@
    protected WalletLogService walletLogService;
    @Autowired
    CapitaltWalletService capitaltWalletService;
    @Autowired
    WalletService walletService;
    /**
     * 首次进入页面,传递session_token
     */
@@ -106,8 +109,10 @@
        // 获取资金账户(capital)
        if(channel.contains("USDT")){
            CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
                    .eq(CapitaltWallet::getUserId, partyId).last(" limit 1 "));
            Wallet capitaltWallet = walletService.getOne(new LambdaQueryWrapper<>(Wallet.class)
                    .eq(Wallet::getUserId, partyId).last(" limit 1 "));
//            CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
//                    .eq(CapitaltWallet::getUserId, partyId).last(" limit 1 "));
            if(capitaltWallet.getMoney().compareTo(new BigDecimal(amount)) < 0){
                throw new YamiShopBindException("Insufficient available balance for withdrawal!");
            }
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiExchangeApplyOrderController.java
@@ -109,12 +109,14 @@
        Map<String, Object> parities = parities(symbol, symbol_to, volume_temp);
        Object getVolume = parities.get("get_volume");
        if(symbol.equals("usdt")){
            CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId);
            Wallet userIdWallet = walletService.getOne(new LambdaQueryWrapper<>(Wallet.class)
                    .eq(Wallet::getUserId, partyId).last(" limit 1 "));
//            CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId);
            if(userIdWallet.getMoney().compareTo(new BigDecimal(volume_temp)) < 0){
                throw new YamiShopBindException("not sufficient funds");
            }
            Double value = Double.valueOf(volume_temp);
            capitaltWalletService.update(userIdWallet,  -value);
            walletService.update(userIdWallet.getUserId(),  -value);
            WalletExtend walletExtend = walletExtendService.getOne(new LambdaQueryWrapper<>(WalletExtend.class)
                    .eq(WalletExtend::getWallettype, symbol_to)
@@ -146,9 +148,12 @@
            walletExtend.setAmount(walletExtend.getAmount() - valueOf);
            walletExtendService.update(walletExtend,new LambdaUpdateWrapper<WalletExtend>().eq(UUIDEntity::getUuid,walletExtend.getUuid()));
            CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId);
            capitaltWalletService.update(userIdWallet,Double.valueOf(getVolume.toString()));
//
//            CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId);
//            capitaltWalletService.update(userIdWallet,Double.valueOf(getVolume.toString()));
            Wallet userIdWallet = walletService.getOne(new LambdaQueryWrapper<>(Wallet.class)
                    .eq(Wallet::getUserId, partyId).last(" limit 1 "));
            walletService.update(partyId,Double.valueOf(getVolume.toString()));
        }else{
            WalletExtend walletExtend = walletExtendService.getOne(new LambdaQueryWrapper<>(WalletExtend.class)
                    .eq(WalletExtend::getWallettype, symbol)
@@ -374,8 +379,8 @@
    public Result openview() {
        Map<String, Object> data = new HashMap<String, Object>();
        String partyId = SecurityUtils.getUser().getUserId();
//        Wallet wallet = walletService.saveWalletByPartyId(partyId);
        CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId);
        Wallet userIdWallet = walletService.saveWalletByPartyId(partyId);
//        CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId);
        // 账户剩余资金
        DecimalFormat df = new DecimalFormat("#.##");
        df.setRoundingMode(RoundingMode.FLOOR);// 向下取整
trading-order-admin/src/main/resources/application-prod.yml
@@ -3,7 +3,7 @@
spring:
  datasource:
#    url: jdbc:mysql://127.0.0.1:6306/8.4?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&serverTimezone=Europe/Paris&useLegacyDatetimeCode=false
    url: jdbc:mysql://127.0.0.1:6306/trading_order?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&serverTimezone=Europe/Paris&useLegacyDatetimeCode=false
    url: jdbc:mysql://127.0.0.1:6306/trading_order?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=America/Mexico_City&nullCatalogMeansCurrent=true
    username: root
    password: Err;2[eoGFUriwdgr
    driver-class-name: com.mysql.cj.jdbc.Driver
@@ -18,9 +18,9 @@
    properties:
      hibernate:
        jdbc:
          time_zone: Europe/Paris
          time_zone: America/Mexico_City
  jackson:
    time-zone: Europe/Paris
    time-zone: America/Mexico_City
    cache:
      type: redis
      redis:
trading-order-bean/src/main/java/com/yami/trading/bean/user/dto/UserDto.java
@@ -22,6 +22,12 @@
     */
    @ApiModelProperty("userCode")
    private  String userCode;
    /**
     * 手机号码
     */
    private String userMobile;
    /**
     * USDT账户余额
     */
trading-order-service/src/main/java/com/yami/trading/service/contract/ContractApplyOrderService.java
@@ -222,6 +222,16 @@
            /**
             * 加上杠杆
             */
            //25x手续费3.75%  50x手续费7.5%  100x手续费15% 200x手续费30%
            if(order.getLeverRate().doubleValue() == 25){
                item.setUnitFee(new BigDecimal("0.0375"));
            }else if(order.getLeverRate().doubleValue() == 50){
                item.setUnitFee(new BigDecimal("0.075"));
            }else if(order.getLeverRate().doubleValue() == 100){
                item.setUnitFee(new BigDecimal("0.15"));
            }else if(order.getLeverRate().doubleValue() == 200){
                item.setUnitFee(new BigDecimal("0.30"));
            }
            BigDecimal fee = order.getDeposit().multiply(order.getLeverRate()).multiply(item.getUnitFee());
            fee = fee.setScale(4, RoundingMode.DOWN);  // 保留两位小数
trading-order-service/src/main/java/com/yami/trading/service/exchange/impl/ExchangeApplyOrderServiceImpl.java
@@ -111,11 +111,11 @@
        double amount = Arith.mul(sub, realtime.getClose().doubleValue());
        order.setCloseTime(new Date());
        order.setClosePrice(realtime.getClose().doubleValue());
//        Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
        CapitaltWallet capitaltWallet = capitaltWalletService.getUserIdWallet(order.getPartyId());
        Wallet capitaltWallet = this.walletService.saveWalletByPartyId(order.getPartyId());
//        CapitaltWallet capitaltWallet = capitaltWalletService.getUserIdWallet(order.getPartyId());
        double amount_before = capitaltWallet.getMoney().doubleValue();
//        this.walletService.update(userIdWallet.getUserId().toString(), amount);
        this.capitaltWalletService.update(capitaltWallet, amount);
        this.walletService.update(capitaltWallet.getUserId(), amount);
        /*
         * 保存资金日志
@@ -615,8 +615,8 @@
        // 可以买的数量
        double amount = Arith.div(sub, order.getClosePrice(), 8);
        order.setSymbolValue(amount);
//        Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
        CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(order.getPartyId());
        Wallet userIdWallet = this.walletService.saveWalletByPartyId(order.getPartyId());
//        CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(order.getPartyId());
        double amount_before = userIdWallet.getMoney().doubleValue();
        // 如果是计划委托,则先不扣钱
        if (order.isTriggerOrder()) {
@@ -643,8 +643,8 @@
            if (userIdWallet.getMoney().doubleValue() < order.getVolume().doubleValue()) {
                throw new YamiShopBindException("余额不足");
            }
//            this.walletService.update(userIdWallet.getUserId().toString(), Arith.sub(0, order.getVolume()));
            capitaltWalletService.update(userIdWallet, Arith.sub(0, order.getVolume()));
            this.walletService.update(userIdWallet.getUserId().toString(), Arith.sub(0, order.getVolume()));
//            capitaltWalletService.update(userIdWallet, Arith.sub(0, order.getVolume()));
            /*
             * 保存资金日志
             */
trading-order-service/src/main/java/com/yami/trading/service/impl/RechargeBlockchainOrderServiceImpl.java
@@ -134,11 +134,12 @@
//            double amount_before = wallet.getMoney().doubleValue();
//
//            walletService.update(wallet.getUserId(), amount1);
            CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
                    .eq(CapitaltWallet::getUserId, recharge.getPartyId()).last(" limit 1 "));
            Wallet capitaltWallet = walletService.getOne(new LambdaQueryWrapper<>(Wallet.class)
                    .eq(Wallet::getUserId, recharge.getPartyId()).last(" limit 1 "));
//            CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
//                    .eq(CapitaltWallet::getUserId, recharge.getPartyId()).last(" limit 1 "));
            double amount_before = capitaltWallet.getMoney().doubleValue();
            capitaltWalletService.update(capitaltWallet,amount1);
            walletService.update(capitaltWallet.getUserId(),amount1);
            // 保存资金日志
            MoneyLog moneyLog = new MoneyLog();
trading-order-service/src/main/java/com/yami/trading/service/impl/UserServiceImpl.java
@@ -638,7 +638,7 @@
    }
    @Override
    public void saveRegister(String username, String password, String usercode, String safeword, String verifcode, String type) {
    public void saveRegister(String username, String password,String phone, String usercode, String safeword, String verifcode, String type) {
        username = username.trim();
        password = password.trim();
        if (!"null".equals(safeword) && !StringUtils.isEmptyString(safeword)) {
@@ -686,6 +686,7 @@
        party.setUserLevel(userLevel);
        party.setSafePassword(this.passwordEncoder.encode(safeword));
        party.setRoleName(Constants.SECURITY_ROLE_MEMBER);
        party.setUserMobile(phone);
        save(party);
//        if (reg.getUsername().indexOf("@") == -1) {
        if (type.equals("1")) {
trading-order-service/src/main/java/com/yami/trading/service/impl/WithdrawServiceImpl.java
@@ -151,14 +151,16 @@
//            walletService.update(wallet.getUserId().toString(),
//                    Arith.add(withdraw.getAmount(), withdraw.getAmountFee()));
            CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
                    .eq(CapitaltWallet::getUserId, wallet.getUserId().toString()).last(" limit 1 "));
//            CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
//                    .eq(CapitaltWallet::getUserId, wallet.getUserId().toString()).last(" limit 1 "));
            Wallet capitaltWallet = walletService.getOne(new LambdaQueryWrapper<>(Wallet.class)
                    .eq(Wallet::getUserId, wallet.getUserId().toString()).last(" limit 1 "));
            if(ObjectUtil.isEmpty(capitaltWallet)){
                throw new YamiShopBindException("用户资金账户不存在!");
            }
            capitaltWalletService.update(new LambdaUpdateWrapper<CapitaltWallet>()
                    .set(CapitaltWallet::getMoney,new BigDecimal(Arith.add(capitaltWallet.getMoney(), withdraw.getVolume())))
                    .eq(CapitaltWallet::getUserId,wallet.getUserId()));
            walletService.update(new LambdaUpdateWrapper<Wallet>()
                    .set(Wallet::getMoney,new BigDecimal(Arith.add(capitaltWallet.getMoney(), withdraw.getVolume())))
                    .eq(Wallet::getUserId,wallet.getUserId()));
            /*
@@ -482,10 +484,10 @@
            throw new YamiShopBindException("Your account has been frozen");
        }
//        Wallet wallet = walletService.saveWalletByPartyId(withdraw.getUserId());
        CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
                .eq(CapitaltWallet::getUserId, withdraw.getUserId()).last(" limit 1 "));
        Wallet capitaltWallet = walletService.saveWalletByPartyId(withdraw.getUserId());
//
//        CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
//                .eq(CapitaltWallet::getUserId, withdraw.getUserId()).last(" limit 1 "));
        if (capitaltWallet.getMoney().doubleValue() < withdraw.getVolume().doubleValue()) {
            throw new YamiShopBindException("not sufficient funds");
        }
@@ -649,6 +651,8 @@
                }
            }
        }
        //固定手续费10u
        fee = 10;
        withdraw.setAmountFee(new BigDecimal(fee));
        withdraw.setAmount(new BigDecimal(Arith.sub(withdraw.getVolume().doubleValue(), fee)));
        if (channel.indexOf("USDT") != -1) {
@@ -681,7 +685,9 @@
        if(ObjectUtil.isEmpty(capitaltWallet)){
            throw new YamiShopBindException("The user's funds account does not exist!");
        }
        capitaltWalletService.update(capitaltWallet,-withdraw.getVolume().doubleValue());
//        walletService.update(capitaltWallet,-withdraw.getVolume().doubleValue());
        walletService.update(capitaltWallet.getUserId(),-withdraw.getVolume().doubleValue());
        save(withdraw);
trading-order-service/src/main/java/com/yami/trading/service/user/UserService.java
@@ -131,7 +131,7 @@
     */
    public User findPartyByVerifiedEmail(String email);
    void saveRegister(String username, String password, String usercode, String safeword, String verifcode, String type);
    void saveRegister(String username, String password,String phone, String usercode, String safeword, String verifcode, String type);
    void logout(String userId);
trading-order-service/src/main/java/com/yami/trading/service/user/impl/UserStatisticsServiceImpl.java
@@ -117,14 +117,14 @@
        data.put("freeze_amount",null==wallet?0:wallet.getFreezeMoney().setScale(8, RoundingMode.FLOOR).toPlainString() );
        result.add(0,data);
        Map<String,Object> capitaldata = new HashMap<String,Object>();
        CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
                .eq(CapitaltWallet::getUserId, targetPartyId).last(" limit 1 "));
        capitaldata.put("capitalttype", "capitalusdt");
        capitaldata.put("amount",null==capitaltWallet?0:new BigDecimal(capitaltWallet.getMoney().doubleValue()).setScale(8, RoundingMode.FLOOR).toPlainString() );
        capitaldata.put("lock_amount",null==capitaltWallet?0:capitaltWallet.getLockMoney().setScale(8, RoundingMode.FLOOR).toPlainString() );
        capitaldata.put("freeze_amount",null==capitaltWallet?0:capitaltWallet.getFreezeMoney().setScale(8, RoundingMode.FLOOR).toPlainString() );
        result.add(0,capitaldata);
//        Map<String,Object> capitaldata = new HashMap<String,Object>();
//        CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
//                .eq(CapitaltWallet::getUserId, targetPartyId).last(" limit 1 "));
//        capitaldata.put("capitalttype", "capitalusdt");
//        capitaldata.put("amount",null==capitaltWallet?0:new BigDecimal(capitaltWallet.getMoney().doubleValue()).setScale(8, RoundingMode.FLOOR).toPlainString() );
//        capitaldata.put("lock_amount",null==capitaltWallet?0:capitaltWallet.getLockMoney().setScale(8, RoundingMode.FLOOR).toPlainString() );
//        capitaldata.put("freeze_amount",null==capitaltWallet?0:capitaltWallet.getFreezeMoney().setScale(8, RoundingMode.FLOOR).toPlainString() );
//        result.add(0,capitaldata);
        return result;
    }
}