From bc26bbd27b75ab2f8ffc79a5a5fe25206f15abc7 Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Tue, 28 Nov 2023 17:39:07 +0800 Subject: [PATCH] 匹配 --- src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 0 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java index e061508..f8cdaf0 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java @@ -60,6 +60,10 @@ private final MallScoreAchieveReleaseMapper mallScoreAchieveReleaseMapper; private final MallScoreVoucherMapper mallScoreVoucherMapper; private final CommonService commonService; + private final MallProductBuyRecordMapper mallProductBuyRecordMapper; + private final MallProductBuyMapper mallProductBuyMapper; + private final MallProductSellMapper mallProductSellMapper; + private final MallProductSellRecordMapper mallProductSellRecordMapper; @Override @Transactional(rollbackFor = Exception.class) @@ -1163,6 +1167,89 @@ } } + @Override + public void fcmOrderSellInsureMsg(Long sellRecordId) { + /** + * 买单确认 + * 判断买单是否存在、是否已支付 + * 判断买单是否存在、是否已支付 + * 更新卖单状态 + * 更新买单状态 + */ + MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId); + if(ObjectUtil.isEmpty(mallProductSellRecord)){ + return; + } + Integer state = mallProductSellRecord.getState(); + if(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue() != state){ + return; + } + MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(mallProductSellRecord.getBuyRecordId()); + if(ObjectUtil.isEmpty(mallProductBuyRecord)){ + return; + } + Integer stateBuy = mallProductBuyRecord.getState(); + if(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue() != stateBuy){ + return; + } + mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FINISH.getValue()); + mallProductSellRecordMapper.updateById(mallProductSellRecord); + mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FINISH.getValue()); + mallProductBuyRecordMapper.updateById(mallProductBuyRecord); + Long sellId = mallProductSellRecord.getSellId(); + + //已完成的买单 + List<MallProductSellRecord> mallProductSellRecords = mallProductSellRecordMapper.selectListBySellId(sellId,ProductEnum.PRODUCT_MATE_STATE_FINISH.getValue()); + if(CollUtil.isNotEmpty(mallProductSellRecords)){ + //实际支付总数 + BigDecimal nftCntTotal = mallProductSellRecords.stream().map(MallProductSellRecord::getNftCnt).reduce(BigDecimal.ZERO, BigDecimal::add); + MallProductSell mallProductSell = mallProductSellMapper.selectById(sellId); + if(nftCntTotal.compareTo(mallProductSell.getNftCnt()) >= 0){ + mallProductSell.setState(ProductEnum.PRODUCT_SELL_SUCCESS.getValue()); + mallProductSellMapper.updateById(mallProductSell); + } + } + + + Long buyId = mallProductBuyRecord.getBuyId(); + List<MallProductBuyRecord> mallProductBuyRecords = mallProductBuyRecordMapper.selectListByBuyId(buyId,ProductEnum.PRODUCT_MATE_STATE_FINISH.getValue()); + if(CollUtil.isNotEmpty(mallProductBuyRecords)){ + //实际支付总数 + BigDecimal nftCntTotalBuy = mallProductBuyRecords.stream().map(MallProductBuyRecord::getPickNftCnt).reduce(BigDecimal.ZERO, BigDecimal::add); + MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(buyId); + if(nftCntTotalBuy.compareTo(mallProductBuy.getNftTotal()) >= 0){ + mallProductBuy.setState(ProductEnum.PRODUCT_BUY_SUCCESS.getValue()); + mallProductBuy.setPayTime(DateUtil.date()); + mallProductBuyMapper.updateById(mallProductBuy); + } + } + } + + @Override + public void fcmOrderBuyCancelMsg(Long buyRecordId) { + MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(buyRecordId); + if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != mallProductBuyRecord.getState()){ + return; + } + Long sellRecordId = mallProductBuyRecord.getSellRecordId(); + //更新买单子表的数据 + mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue()); + mallProductBuyRecordMapper.updateById(mallProductBuyRecord); + //更新买单主表 + MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(mallProductBuyRecord.getBuyId()); + mallProductBuy.setNftAva(mallProductBuy.getNftAva().add(mallProductBuyRecord.getPickNftCnt())); + mallProductBuyMapper.updateById(mallProductBuy); + //更新卖单子表的数据 + MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId); + mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue()); + mallProductSellRecordMapper.updateById(mallProductSellRecord); + //更新卖单主表 + Long sellId = mallProductSellRecord.getSellId(); + MallProductSell mallProductSell = mallProductSellMapper.selectById(sellId); + mallProductSell.setNftCntAva(mallProductSell.getNftCntAva().add(mallProductSellRecord.getNftCnt())); + mallProductSellMapper.updateById(mallProductSell); + } + public static void main(String[] args) { BigDecimal divide = new BigDecimal(12000).divide(new BigDecimal(10000), 0, BigDecimal.ROUND_DOWN); System.out.println(divide); -- Gitblit v1.9.1