| | |
| | | package com.xcong.excoin.modules.yunding.service.Impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao; |
| | | import com.xcong.excoin.modules.member.dao.MemberDao; |
| | |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; |
| | | 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.YdOrderEntity; |
| | | import com.xcong.excoin.modules.yunding.entity.YdProductEntity; |
| | | import com.xcong.excoin.modules.yunding.service.XchProfitService; |
| | | import com.xcong.excoin.utils.LogRecordUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | @Autowired |
| | | private MemberWalletCoinDao memberWalletCoinDao; |
| | | |
| | | @Autowired |
| | | private YdProductDao ydProductDao; |
| | | |
| | | @Override |
| | | public void autoBeAgent(Long id) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void agentProfitDistributor() { |
| | | public void agentUsdtProfitDistributor() { |
| | | List<YdOrderEntity> orders = ydOrderDao.selectNeedReturnOrders(); |
| | | |
| | | if (CollUtil.isNotEmpty(orders)) { |
| | |
| | | List<MemberEntity> agents = memberDao.selectYdParentAgent(inviteIds); |
| | | |
| | | if (CollUtil.isNotEmpty(agents)) { |
| | | Map<Long, BigDecimal> returnRatio = new HashMap<Long, BigDecimal>(); |
| | | Long lastId = null; |
| | | for (MemberEntity agent : agents) { |
| | | YdBasicLevelSettingEntity settingEntity = agent.getYdBasicLevelSettingEntity(); |
| | | if(settingEntity.getLevel() == 1) { |
| | | if (CollUtil.isNotEmpty(returnRatio)) { |
| | | BigDecimal lastRatio = returnRatio.get(lastId); |
| | | returnRatio.put(agent.getId(), settingEntity.getUsdtRatio().subtract(lastRatio)); |
| | | } else { |
| | | returnRatio.put(agent.getId(), settingEntity.getUsdtRatio()); |
| | | } |
| | | break; |
| | | } |
| | | |
| | | if (CollUtil.isEmpty(returnRatio)) { |
| | | lastId = agent.getId(); |
| | | returnRatio.put(agent.getId(), settingEntity.getUsdtRatio()); |
| | | } |
| | | } |
| | | Map<Long, BigDecimal> returnRatio = buildReturnRatioObj(agents, 1); |
| | | |
| | | for (Map.Entry<Long, BigDecimal> entry : returnRatio.entrySet()) { |
| | | String conent = "USDT返利"; |
| | |
| | | ydOrderDao.updateById(updateOrder); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private Map<Long, BigDecimal> buildReturnRatioObj(List<MemberEntity> agents, int type) { |
| | | Map<Long, BigDecimal> returnRatio = new HashMap<Long, BigDecimal>(); |
| | | Long lastId = null; |
| | | for (MemberEntity agent : agents) { |
| | | YdBasicLevelSettingEntity settingEntity = agent.getYdBasicLevelSettingEntity(); |
| | | |
| | | BigDecimal ratio; |
| | | if (type == 1) { |
| | | ratio = settingEntity.getUsdtRatio(); |
| | | } else { |
| | | ratio = settingEntity.getXchRatio(); |
| | | } |
| | | if(settingEntity.getLevel() == 1) { |
| | | if (CollUtil.isNotEmpty(returnRatio)) { |
| | | BigDecimal lastRatio = returnRatio.get(lastId); |
| | | returnRatio.put(agent.getId(), ratio.subtract(lastRatio)); |
| | | } else { |
| | | returnRatio.put(agent.getId(), ratio); |
| | | } |
| | | break; |
| | | } |
| | | |
| | | if (CollUtil.isEmpty(returnRatio)) { |
| | | lastId = agent.getId(); |
| | | returnRatio.put(agent.getId(), ratio); |
| | | } |
| | | } |
| | | |
| | | return returnRatio; |
| | | } |
| | | |
| | | @Override |
| | | public void xchProfitDistributor(BigDecimal totalProfit) { |
| | | Date currentDate = new Date(); |
| | | List<YdProductEntity> products = ydProductDao.selectList(null); |
| | | if (CollUtil.isNotEmpty(products)) { |
| | | BigDecimal totalCount = BigDecimal.ZERO; |
| | | for (YdProductEntity product : products) { |
| | | BigDecimal count = product.getTotalT(); |
| | | if ("P".equals(product.getProUnit())) { |
| | | count = count.multiply(BigDecimal.valueOf(1024)); |
| | | } |
| | | |
| | | totalCount = totalCount.add(count); |
| | | } |
| | | |
| | | // 单位XCH收益 |
| | | BigDecimal unitProfit = totalProfit.divide(totalCount, 8, BigDecimal.ROUND_DOWN); |
| | | |
| | | List<YdOrderEntity> orders = ydOrderDao.selectAllValidOrders(); |
| | | if (CollUtil.isNotEmpty(orders)) { |
| | | for (YdOrderEntity order : orders) { |
| | | long between = DateUtil.between(order.getWorkTime(), currentDate, DateUnit.DAY); |
| | | if (between < 1) { |
| | | continue; |
| | | } |
| | | |
| | | MemberEntity memberEntity = memberDao.selectById(order.getMemberId()); |
| | | List<String> inviteIds = StrUtil.split(memberEntity.getRefererIds(), ','); |
| | | List<MemberEntity> agents = memberDao.selectYdParentAgent(inviteIds); |
| | | |
| | | BigDecimal count = BigDecimal.valueOf(order.getQuantity()); |
| | | if ("P".equals(order.getYdProductEntity().getProUnit())) { |
| | | count = count.multiply(BigDecimal.valueOf(1024)); |
| | | } |
| | | BigDecimal orderProfit = count.multiply(unitProfit); |
| | | BigDecimal remainProfit = orderProfit; |
| | | if (CollUtil.isNotEmpty(agents)) { |
| | | Map<Long, BigDecimal> returnRatio = buildReturnRatioObj(agents, 2); |
| | | |
| | | for (Map.Entry<Long, BigDecimal> entry : returnRatio.entrySet()) { |
| | | String content = "XCH收益返利"; |
| | | BigDecimal amount = entry.getValue().multiply(orderProfit); |
| | | |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(entry.getKey(), content, amount, "XCH", 1, 5, order.getId()); |
| | | MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(entry.getKey(), "XCH"); |
| | | |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), amount, BigDecimal.ZERO, 0); |
| | | remainProfit = remainProfit.subtract(amount); |
| | | } |
| | | } |
| | | |
| | | String content = "XCH收益"; |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(order.getMemberId(), content, remainProfit, "XCH", 1, 4, order.getId()); |
| | | MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(order.getMemberId(), "XCH"); |
| | | |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), remainProfit, BigDecimal.ZERO, 0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |