From b787caa660c2aed5281d1429d5db2ec18ac8fa7c Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Tue, 25 May 2021 16:31:36 +0800
Subject: [PATCH] Merge branch 'otc' of http://120.27.238.55:7000/r/exchange into otc

---
 src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcEntrustOrderServiceImpl.java |   49 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcEntrustOrderServiceImpl.java b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcEntrustOrderServiceImpl.java
index 9557361..532df17 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcEntrustOrderServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcEntrustOrderServiceImpl.java
@@ -40,9 +40,9 @@
 @RequiredArgsConstructor
 public class OtcEntrustOrderServiceImpl extends ServiceImpl<OtcEntrustOrderDao, OtcEntrustOrder> implements OtcEntrustOrderService {
 
-    private final OtcMarketBussinessDao otcMarketBussinessDao;
     private final MemberDao memberDao;
     private final MemberPaymentMethodDao memberPaymentMethodDao;
+    private final OtcMarketBussinessDao otcMarketBussinessDao;
     private final MemberWalletCoinDao memberWalletCoinDao;
     private final OtcOrderDao otcOrderDao;
     private final CommonService commonService;
@@ -66,20 +66,36 @@
 
         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) {
                 throw new GlobalException("可用金额不足");
             }
 
-            memberWalletCoinDao.updateFrozenBalance(member.getId(), coinWallet.getId(), totalAmount);
+            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 (member.getIsTrader() == 2) {
             otcEntrustOrder.setIsMb(OtcEntrustOrder.IS_MB_N);
         } else {
-            otcEntrustOrder.setMbId(mb.getId());
             otcEntrustOrder.setIsMb(OtcEntrustOrder.IS_MB_Y);
         }
 
@@ -114,11 +130,9 @@
             throw new GlobalException("类型错误");
         }
 
-        OtcMarketBussiness mb = otcMarketBussinessDao.selectMarketBussinessByMemberId(member.getId());
-        if (mb == null) {
+        if (member.getIsTrader() == 2) {
             otcEntrustOrder.setIsMb(OtcEntrustOrder.IS_MB_N);
         } else {
-            otcEntrustOrder.setMbId(mb.getId());
             otcEntrustOrder.setIsMb(OtcEntrustOrder.IS_MB_Y);
         }
 
@@ -141,19 +155,23 @@
 
     @Override
     public IPage<EntrustListVo> findEntrustListInPage(EntrustOrderListDto dto) {
+        MemberEntity member = LoginUserUtils.getAppLoginUser();
         Page<EntrustListVo> page = new Page<>(dto.getPageNum(), dto.getPageSize());
+        dto.setMemberId(member.getId());
         return this.baseMapper.selectEntrustListInPage(dto, page);
     }
 
     @Override
-    public List<EntrustListInfoVo> findOwnEntrustOrder() {
+    public List<EntrustListInfoVo> findOwnEntrustOrder(EntrustOrderListDto orderListDto) {
         MemberEntity member = LoginUserUtils.getAppLoginUser();
 
         OtcEntrustOrder query = new OtcEntrustOrder();
         query.setStatus(3);
         query.setMemberId(member.getId());
-        List<OtcEntrustOrder> otcEntrustOrders = this.baseMapper.selectEntrustOrderByOrderType(query);
-        return OtcEntrustOrderMapper.INSTANCE.entrustToListInfoVoList(otcEntrustOrders);
+
+        Page<OtcEntrustOrder> page = new Page<>(orderListDto.getPageNum(), orderListDto.getPageSize());
+        IPage<OtcEntrustOrder> result = this.baseMapper.selectOwnEntrustListInPage(query, page);
+        return OtcEntrustOrderMapper.INSTANCE.entrustToListInfoVoList(result.getRecords());
     }
 
     @Override
@@ -187,18 +205,19 @@
 
     @Override
     public Result findEntrustOrderDetail(Long id) {
-        MemberEntity member = LoginUserUtils.getAppLoginUser();
-
         OtcEntrustOrder otcEntrustOrder = this.baseMapper.selectById(id);
         if (otcEntrustOrder == null) {
             return Result.fail("参数错误");
         }
 
-        if (!member.getId().equals(otcEntrustOrder.getMemberId())) {
-            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);
     }
 }

--
Gitblit v1.9.1