xiaoyong931011
2022-11-30 03f330eaed9ae6666e6fbe72b12d0ce279bf56e6
20221124
12 files modified
1 files added
171 ■■■■■ changed files
src/main/java/cc/mrbird/febs/dapp/dto/TransferDto.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/entity/DappFundFlowEntity.java 2 ●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/entity/DappSystemProfit.java 4 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/enumerate/DataDictionaryEnum.java 4 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/mapper/DappMemberDao.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/mapper/DappSystemProfitDao.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java 71 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java 46 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/job/ProfitDailyJob.java 2 ●●● patch | view | raw | blame | history
src/main/resources/application-dev.yml 2 ●●● patch | view | raw | blame | history
src/main/resources/mapper/dapp/DappMemberDao.xml 6 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/dapp/DappSystemProfitDao.xml 22 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/dto/TransferDto.java
@@ -39,4 +39,7 @@
    @ApiModelProperty(value = "1-余额 2-钱包")
    private Integer buyType;
    @ApiModelProperty(hidden = true)
    private Long memberId;
}
src/main/java/cc/mrbird/febs/dapp/entity/DappFundFlowEntity.java
@@ -67,7 +67,7 @@
    /**
     * 类型 1-买入 2-矩阵收益 3-直推收益 4-保险池 5-提现 6-手续费充值 7-手续费扣除 8-结算 9-冻结 10-冻结释放 11-产矿 12-手续费返利
     * 类型 1-加入动能 2-技术方收益 3-直推收益 4-层级收益 5-剩余层级收益 6-手续费充值 7-手续费扣除 8-结算 9-冻结 10-冻结释放 11-产矿 12-手续费返利
     * 类型 1-加入动能 2-技术方收益 3-直推收益 4-层级收益 5-剩余层级收益给系统 6-复投动能 7-动能收益 8-结算 9-冻结 10-冻结释放 11-产矿 12-手续费返利
     */
    private Integer type;
src/main/java/cc/mrbird/febs/dapp/entity/DappSystemProfit.java
@@ -15,8 +15,8 @@
    private BigDecimal amount;
    //1:入列 2:出列
    private Integer state;
    public DappSystemProfit() {}
    public static final int STATE_IN = 1;
    public static final int STATE_OUT = 2;
    public DappSystemProfit(Long memberId, BigDecimal amount) {
        this.memberId = memberId;
src/main/java/cc/mrbird/febs/dapp/enumerate/DataDictionaryEnum.java
@@ -4,6 +4,10 @@
@Getter
public enum DataDictionaryEnum {
    // 投资金额
    INVEST_AMOUNT("SYSTEM_SETTING","INVEST_AMOUNT"),
    // 当前轮数
    QUEUE_COUNT("SYSTEM_SETTING","QUEUE_COUNT"),
    // 会员代理等级
    BIG_BOSS("MEMBER_LEVEL","BIG_BOSS"),
    BOSS("MEMBER_LEVEL","BOSS"),
src/main/java/cc/mrbird/febs/dapp/mapper/DappMemberDao.java
@@ -44,4 +44,6 @@
    DappMemberEntity selectNewestDirectMember(@Param("inviteId") String inviteId);
    List<DappMemberEntity> selectMemberListNeedProfit();
    void updateMemberAccountType(@Param("accountType")String code, @Param("id")Long id);
}
src/main/java/cc/mrbird/febs/dapp/mapper/DappSystemProfitDao.java
@@ -2,6 +2,11 @@
import cc.mrbird.febs.dapp.entity.DappSystemProfit;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
public interface DappSystemProfitDao extends BaseMapper<DappSystemProfit> {
    DappSystemProfit selectSystemProfitByState(@Param("state") int stateOut);
    DappSystemProfit selectByIdForUpdate(@Param("id") Long id,@Param("state") int stateOut);
}
src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java
@@ -45,4 +45,6 @@
    DappWalletCoinEntity findByMemberId(Long memberId);
    void transferAgain(TransferDto transferDto);
}
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -7,6 +7,7 @@
import cc.mrbird.febs.dapp.chain.ChainEnum;
import cc.mrbird.febs.dapp.chain.ChainService;
import cc.mrbird.febs.dapp.dto.SystemDto;
import cc.mrbird.febs.dapp.dto.TransferDto;
import cc.mrbird.febs.dapp.entity.*;
import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum;
import cc.mrbird.febs.dapp.enumerate.LevelProfitEnum;
@@ -330,7 +331,12 @@
                }
                //获取对应层级奖励
                BigDecimal profit = LevelProfitEnum.YI.getProfit(i);
                BigDecimal memberLevelProfit = levelProfitTotal.multiply(profit);
                String accountType = refererMember.getAccountType();
                //根据会员的等级类型,获取对应的百分比收益
                DataDictionaryCustom memberLevelSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode("MEMBER_LEVEL", accountType);
                BigDecimal memberLevel = new BigDecimal(memberLevelSet.getValue());
                BigDecimal memberLevelProfit = levelProfitTotal.multiply(profit).multiply(memberLevel);
                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 2, BigDecimal.ZERO,null,dappSystemProfit.getId());
                dappFundFlowDao.insert(fundFlow);
