Helius
2021-05-20 57cddad3c7841774720eb3112259b0d5b64d3059
modify
8 files modified
66 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletCoinDao.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/otc/controller/OtcMarketBussinessController.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/otc/controller/OtcOrderController.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/otc/dao/OtcOrderDao.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/otc/service/OtcOrderService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java 45 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/member/MemberWalletCoinDao.xml 5 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/otc/OtcOrderDao.xml 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletCoinDao.java
@@ -22,4 +22,6 @@
    int subFrozenBalance(@Param("memberId") Long memberId, @Param("id") Long id, @Param("amount") BigDecimal amount);
    int updateBlockBalance(@Param("id") Long id, @Param("availableBalance") BigDecimal availableBalance, @Param("earlyBalance") BigDecimal earlyBalance, @Param("blockNumber") Integer blockNumber);
    int reduceFrozenBalance(@Param("id") Long id, @Param("amount") BigDecimal amount);
}
src/main/java/com/xcong/excoin/modules/otc/controller/OtcMarketBussinessController.java
@@ -69,7 +69,7 @@
    }
    @ApiOperation(value = "findMbInfo", notes = "获取市商信息")
    @ApiOperation(value = "获取市商信息", notes = "获取市商信息")
    @ApiResponses({
            @ApiResponse(code = 200, message = "获取成功", response = MarketBussinessInfoVo.class)
    })
src/main/java/com/xcong/excoin/modules/otc/controller/OtcOrderController.java
@@ -56,6 +56,7 @@
    @ApiOperation(value = "确认收款")
    @PostMapping(value = "/finishOrder/{id}")
    public Result finishOrder(@PathVariable("id") Long id) {
        return null;
        otcOrderService.finishOrder(id);
        return Result.ok("操作成功");
    }
}
src/main/java/com/xcong/excoin/modules/otc/dao/OtcOrderDao.java
@@ -16,4 +16,6 @@
    IPage<OrderListVo> selectOrdderListInPage(@Param("record") OtcOrder order, Page<OrderListVo> page);
    int updateOrderStatusByOrderNo(@Param("status") Integer status, @Param("orderNo") String orderNo);
    OtcOrder selectOrderByOrderNoAndType(String orderNo, String orderType);
}
src/main/java/com/xcong/excoin/modules/otc/service/OtcOrderService.java
@@ -16,4 +16,6 @@
    IPage<OrderListVo> findOrderListInPage(OrderListDto orderListDto);
    void hasPay(Long id);
    void finishOrder(Long id);
}
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_PAY.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());
    }
}
src/main/resources/mapper/member/MemberWalletCoinDao.xml
@@ -39,5 +39,10 @@
        where id=#{id}
    </update>
    <update id="reduceFrozenBalance">
        update member_wallet_coin
        set frozen_balance = frozen_balance - #{amount}
        where id=#{id}
    </update>
</mapper>
src/main/resources/mapper/otc/OtcOrderDao.xml
@@ -43,4 +43,9 @@
        set status=#{status}
        where order_no=#{orderNo}
    </update>
    <select id="selectOrderByOrderNoAndType" resultType="com.xcong.excoin.modules.otc.entity.OtcOrder">
        select * from otc_order
        where order_no=#{orderNo} and order_type=#{orderType}
    </select>
</mapper>