| | |
| | | package com.xcong.excoin.modules.coin.service.impl;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.math.RoundingMode;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.*;
|
| | |
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.xcong.excoin.common.contants.AppContants;
|
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum;
|
| | | import com.xcong.excoin.modules.blackchain.service.DateUtil;
|
| | | import com.xcong.excoin.modules.blackchain.service.RocService;
|
| | | import com.xcong.excoin.modules.coin.mapper.OrderCoinsDealMapper;
|
| | | import com.xcong.excoin.modules.coin.service.CoinService;
|
| | |
| | |
|
| | | @Resource
|
| | | private CoinService coinService;
|
| | |
|
| | | private static BigDecimal PERSENT = new BigDecimal("100");
|
| | |
|
| | | /**
|
| | | * 每日卖出限制 日期 20201128 会员ID
|
| | | */
|
| | | String LIMIT_SELL_PERSENT_KEY ="SELL:PERSENT:%s:%s";
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | return Result.fail("");
|
| | | }
|
| | | // 不能超过800个
|
| | |
|
| | | // if (amount != null && amount.compareTo(new BigDecimal("800")) > 0) {
|
| | | // return Result.fail("买入额度受限");
|
| | | // }
|
| | | // BigDecimal bigDecimal = orderCoinDealDao.sumTodayBuyAmount(memberId, symbol);
|
| | | // if (bigDecimal == null) {
|
| | | // bigDecimal = BigDecimal.ZERO;
|
| | | // }
|
| | | // amount = amount == null ? BigDecimal.ZERO : amount;
|
| | | // bigDecimal = bigDecimal.add(amount);
|
| | | // if (bigDecimal != null && bigDecimal.compareTo(new BigDecimal("800")) > 0) {
|
| | | // return Result.fail("买入额度受限");
|
| | | // }
|
| | | // // 挂单不能超过800
|
| | | // BigDecimal bigDecimal1 = orderCoinDealDao.sumTodayEntrustCntBuyAmount(memberId, symbol);
|
| | | // if (bigDecimal1 == null) {
|
| | | // bigDecimal1 = BigDecimal.ZERO;
|
| | | // }
|
| | | // bigDecimal1 = bigDecimal1.add(amount);
|
| | | // if (bigDecimal1 != null && bigDecimal1.compareTo(new BigDecimal("800")) > 0) {
|
| | | // return Result.fail("买入额度受限");
|
| | | // }
|
| | | } else {
|
| | | // 判断redis开关
|
| | | //String string = redisUtils.getString("SELL_LIMIT_KEY");
|
| | |
| | | if (StringUtils.isNotBlank(string) && StringUtils.isNotBlank(memberEntity.getEmail()) && string.contains(memberEntity.getEmail())) {
|
| | | return Result.fail("");
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | BigDecimal availableBalance = walletCoin.getAvailableBalance();
|
| | | if (amount.compareTo(availableBalance) > 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("order_service_0010"));
|
| | | }
|
| | | // 控制这个用户每日的挂卖额度 TODO
|
| | | // 每天3% 第一次的为基数
|
| | | BigDecimal spread = memberEntity.getSpread();
|
| | | if(spread!=null && spread.compareTo(BigDecimal.ZERO)>0 && spread.compareTo(PERSENT)<0){
|
| | | // 获取当日的额度
|
| | | String yyyyMMdd = DateUtil.dateToString(new Date(), "yyyyMMdd");
|
| | | String persentKey = String.format(LIMIT_SELL_PERSENT_KEY,yyyyMMdd,memberId.toString());
|
| | | BigDecimal aviSell =BigDecimal.ZERO;
|
| | | if(StringUtils.isBlank(persentKey)){
|
| | | // 当日可以卖的数量
|
| | | aviSell = spread.divide(PERSENT,4, RoundingMode.HALF_UP).multiply(availableBalance);
|
| | | }
|
| | | if(aviSell.compareTo(amount)<0){
|
| | | return Result.fail("卖出超过上限"+spread+"%");
|
| | | }
|
| | | aviSell = aviSell.subtract(amount);
|
| | | // 设置
|
| | | redisUtils.set(persentKey,aviSell.toPlainString());
|
| | | //redisUtils.getString()
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | return Result.ok(MessageSourceUtils.getString("order_service_0013"));
|
| | | }
|
| | | } else {
|
| | |
|
| | | //如果是限价卖出,撤单将对应的钱包冻结金额返回
|
| | | MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
|
| | | if (ObjectUtil.isNotEmpty(walletCoin)) {
|
| | | // 卖出按卖出的数量计算手续费
|
| | | BigDecimal returnBalance = orderCoinsEntity.getEntrustCnt().subtract(coinsEntityCancel.getDealCnt());
|
| | | // 取消订单 则退回额度
|
| | | String yyyyMMdd = DateUtil.dateToString(new Date(), "yyyyMMdd");
|
| | | String persentKey = String.format(LIMIT_SELL_PERSENT_KEY,yyyyMMdd,memberId.toString());
|
| | | String aviSell = redisUtils.getString(persentKey);
|
| | | // TODO
|
| | | if(StringUtils.isNotBlank(aviSell)){
|
| | | BigDecimal needSub = new BigDecimal(aviSell).add(returnBalance);
|
| | | redisUtils.set(persentKey,needSub.toPlainString());
|
| | | }
|
| | | walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance));
|
| | | walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance));
|
| | | //memberWalletCoinDao.updateById(walletCoin);
|