package com.xcong.excoin.modules.yunding.service.Impl;
|
|
import cn.hutool.core.collection.CollUtil;
|
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.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.YdOrderDao;
|
import com.xcong.excoin.modules.yunding.entity.YdBasicLevelSettingEntity;
|
import com.xcong.excoin.modules.yunding.entity.YdOrderEntity;
|
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.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service
|
public class XchProfitServiceImpl implements XchProfitService {
|
|
@Autowired
|
private MemberDao memberDao;
|
|
@Autowired
|
private YdOrderDao ydOrderDao;
|
|
@Autowired
|
private MemberWalletCoinDao memberWalletCoinDao;
|
|
@Override
|
public void autoBeAgent(Long id) {
|
|
}
|
|
@Override
|
public void agentProfitDistributor() {
|
List<YdOrderEntity> orders = ydOrderDao.selectNeedReturnOrders();
|
|
if (CollUtil.isNotEmpty(orders)) {
|
for (YdOrderEntity order : orders) {
|
MemberEntity memberEntity = memberDao.selectById(order.getMemberId());
|
List<String> inviteIds = StrUtil.split(memberEntity.getRefererIds(), ',');
|
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());
|
}
|
}
|
|
for (Map.Entry<Long, BigDecimal> entry : returnRatio.entrySet()) {
|
String conent = "USDT返利";
|
BigDecimal amount = order.getAmount().multiply(entry.getValue());
|
LogRecordUtils.insertMemberAccountMoneyChangeWithId(entry.getKey(), conent, amount, "USDT", 1, 6, order.getId());
|
MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(entry.getKey(), "USDT");
|
|
memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), amount, BigDecimal.ZERO, 0);
|
}
|
|
YdOrderEntity updateOrder = new YdOrderEntity();
|
updateOrder.setReturnState(2);
|
updateOrder.setId(order.getId());
|
ydOrderDao.updateById(updateOrder);
|
}
|
}
|
|
}
|
}
|
}
|