| | |
| | | package com.xcong.excoin.modules.contract.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum; |
| | | import com.xcong.excoin.common.enumerates.OrderClosingTypeEnum; |
| | | import com.xcong.excoin.common.system.service.CommonService; |
| | |
| | | import com.xcong.excoin.modules.contract.entity.ContractOrderEntity; |
| | | import com.xcong.excoin.modules.contract.mapper.ContractHoldOrderEntityMapper; |
| | | import com.xcong.excoin.modules.contract.service.RabbitOrderService; |
| | | import com.xcong.excoin.modules.documentary.common.NoticeConstant; |
| | | import com.xcong.excoin.modules.documentary.dao.FollowFollowerOrderRelationDao; |
| | | import com.xcong.excoin.modules.documentary.dao.FollowTraderInfoDao; |
| | | import com.xcong.excoin.modules.documentary.dao.FollowTraderProfitDetailDao; |
| | | import com.xcong.excoin.modules.documentary.entity.FollowFollowerOrderRelationEntity; |
| | | import com.xcong.excoin.modules.documentary.entity.FollowFollowerProfitEntity; |
| | | import com.xcong.excoin.modules.documentary.entity.FollowTraderInfoEntity; |
| | | import com.xcong.excoin.modules.documentary.entity.FollowTraderProfitDetailEntity; |
| | | import com.xcong.excoin.modules.documentary.service.FollowOrderOperationService; |
| | | import com.xcong.excoin.modules.member.dao.MemberDao; |
| | | import com.xcong.excoin.modules.member.dao.MemberWalletContractDao; |
| | |
| | | private FollowFollowerOrderRelationDao followFollowerOrderRelationDao; |
| | | @Resource |
| | | private FollowOrderOperationService followOrderOperationService; |
| | | @Resource |
| | | private FollowTraderInfoDao followTraderInfoDao; |
| | | @Resource |
| | | private FollowTraderProfitDetailDao followTraderProfitDetailDao; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | FollowTraderInfoEntity traderInfoEntity = null; |
| | | // 判断当前订单是否为跟单 |
| | | if (ContractOrderEntity.CONTRACTTYPE_DOCUMENTARY == holdOrderEntity.getContractType()) { |
| | | // 若不为交易员,则计算跟随者订单返利 |
| | | if (!MemberEntity.IS_TRADER_Y.equals(memberEntity.getIsTrader())) { |
| | | traderInfoEntity = followTraderInfoDao.selectTraderInfoByOrderId(holdOrderEntity.getId()); |
| | | if (profitOrLoss.compareTo(BigDecimal.ZERO) > 0) { |
| | | // 计算需返利给交易员的金额 |
| | | BigDecimal returnMoney = profitOrLoss.subtract(traderInfoEntity.getProfitRatio()); |
| | | profitOrLoss = profitOrLoss.subtract(returnMoney); |
| | | MemberWalletContractEntity traderWallet = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(traderInfoEntity.getMemberId(), CoinTypeEnum.USDT.name()); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(returnMoney, returnMoney, null, traderWallet.getId()); |
| | | insertReturnProfitDetail(traderInfoEntity.getMemberId(), memberEntity.getId(), returnMoney, holdOrderEntity.getOrderNo()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 盈亏比例(回报率) |
| | | BigDecimal rewardRatio = profitOrLoss.divide(holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getOpeningFeeAmount()), 8, BigDecimal.ROUND_DOWN); |
| | | |
| | |
| | | // 若为交易员,则平仓跟随者订单 |
| | | if (MemberEntity.IS_TRADER_Y.equals(memberEntity.getIsTrader())) { |
| | | followOrderOperationService.closingFollowOrders(holdOrderEntity.getOrderNo()); |
| | | } else { |
| | | LogRecordUtils.insertFollowerNotice(memberEntity.getId(), NoticeConstant.CLOSE_ORDER_TITLE, StrUtil.format(NoticeConstant.CLOSE_ORDER_CONTENT, contractOrderEntity.getSymbol(), contractOrderEntity.getClosingPrice(), profitOrLoss)); |
| | | } |
| | | } |
| | | } |
| | |
| | | followFollowerOrderRelationDao.updateById(orderRelationEntity); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 插入跟单返利明细 |
| | | * |
| | | * @param memberId 交易员会员ID |
| | | * @param followMemberId 跟随者会员ID |
| | | * @param amount 返利金额 |
| | | * @param orderNo 订单编号 |
| | | */ |
| | | public void insertReturnProfitDetail(Long memberId, Long followMemberId, BigDecimal amount, String orderNo) { |
| | | FollowTraderProfitDetailEntity profitDetailEntity = new FollowTraderProfitDetailEntity(); |
| | | profitDetailEntity.setMemberId(memberId); |
| | | profitDetailEntity.setFollowMemberId(followMemberId); |
| | | profitDetailEntity.setAmount(amount); |
| | | profitDetailEntity.setOrderNo(orderNo); |
| | | followTraderProfitDetailDao.insert(profitDetailEntity); |
| | | } |
| | | } |