Helius
2021-05-20 0469ade9be848d97eefb92f3e584441d89e6b69d
src/main/java/com/xcong/excoin/modules/yunding/service/Impl/XchProfitServiceImpl.java
@@ -4,18 +4,23 @@
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao;
import com.xcong.excoin.modules.member.dao.MemberDao;
import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.modules.yunding.dao.YdBasicLevelSettingDao;
import com.xcong.excoin.modules.yunding.dao.YdBasicSettingDao;
import com.xcong.excoin.modules.yunding.dao.YdOrderDao;
import com.xcong.excoin.modules.yunding.dao.YdProductDao;
import com.xcong.excoin.modules.yunding.entity.YdBasicLevelSettingEntity;
import com.xcong.excoin.modules.yunding.entity.YdBasicSettingEntity;
import com.xcong.excoin.modules.yunding.entity.YdOrderEntity;
import com.xcong.excoin.modules.yunding.entity.YdProductEntity;
import com.xcong.excoin.modules.yunding.service.XchProfitService;
import com.xcong.excoin.netty.common.Contans;
import com.xcong.excoin.rabbit.producer.YunDingProducter;
import com.xcong.excoin.utils.LogRecordUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,6 +49,12 @@
    @Autowired
    private YdBasicLevelSettingDao ydBasicLevelSettingDao;
    @Autowired
    private YunDingProducter yunDingProducter;
    @Autowired
    private YdBasicSettingDao ydBasicSettingDao;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void autoBeAgent(Long id) {
@@ -68,7 +79,7 @@
                        update.setAgentLevel(2);
                        memberDao.updateById(update);
                    }
                } else if (memberEntity.getAgentLevel() != null && member.getAgentLevel() == 2){
                } else if (memberEntity.getAgentLevel() != null && memberEntity.getAgentLevel() == 2){
                    // 判断是否达到总代标准
                    if(becomeZd(memberEntity, settings.get(0))) {
                        update.setAgentLevel(1);
@@ -147,6 +158,8 @@
    public void usdtProfitDistributorByOrderId(Long id) {
        YdOrderEntity ydOrderEntity = ydOrderDao.selectById(id);
        usdtProfitDistributor(ydOrderEntity);
        yunDingProducter.sendYunDingAutoAgent(ydOrderEntity.getMemberId());
    }
    private void usdtProfitDistributor(YdOrderEntity order) {
@@ -170,6 +183,35 @@
            updateOrder.setReturnState(2);
            updateOrder.setId(order.getId());
            ydOrderDao.updateById(updateOrder);
        }
        // 合伙人分红
        List<MemberEntity> partners = memberDao.selectPartnerMemberList();
        YdBasicSettingEntity setting = ydBasicSettingDao.selectById(1L);
        if (CollUtil.isNotEmpty(partners)) {
            BigDecimal returnAmount = order.getAmount().multiply(setting.getPartnerRatio()).divide(BigDecimal.valueOf(partners.size()), 8, BigDecimal.ROUND_DOWN);
            log.info("合伙人分红:{}", returnAmount);
            for (MemberEntity partner : partners) {
                String conent = "合伙人USDT分红";
                LogRecordUtils.insertMemberAccountMoneyChangeWithId(partner.getId(), conent, returnAmount, "USDT", 1, 9, order.getId());
                MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(partner.getId(), "USDT");
                memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), returnAmount, BigDecimal.ZERO, 0);
            }
        }
        if(!AppContants.SYSTEM_REFERER.equals(memberEntity.getRefererId())) {
            // 直推返利
            MemberEntity parentNode = memberDao.selectMemberInfoByInviteId(memberEntity.getRefererId());
            if (parentNode != null) {
                BigDecimal parentAmount = order.getAmount().multiply(setting.getParentRatio());
                String conent = "直推USDT返利";
                LogRecordUtils.insertMemberAccountMoneyChangeWithId(parentNode.getId(), conent, parentAmount, "USDT", 1, 10, order.getId());
                MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(parentNode.getId(), "USDT");
                memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), parentAmount, BigDecimal.ZERO, 0);
            }
        }
    }
@@ -257,11 +299,12 @@
                        }
                    }
                    remainProfit = remainProfit.subtract(orderProfit.subtract(orderProfit.multiply(order.getYdProductEntity().getManageExpense())));
                    remainProfit = remainProfit.subtract(orderProfit.multiply(order.getYdProductEntity().getManageExpense()));
                    String content = "XCH收益";
                    LogRecordUtils.insertMemberAccountMoneyChangeWithId(order.getMemberId(), content, remainProfit, "XCH", 1, 4, order.getId());
                    MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(order.getMemberId(), "XCH");
                    ydOrderDao.updateOrderProfit(remainProfit, order.getId());
                    memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), remainProfit, BigDecimal.ZERO, 0);
                }
            }