Helius
2021-05-26 f5d87a5a585adcbb148dee6c62ff6e18c4e7334c
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcEntrustOrderServiceImpl.java
@@ -16,10 +16,12 @@
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberPaymentMethodEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.modules.otc.dao.OtcBlackListDao;
import com.xcong.excoin.modules.otc.dao.OtcMarketBussinessDao;
import com.xcong.excoin.modules.otc.dao.OtcOrderDao;
import com.xcong.excoin.modules.otc.dto.EntrustOrderAddDto;
import com.xcong.excoin.modules.otc.dto.EntrustOrderListDto;
import com.xcong.excoin.modules.otc.entity.OtcBlackList;
import com.xcong.excoin.modules.otc.entity.OtcEntrustOrder;
import com.xcong.excoin.modules.otc.dao.OtcEntrustOrderDao;
import com.xcong.excoin.modules.otc.entity.OtcMarketBussiness;
@@ -46,6 +48,7 @@
    private final MemberWalletCoinDao memberWalletCoinDao;
    private final OtcOrderDao otcOrderDao;
    private final CommonService commonService;
    private final OtcBlackListDao otcBlackListDao;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -66,26 +69,23 @@
        BigDecimal totalAmount = addDto.getUnitPrice().multiply(addDto.getAmount());
        otcEntrustOrder.setTotalAmount(totalAmount);
        if (addDto.getMax().compareTo(totalAmount) < 0) {
            throw new GlobalException("最大限额应小于总金额");
        }
        if (OtcEntrustOrder.ORDER_TYPE_S.equals(addDto.getType())) {
            MemberWalletCoinEntity coinWallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(), "USDT");
            if(coinWallet.getAvailableBalance().compareTo(totalAmount) < 0) {
            BigDecimal multiply = addDto.getUnitPrice().multiply(coinWallet.getAvailableBalance());
            if(multiply.compareTo(totalAmount) < 0) {
                throw new GlobalException("可用金额不足");
            }
            memberWalletCoinDao.updateFrozenBalance(member.getId(), coinWallet.getId(), addDto.getAmount());
        }
        OtcMarketBussiness mb = otcMarketBussinessDao.selectMarketBussinessByMemberId(member.getId());
        if (mb == null) {
            OtcMarketBussiness otcMb = new OtcMarketBussiness();
            otcMb.setMemberId(member.getId());
            otcMb.setAvgCoinTime(0);
            otcMb.setAvgPayTime(0);
            otcMb.setTotalOrderCnt(0);
            otcMb.setBuyCnt(0);
            otcMb.setFinishRatio(BigDecimal.ZERO);
            otcMb.setStatus(OtcMarketBussiness.CHECK_PASS);
            otcMarketBussinessDao.insert(otcMb);
        if (!MemberEntity.IS_TRADER_Y.equals(member.getIsTrader())) {
            throw new GlobalException("不是市商");
        }
        if (member.getIsTrader() == 2) {
@@ -150,7 +150,12 @@
    @Override
    public IPage<EntrustListVo> findEntrustListInPage(EntrustOrderListDto dto) {
        MemberEntity member = LoginUserUtils.getAppLoginUser();
        Page<EntrustListVo> page = new Page<>(dto.getPageNum(), dto.getPageSize());
//        List<OtcBlackList> blackLists = otcBlackListDao.selectBlackListByMemberId(member.getId());
//        if (CollUtil.isNotEmpty(blackLists)) {
            dto.setMemberId(member.getId());
//        }
        return this.baseMapper.selectEntrustListInPage(dto, page);
    }
@@ -203,12 +208,14 @@
            return Result.fail("参数错误");
        }
        MemberPaymentMethodEntity defualtMethod = memberPaymentMethodDao.selectDefualtMethod(otcEntrustOrder.getMemberId(), null, "1");
        MemberEntity member = memberDao.selectById(otcEntrustOrder.getMemberId());
        OtcMarketBussiness mb = otcMarketBussinessDao.selectMarketBussinessByMemberId(member.getId());
        EntrustOrderDetailVo detail = OtcEntrustOrderMapper.INSTANCE.entityToOrderDetail(otcEntrustOrder);
        detail.setName(member.getName());
        detail.setOrderCnt(mb.getBuyCnt());
        detail.setFinishRatio(mb.getFinishRatio());
        detail.setPayType(defualtMethod.getPaymentType());
        return Result.ok(detail);
    }
}