KKSU
2024-03-18 57ac3a35ac056f0a09d8a013e8f3da2ecfe8a7c6
src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java
@@ -64,6 +64,9 @@
    private final MallProductBuyMapper mallProductBuyMapper;
    private final MallProductSellMapper mallProductSellMapper;
    private final MallProductSellRecordMapper mallProductSellRecordMapper;
    private final MallMemberAmountMapper mallMemberAmountMapper;
    private final IMallMoneyFlowService iMallMoneyFlowService;
    private final MallProductNftMapper mallProductNftMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -1113,8 +1116,62 @@
    @Override
    public void fcmNFTExchangeMsg(String cnt) {
        /**
         * 销毁数量 按照比例销毁或者返利给节点
         */
        BigDecimal destoryCntTotal = new BigDecimal(cnt);
        DataDictionaryCustom totalPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.FCM_DESTORY_TOTAL_PERCENT.getType(),
                DataDictionaryEnum.FCM_DESTORY_TOTAL_PERCENT.getCode()
        );
        BigDecimal totalPercent = new BigDecimal(totalPercentDic.getValue()).multiply(AppContants.BASIC_PERCENT);
        //销毁数量
        BigDecimal destoryCnt = new BigDecimal(cnt);
        BigDecimal destoryCnt = destoryCntTotal.multiply(totalPercent).setScale(2,BigDecimal.ROUND_DOWN);
        DataDictionaryCustom pointPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.FCM_DESTORY_POINT_PERCENT.getType(),
                DataDictionaryEnum.FCM_DESTORY_POINT_PERCENT.getCode()
        );
        BigDecimal pointPercent = new BigDecimal(pointPercentDic.getValue()).multiply(AppContants.BASIC_PERCENT);
        //节点评分总数量
        BigDecimal pointCnt = destoryCntTotal.multiply(pointPercent).setScale(2,BigDecimal.ROUND_DOWN);
        //给每个节点平分pointCnt。
        QueryWrapper<MallMember> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("partner",1);
        List<MallMember> mallMembers = mallMemberMapper.selectList(queryWrapper);
        if(CollUtil.isNotEmpty(mallMembers)){
            BigDecimal dividePointCnt = pointCnt.divide(new BigDecimal(mallMembers.size()), 2, BigDecimal.ROUND_DOWN);
            for(MallMember mallMember : mallMembers){
                Long memberId = mallMember.getId();
                MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId);
                mallMemberAmount.setFcmCntAva(mallMemberAmount.getFcmCntAva().add(dividePointCnt));
                mallMemberAmountMapper.updateFcmCntAvaById(mallMemberAmount);
                String orderNo = MallUtils.getOrderNum("JD");
                iMallMoneyFlowService.addMoneyFlow(
                        memberId,
                        dividePointCnt,
                        MoneyFlowTypeNewEnum.PERK_POINT.getValue(),
                        orderNo,
                        mallMember.getId(),
                        FlowTypeNewEnum.FCM_COIN.getValue(),
                        MoneyFlowTypeNewEnum.PERK_POINT.getDescrition());
            }
        }
        //更新总销毁数量
        DataDictionaryCustom fcmDestoryTotalDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.FCM_DESTORY_TOTAL.getType(),
                DataDictionaryEnum.FCM_DESTORY_TOTAL.getCode()
        );
        BigDecimal fcmDestoryTotal = new BigDecimal(fcmDestoryTotalDic.getValue());
        fcmDestoryTotal = fcmDestoryTotal.add(destoryCnt);
        commonService.updateDataDic(
                DataDictionaryEnum.FCM_DESTORY_TOTAL.getType(),
                DataDictionaryEnum.FCM_DESTORY_TOTAL.getCode(),
                fcmDestoryTotal.toString());
        DataDictionaryCustom fcmDestoryCntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.FCM_DESTORY_CNT.getType(),
                DataDictionaryEnum.FCM_DESTORY_CNT.getCode()
@@ -1129,8 +1186,8 @@
        BigDecimal divide = fcmDestoryCntAdd.divide(AppContants.FCM_BASIC, 0, BigDecimal.ROUND_DOWN);
        if(BigDecimal.ZERO.compareTo(divide) == 0){
            commonService.updateDataDic(
                    DataDictionaryEnum.BANK_TRANS_URL.getType(),
                    DataDictionaryEnum.BANK_TRANS_URL.getCode(),
                    DataDictionaryEnum.FCM_DESTORY_CNT.getType(),
                    DataDictionaryEnum.FCM_DESTORY_CNT.getCode(),
                    fcmDestoryCntAdd.toString());
        }
@@ -1141,18 +1198,6 @@
                    DataDictionaryEnum.FCM_DESTORY_CNT.getType(),
                    DataDictionaryEnum.FCM_DESTORY_CNT.getCode(),
                    fcmDestoryCntReal.toString());
            //更新总销毁数量
            DataDictionaryCustom fcmDestoryTotalDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                    DataDictionaryEnum.FCM_DESTORY_TOTAL.getType(),
                    DataDictionaryEnum.FCM_DESTORY_TOTAL.getCode()
            );
            BigDecimal fcmDestoryTotal = new BigDecimal(fcmDestoryTotalDic.getValue());
            fcmDestoryTotal = fcmDestoryTotal.add(destoryCnt);
            commonService.updateDataDic(
                    DataDictionaryEnum.FCM_DESTORY_TOTAL.getType(),
                    DataDictionaryEnum.FCM_DESTORY_TOTAL.getCode(),
                    fcmDestoryTotal.toString());
            //更新价格
            DataDictionaryCustom fcmPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                    DataDictionaryEnum.FCM_PRICE.getType(),
@@ -1218,11 +1263,18 @@
            BigDecimal nftCntTotalBuy = mallProductBuyRecords.stream().map(MallProductBuyRecord::getPickNftCnt).reduce(BigDecimal.ZERO, BigDecimal::add);
            MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(buyId);
            if(nftCntTotalBuy.compareTo(mallProductBuy.getNftTotal()) >= 0){
                return;
                Long productNftId = mallProductBuy.getProductNftId();
                MallProductNft mallProductNft = mallProductNftMapper.selectById(productNftId);
                BigDecimal perkTime = mallProductNft.getPerkTime();
                BigDecimal totalPerk = perkTime.multiply(mallProductBuy.getNftTotal()).setScale(2, BigDecimal.ROUND_DOWN);
                mallProductBuy.setTotalPerk(totalPerk);
                mallProductBuy.setState(ProductEnum.PRODUCT_BUY_SUCCESS.getValue());
                mallProductBuy.setPayTime(DateUtil.date());
                mallProductBuyMapper.updateById(mallProductBuy);
            }
            mallProductBuy.setState(ProductEnum.PRODUCT_BUY_SUCCESS.getValue());
            mallProductBuy.setPayTime(DateUtil.date());
            mallProductBuyMapper.updateById(mallProductBuy);
        }
    }
@@ -1240,6 +1292,10 @@
        MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(mallProductBuyRecord.getBuyId());
        mallProductBuy.setNftAva(mallProductBuy.getNftAva().add(mallProductBuyRecord.getPickNftCnt()));
        mallProductBuyMapper.updateById(mallProductBuy);
        Long memberId = mallProductBuy.getMemberId();
        MallMember mallMember = mallMemberMapper.selectById(memberId);
        mallMember.setIsFrozen(ProductEnum.MEMBER_FROZEN.getValue());
        mallMemberMapper.updateById(mallMember);
        //更新卖单子表的数据
        MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId);
        mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue());