From 9d641b6dd286bb9a817d9d4e42e36d4743a4bfd6 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 21 May 2021 10:14:47 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java | 47 ++++++++++++++++++++++++++++++++++++-----------
1 files changed, 36 insertions(+), 11 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 153f899..fe46ce8 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
@@ -56,22 +56,22 @@
@Override
@Transactional(rollbackFor = Exception.class)
- public void buyOrder(OtcOrderAddDto 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("低于最低限额");
}
@@ -79,7 +79,7 @@
throw new GlobalException("高于最高限额");
}
- if (orderAddDto.getCnyAmount().compareTo(entrustOrder.getRemainCoinAmount()) > 0) {
+ if (orderAddDto.getUsdtAmount().compareTo(entrustOrder.getRemainCoinAmount()) > 0) {
throw new GlobalException("剩余数量不足");
}
@@ -107,15 +107,21 @@
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(OtcOrderAddDto 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())) {
@@ -175,6 +181,7 @@
this.baseMapper.insert(buy);
memberWalletCoinDao.updateFrozenBalance(member.getId(), wallet.getId(), orderAddDto.getUsdtAmount());
+ return Result.ok("出售成功", otcOrder.getId());
}
@Override
@@ -242,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
@@ -285,8 +292,11 @@
buyDetail.setOrderCnt(otcMb.getBuyCnt());
}
- long between = DateUtil.between(buyOrder.getCreateTime(), new Date(), DateUnit.SECOND);
- buyDetail.setTimes(between);
+
+ if (OtcOrder.STATUS_SUBMIT.equals(buyOrder.getStatus())) {
+ long between = DateUtil.between(new Date(), DateUtil.offsetMinute(buyOrder.getCreateTime(), 30), DateUnit.SECOND, false);
+ buyDetail.setTimes(between);
+ }
return Result.ok(buyDetail);
}
@@ -323,4 +333,19 @@
return Result.ok(saleDetail);
}
+
+ @Override
+ public void cancelOrder(Long id) {
+ OtcOrder otcOrder = this.baseMapper.selectById(id);
+ if (otcOrder == null) {
+ throw new GlobalException("订单不存在");
+ }
+
+ if (!OtcOrder.STATUS_SUBMIT.equals(otcOrder.getStatus())) {
+ throw new GlobalException("不能取消");
+ }
+
+ otcEntrustOrderDao.updateRemainAmount(otcOrder.getEntrustOrderId(), otcOrder.getCoinAmount());
+ this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_CANCEL, null, otcOrder.getOrderNo());
+ }
}
--
Gitblit v1.9.1