xiaoyong931011
2022-11-02 159a0246dbca8b0faea5d2ff3de38047e181a811
src/main/java/cc/mrbird/febs/job/OnHookPlanJob.java
@@ -226,7 +226,7 @@
//                        igtOnHookPlanOrder.setState(3);
//                        igtOnHookPlanOrderDao.updateById(igtOnHookPlanOrder);
//                    }else{
//                        //获取收益率
                        //获取收益率
//                        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(igtOnHookPlanOrder.getMemberId());
//                        DataDictionaryCustom identityDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.LEVEL_MB.getType(), dappMemberEntity.getIdentity());
//                        String identityDicValue = identityDic.getValue();
@@ -278,56 +278,64 @@
    @Scheduled(cron = "0 0/1 * * * ? ")
    public void updatePlanOrder(){
        Log.info("开始更新挂机主表状态");
        List<IgtOnHookPlanOrder> igtOnHookPlanOrders = igtOnHookPlanOrderDao.selectByState(3);
        if(CollUtil.isNotEmpty(igtOnHookPlanOrders)){
            List<Long> ids = igtOnHookPlanOrderDao.selectIdsByState(3);
            //更新状态避免重复查询
            igtOnHookPlanOrderDao.updateByIds(ids);
            for(IgtOnHookPlanOrder igtOnHookPlanOrder : igtOnHookPlanOrders){
                Long orderId = igtOnHookPlanOrder.getId();
                Long memberId = igtOnHookPlanOrder.getMemberId();
                BigDecimal planAmount = igtOnHookPlanOrder.getPlanAmount();
                BigDecimal avaAmount = igtOnHookPlanOrder.getAvaAmount();
                //总盈利
//            BigDecimal totalProfit = igtOnHookPlanOrderItemDao.selectTotalProfitByByOrderIdAndMemberIdAndState(orderId,memberId,1,2);
                BigDecimal totalProfit = igtOnHookPlanOrder.getProfit();
                DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId);
                String refererIds = dappMemberEntity.getRefererIds();
                List<String> refererIdList = StrUtil.split(refererIds, ",", -1, true, true);
                //生成流水佣金和盈利分成和流水记录,返回剩余盈利
                BigDecimal profitSharingTotal = dappWalletService.updateLSYJYLFC(refererIdList, totalProfit);
                //平台分成,返回剩余盈利
                BigDecimal systemTotal = dappWalletService.updatePTFC(memberId,totalProfit);
                totalProfit = totalProfit.subtract(profitSharingTotal).subtract(systemTotal);
                //获取用户信息的是否盈利字段
                DappMemberEntity dappMember = dappMemberDao.selectById(memberId);
                Integer isProfit = dappMember.getIsProfit() == null ? 1 : dappMember.getIsProfit();
                igtOnHookPlanOrder.setState(2);
                //一次挂机剩余的全部金额
                BigDecimal totalMoney = totalProfit.add(avaAmount);
                if(totalMoney.compareTo(planAmount)<=0){
                    igtOnHookPlanOrder.setProfitState(2);
                //是否设置了亏损
                Integer isProfit = dappMemberEntity.getIsProfit() == null ? 1 : dappMemberEntity.getIsProfit();
                if(2 == isProfit){
                    BigDecimal bigDecimal = planAmount.divide(new BigDecimal(2)).setScale(4, BigDecimal.ROUND_DOWN);
                    DappWalletCoinEntity dappWalletCoinEntity = dappWalletCoinDao.selectByMemberId(memberId);
                    BigDecimal availableAmount = dappWalletCoinEntity.getAvailableAmount();
                    dappWalletCoinDao.addTotalAndaddAvailableById(dappWalletCoinEntity.getId(),planAmount.negate());
                    BigDecimal add = availableAmount.add(bigDecimal).setScale(4, BigDecimal.ROUND_DOWN);
                    DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(memberId, availableAmount, bigDecimal, add, "系统", 9);
                    dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                }else{
                    igtOnHookPlanOrder.setProfitState(1);
                    //获取收益率
                    DataDictionaryCustom identityDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.LEVEL_MB.getType(), dappMemberEntity.getIdentity());
                    String identityDicValue = identityDic.getValue();
                    JSONObject identityDicValueParse = JSONUtil.parseObj(identityDicValue);
                    BigDecimal hangingRevenueLevel = new BigDecimal(identityDicValueParse.get("hangingRevenue").toString())
                            .multiply(new BigDecimal(0.01)).setScale(4,BigDecimal.ROUND_DOWN);
                    //获取收益
                    BigDecimal totalProfit = planAmount.multiply(hangingRevenueLevel).setScale(4,BigDecimal.ROUND_DOWN);
                    String refererIds = dappMemberEntity.getRefererIds();
                    List<String> refererIdList = StrUtil.split(refererIds, ",", -1, true, true);
                    //生成流水佣金和盈利分成和流水记录,返回剩余盈利
                    BigDecimal profitSharingTotal = dappWalletService.updateLSYJYLFC(refererIdList, totalProfit);
                    //平台分成,返回剩余盈利
                    BigDecimal systemTotal = dappWalletService.updatePTFC(memberId,totalProfit);
                    totalProfit = totalProfit.subtract(profitSharingTotal).subtract(systemTotal);
                    igtOnHookPlanOrder.setState(2);
                    //一次挂机剩余的全部金额
                    BigDecimal totalMoney = totalProfit.add(planAmount);
                    igtOnHookPlanOrder.setProfit(totalProfit);
                    igtOnHookPlanOrderDao.updateById(igtOnHookPlanOrder);
                    dappMemberEntity.setIsOnHook(3);
                    dappMemberDao.updateById(dappMemberEntity);
                    DappWalletCoinEntity dappWalletCoinEntity = dappWalletCoinDao.selectByMemberId(memberId);
                    BigDecimal availableAmount = dappWalletCoinEntity.getAvailableAmount();
                    dappWalletCoinDao.addTotalAndaddAvailableById(dappWalletCoinEntity.getId(),totalMoney);
                    BigDecimal add = availableAmount.add(totalMoney);
                    BigDecimal subtract = add.subtract(totalProfit);
                    DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(memberId, subtract, totalProfit, add, "投注盈利", 5);
                    dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                }
                igtOnHookPlanOrder.setProfit(totalProfit);
                igtOnHookPlanOrderDao.updateById(igtOnHookPlanOrder);
                dappMemberEntity.setIsOnHook(3);
                dappMemberDao.updateById(dappMemberEntity);
                DappWalletCoinEntity dappWalletCoinEntity = dappWalletCoinDao.selectByMemberId(memberId);
                BigDecimal availableAmount = dappWalletCoinEntity.getAvailableAmount();
                dappWalletCoinDao.addTotalAndaddAvailableById(dappWalletCoinEntity.getId(),totalMoney);
                BigDecimal add = availableAmount.add(totalMoney);
                BigDecimal subtract = add.subtract(totalProfit);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(memberId, subtract, totalProfit, add, "投注盈利", 5);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
            }
        }
    }