@@ -347,9 +353,72 @@
    @Override
    public void memberOut(Long id) {
        //验证是否已经加入动能队列
        DappSystemProfit systemProfit = dappSystemProfitDao.selectById(id);
        if(ObjectUtil.isEmpty(systemProfit)){
            return;
        }
        //获取当前是第几轮队列
        String redisKey = "QUEUE_COUNT";
        String memberOutCount = redisUtils.getString(redisKey);
        DataDictionaryCustom queueCountSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.QUEUE_COUNT.getType(), DataDictionaryEnum.QUEUE_COUNT.getCode());
        String queueCount = queueCountSet.getValue();
        if(StrUtil.isBlank(memberOutCount)){
            redisUtils.set(redisKey,queueCount,0L);
            memberOutCount = queueCount;
        }
        //出局条件的人数
        /**
         * 初始大小 5+4*0
         * 1  1,2,3,4,5  1出局 5+4*0
         * 2  2,3,4,5,1(复投),7,8,9,10  2出局 5+4*1
         * 3  3,4,5,1(复投),7,8,9,10,2(复投),12,13,14,15 3出局 5+4*2
         * 4  4,5,1(复投),7,8,9,10,2(复投),12,13,14,15,3(复投),17,18,19,20  4出局 5+4*3
         */
        Integer memberCount = Integer.parseInt(memberOutCount) * 4 + 5;
        //判断当前是否符合出局条件
        QueryWrapper<DappSystemProfit> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("state",DappSystemProfit.STATE_IN);
        //实际投资人数
        Integer selectCount = dappSystemProfitDao.selectCount(objectQueryWrapper);
        //实际投资人数小于出局条件人数
        if(selectCount < memberCount){
            return;
        }
        //符合则出局 实际投资人数等于出局条件人数
        DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectSystemProfitByState(DappSystemProfit.STATE_IN);
        if(ObjectUtil.isEmpty(dappSystemProfit)){
            return;
        }
        //符合则出局,轮数+1
        Integer realCount = (Integer.parseInt(queueCount) + 1);
        queueCountSet.setValue(realCount.toString());
        dataDictionaryCustomMapper.updateById(queueCountSet);
        redisUtils.set(redisKey,realCount,0L);
        DappSystemProfit dappSystemProfitNow = dappSystemProfitDao.selectByIdForUpdate(dappSystemProfit.getId(),DappSystemProfit.STATE_IN);
        dappSystemProfitNow.setState(DappSystemProfit.STATE_OUT);
        dappSystemProfitDao.updateById(dappSystemProfitNow);
        //todo 直接拿走0.95ge
        DappFundFlowEntity fundFlowOut = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), new BigDecimal(0.95), 7, 2, BigDecimal.ZERO, null,dappSystemProfitNow.getId());
        dappFundFlowDao.insert(fundFlowOut);
        //复投 成功{type: 1, txHash: result.transactionHash, id: res.data, flag: 'success', buyType: 2}
        DataDictionaryCustom investAmountSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.INVEST_AMOUNT.getType(), DataDictionaryEnum.INVEST_AMOUNT.getCode());
        BigDecimal investAmount = new BigDecimal(investAmountSet.getValue());
        //todo 直接运行转账
        String txHash = "复投";
        DappFundFlowEntity fundFlow = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), investAmount, 6, 2, BigDecimal.ZERO, txHash);
        dappFundFlowDao.insert(fundFlow);
        TransferDto transferDto = new TransferDto();
        transferDto.setType(1);
        transferDto.setTxHash(txHash);
        transferDto.setBuyType(2);
        transferDto.setId(fundFlow.getId());
        transferDto.setFlag("success");
        transferDto.setMemberId(dappSystemProfitNow.getMemberId());
        dappWalletService.transferAgain(transferDto);
    }
    public static void main(String[] args) {
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -174,6 +174,9 @@
                //插入一条会员入列记录,即加入动能队列
                DappSystemProfit dappSystemProfit = new DappSystemProfit(member.getId(), transferDto.getAmount());
                dappSystemProfitDao.insert(dappSystemProfit);
                //升级成为Agent
                dappMemberDao.updateMemberAccountType(DataDictionaryEnum.AGENT.getCode(),member.getId());
                DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
                flow.setFromHash(transferDto.getTxHash());
                flow.setSystemProfitId(dappSystemProfit.getId());
@@ -198,7 +201,7 @@
                //层级奖励30%
                chainProducer.sendLevelProfitMsg(dappSystemProfit.getId());
                //发送一个消息,计算当前是否有人可以出局
                chainProducer.sendMemberOutMsg(dappSystemProfit.getId());
            } else {
                DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
                if (flow.getStatus() == 1) {
@@ -369,4 +372,45 @@
    public DappWalletCoinEntity findByMemberId(Long memberId) {
        return dappWalletCoinDao.selectByMemberId(memberId);
    }
    @Override
    public void transferAgain(TransferDto transferDto) {
        Long memberId = transferDto.getMemberId();
        DappMemberEntity member = dappMemberDao.selectById(memberId);
        String upgrade = redisUtils.getString("APP_UPGRADE");
        if ("upgrade".equals(upgrade)) {
            throw new FebsException("功能升级中");
        }
        if ("success".equals(transferDto.getFlag())) {
            //插入一条会员入列记录,即加入动能队列
            DappSystemProfit dappSystemProfit = new DappSystemProfit(member.getId(), transferDto.getAmount());
            dappSystemProfitDao.insert(dappSystemProfit);
            DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
            flow.setFromHash(transferDto.getTxHash());
            flow.setSystemProfitId(dappSystemProfit.getId());
            dappFundFlowDao.updateById(flow);
            //直接拿走0.05个BNB放入技术方
            DataDictionaryCustom systemProfit = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYSTEM_PROFIT.getType(), DataDictionaryEnum.SYSTEM_PROFIT.getCode());
            String systemProfitStr = StrUtil.isEmpty(systemProfit.getValue()) ? "0.05" : systemProfit.getValue();
            DappFundFlowEntity systemProfitFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(systemProfitStr), 2, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
            dappFundFlowDao.insert(systemProfitFlow);
            //直接返利30%给直接上级
            DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
            String refererId = dappMemberEntity.getRefererId();
            DappMemberEntity refererMember = dappMemberDao.selectMemberInfoByInviteId(refererId);
            DataDictionaryCustom directProfitSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DIRECT_PROFIT.getType(), DataDictionaryEnum.DIRECT_PROFIT.getCode());
            BigDecimal directProfitStr = new BigDecimal(StrUtil.isEmpty(directProfitSet.getValue()) ? "0.3" : directProfitSet.getValue());
            BigDecimal directProfit = (transferDto.getAmount().subtract(new BigDecimal(systemProfitStr))).multiply(directProfitStr).setScale(BigDecimal.ROUND_DOWN, 2);
            DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), directProfit, 3, 2, BigDecimal.ZERO, transferDto.getTxHash(),dappSystemProfit.getId());
            dappFundFlowDao.insert(fundFlow);
            //层级奖励30%
            chainProducer.sendLevelProfitMsg(dappSystemProfit.getId());
            //发送一个消息,计算当前是否有人可以出局
            chainProducer.sendMemberOutMsg(dappSystemProfit.getId());
        }
    }
}
src/main/java/cc/mrbird/febs/job/ProfitDailyJob.java
@@ -36,7 +36,7 @@
    private DataDictionaryCustomMapper dataDictionaryCustomMapper;
    @Autowired
    private DappWalletService dappWalletService;
    //todo -- 升级会员等级
    @Scheduled(cron = "0 0 0 * * ?")
    public void profitDailyJob() {
        log.info("每日产矿任务执行");
src/main/resources/application-dev.yml
@@ -23,7 +23,7 @@
          username: ct_test
          password: 123456
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://120.27.238.55:3306/db_sdm?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8
          url: jdbc:mysql://120.27.238.55:3306/db_bnbweb?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8
  redis:
    database: 8
src/main/resources/mapper/dapp/DappMemberDao.xml
@@ -146,4 +146,10 @@
            group by referer_id having count(1) > 3
        ) b on a.invite_id=b.referer_id
    </select>
    <update id="updateMemberAccountType">
        update dapp_member
        set account_type = #{accountType}
        where id = #{id}
    </update>
</mapper>
src/main/resources/mapper/dapp/DappSystemProfitDao.xml
New file
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.mrbird.febs.dapp.mapper.DappSystemProfitDao">
    <select id="selectSystemProfitByState" resultType="cc.mrbird.febs.dapp.entity.DappSystemProfit">
        select a.*
        from dapp_system_profit a
        where state = #{state}
        order by id ASC
        limit 1
        for update
    </select>
    <select id="selectByIdForUpdate" resultType="cc.mrbird.febs.dapp.entity.DappSystemProfit">
        select a.*
        from dapp_system_profit a
        where a.id = #{id}
        and a.state = #{state}
        for update
    </select>
</mapper>