Helius
2021-05-20 d8fb05f44d8969921b7128d92be282176475ee80
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
@@ -29,6 +29,7 @@
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
@@ -155,6 +156,50 @@
    public void hasPay(Long id) {
        OtcOrder otcOrder = this.baseMapper.selectById(id);
        if (otcOrder == null) {
            throw new GlobalException("订单不存在");
        }
        if (!OtcOrder.STATUS_SUBMIT.equals(otcOrder.getStatus())) {
            throw new GlobalException("状态不正确");
        }
        if (!OtcEntrustOrder.ORDER_TYPE_B.equals(otcOrder.getOrderType())) {
            throw new GlobalException("不是购买单");
        }
        this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_PAY, otcOrder.getOrderNo());
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void finishOrder(Long id) {
        MemberEntity member = LoginUserUtils.getAppLoginUser();
        OtcOrder otcOrder = this.baseMapper.selectById(id);
        if (otcOrder == null) {
            throw new GlobalException("订单不存在");
        }
        if (!OtcOrder.STATUS_PAY.equals(otcOrder.getStatus())) {
            throw new GlobalException("状态不正确");
        }
        if (!OtcEntrustOrder.ORDER_TYPE_S.equals(otcOrder.getOrderType())) {
            throw new GlobalException("不是出售单");
        }
        OtcOrder buyOrder = this.baseMapper.selectOrderByOrderNoAndType(otcOrder.getOrderNo(), OtcEntrustOrder.ORDER_TYPE_B);
        OtcOrder saleOrder = this.baseMapper.selectOrderByOrderNoAndType(otcOrder.getOrderNo(), OtcEntrustOrder.ORDER_TYPE_S);
        MemberWalletCoinEntity buyWallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(buyOrder.getMemberId(), "USDT");
        MemberWalletCoinEntity saleWallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(saleOrder.getMemberId(), "USDT");
        // 购买者钱包可用新增币
        memberWalletCoinDao.updateBlockBalance(buyWallet.getId(), buyOrder.getCoinAmount(), BigDecimal.ZERO, 0);
        // 出售者钱包冻结减少币
        memberWalletCoinDao.reduceFrozenBalance(saleWallet.getId(), buyOrder.getCoinAmount());
        this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_PAY, otcOrder.getOrderNo());
    }
}