From 8da201d092f8977d8407d2d49b248c28c45eee70 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 20 May 2021 17:53:47 +0800
Subject: [PATCH] modify

---
 src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java |   31 +++++++++++++++++++++++++++----
 1 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
index f0838ba..e9379dc 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
@@ -19,8 +19,8 @@
 import com.xcong.excoin.modules.otc.dao.OtcEntrustOrderDao;
 import com.xcong.excoin.modules.otc.dao.OtcMarketBussinessDao;
 import com.xcong.excoin.modules.otc.dto.HasPayDto;
-import com.xcong.excoin.modules.otc.dto.OrderAddDto;
 import com.xcong.excoin.modules.otc.dto.OrderListDto;
+import com.xcong.excoin.modules.otc.dto.OtcOrderAddDto;
 import com.xcong.excoin.modules.otc.entity.OtcEntrustOrder;
 import com.xcong.excoin.modules.otc.entity.OtcMarketBussiness;
 import com.xcong.excoin.modules.otc.entity.OtcOrder;
@@ -54,7 +54,7 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void buyOrder(OrderAddDto orderAddDto) {
+    public void buyOrder(OtcOrderAddDto orderAddDto) {
         MemberEntity member = LoginUserUtils.getAppLoginUser();
         OtcEntrustOrder entrustOrder = otcEntrustOrderDao.selectById(orderAddDto.getId());
         if (entrustOrder == null) {
@@ -69,8 +69,19 @@
             throw new GlobalException("无足够的USDT");
         }
 
+        if (orderAddDto.getUsdtAmount().compareTo(entrustOrder.getLimitMinAmount()) < 0) {
+            throw new GlobalException("低于最低限额");
+        }
+
+        if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getLimitMaxAmount()) > 0) {
+            throw new GlobalException("高于最高限额");
+        }
+
+        if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getRemainCoinAmount()) > 0) {
+            throw new GlobalException("剩余数量不足");
+        }
+
         BigDecimal cny = orderAddDto.getUsdtAmount().multiply(entrustOrder.getUnitPrice());
-        log.info("--->{}", cny);
         if (cny.compareTo(orderAddDto.getCnyAmount()) != 0) {
             throw new GlobalException("数量与金额不符");
         }
@@ -98,7 +109,7 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void saleOrder(OrderAddDto orderAddDto) {
+    public void saleOrder(OtcOrderAddDto orderAddDto) {
         MemberEntity member = LoginUserUtils.getAppLoginUser();
         OtcEntrustOrder entrustOrder = otcEntrustOrderDao.selectById(orderAddDto.getId());
         if (entrustOrder == null) {
@@ -109,6 +120,18 @@
             throw new GlobalException("无法出售");
         }
 
+        if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getLimitMinAmount()) < 0) {
+            throw new GlobalException("低于最低限额");
+        }
+
+        if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getLimitMaxAmount()) > 0) {
+            throw new GlobalException("高于最高限额");
+        }
+
+        if (orderAddDto.getUsdtAmount().compareTo(entrustOrder.getRemainCoinAmount()) > 0) {
+            throw new GlobalException("剩余数量不足");
+        }
+
         if (StrUtil.isBlank(orderAddDto.getPassword())) {
             throw new GlobalException("资金密码不能为空");
         }

--
Gitblit v1.9.1