From f8034d74a80c0ccc989bd79dc864dbf7cb02d03c Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 20 May 2021 19:50:37 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java | 44 ++++++++++++++++++++++++++++++++------------
1 files changed, 32 insertions(+), 12 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 f3fdf79..0086fec 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
@@ -1,6 +1,8 @@
package com.xcong.excoin.modules.otc.service.impl;
import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.date.DateUnit;
+import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -19,8 +21,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,27 +56,31 @@
@Override
@Transactional(rollbackFor = Exception.class)
- public void buyOrder(OrderAddDto orderAddDto) {
+ public Result buyOrder(OtcOrderAddDto orderAddDto) {
MemberEntity member = LoginUserUtils.getAppLoginUser();
OtcEntrustOrder entrustOrder = otcEntrustOrderDao.selectById(orderAddDto.getId());
if (entrustOrder == null) {
throw new GlobalException("委托单不存在");
}
+ if (member.getId().equals(entrustOrder.getMemberId())) {
+ throw new GlobalException("不能购买自己的委托单");
+ }
+
if (!OtcEntrustOrder.ORDER_TYPE_S.equals(entrustOrder.getOrderType())) {
throw new GlobalException("无法购买");
}
- if (orderAddDto.getUsdtAmount().compareTo(entrustOrder.getRemainCoinAmount()) > 0) {
- throw new GlobalException("无足够的USDT");
- }
-
- if (orderAddDto.getUsdtAmount().compareTo(entrustOrder.getLimitMinAmount()) < 0) {
+ if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getLimitMinAmount()) < 0) {
throw new GlobalException("低于最低限额");
}
- if (orderAddDto.getUsdtAmount().compareTo(entrustOrder.getLimitMaxAmount()) > 0) {
+ if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getLimitMaxAmount()) > 0) {
throw new GlobalException("高于最高限额");
+ }
+
+ if (orderAddDto.getUsdtAmount().compareTo(entrustOrder.getRemainCoinAmount()) > 0) {
+ throw new GlobalException("剩余数量不足");
}
BigDecimal cny = orderAddDto.getUsdtAmount().multiply(entrustOrder.getUnitPrice());
@@ -101,27 +107,37 @@
otcEntrustOrderDao.updateRemainAmount(entrustOrder.getId(), orderAddDto.getUsdtAmount().negate());
this.baseMapper.insert(otcOrder);
this.baseMapper.insert(sale);
+
+ return Result.ok("购买成功", otcOrder.getId());
}
@Override
@Transactional(rollbackFor = Exception.class)
- public void saleOrder(OrderAddDto orderAddDto) {
+ public Result saleOrder(OtcOrderAddDto orderAddDto) {
MemberEntity member = LoginUserUtils.getAppLoginUser();
OtcEntrustOrder entrustOrder = otcEntrustOrderDao.selectById(orderAddDto.getId());
if (entrustOrder == null) {
throw new GlobalException("委托单不存在");
}
+ if (member.getId().equals(entrustOrder.getMemberId())) {
+ throw new GlobalException("不能购买自己的委托单");
+ }
+
if (!OtcEntrustOrder.ORDER_TYPE_B.equals(entrustOrder.getOrderType())) {
throw new GlobalException("无法出售");
}
- if (orderAddDto.getUsdtAmount().compareTo(entrustOrder.getLimitMinAmount()) < 0) {
+ if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getLimitMinAmount()) < 0) {
throw new GlobalException("低于最低限额");
}
- if (orderAddDto.getUsdtAmount().compareTo(entrustOrder.getLimitMaxAmount()) > 0) {
+ 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())) {
@@ -165,6 +181,7 @@
this.baseMapper.insert(buy);
memberWalletCoinDao.updateFrozenBalance(member.getId(), wallet.getId(), orderAddDto.getUsdtAmount());
+ return Result.ok("出售成功", otcOrder.getId());
}
@Override
@@ -232,7 +249,7 @@
// 出售者钱包冻结减少币
memberWalletCoinDao.reduceFrozenBalance(saleWallet.getId(), buyOrder.getCoinAmount());
- this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_PAY, null, otcOrder.getOrderNo());
+ this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_FINISH, null, otcOrder.getOrderNo());
}
@Override
@@ -275,6 +292,9 @@
buyDetail.setOrderCnt(otcMb.getBuyCnt());
}
+ long between = DateUtil.between(buyOrder.getCreateTime(), new Date(), DateUnit.SECOND);
+ buyDetail.setTimes(between);
+
return Result.ok(buyDetail);
}
--
Gitblit v1.9.1