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/ApiMallProductServiceImpl.java |  125 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 104 insertions(+), 21 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java
index 1fdf668..842f7b9 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java
@@ -49,7 +49,32 @@
 
     @Override
     public List<ApiMallProductNftVo> productNFTList() {
+
+        DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
+        DataDictionaryCustom startTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.YU_YUE_START_TIME.getType(),
+                DataDictionaryEnum.YU_YUE_START_TIME.getCode()
+        );
+        DateTime startTime = DateUtil.parseTime(startTimeDic.getValue());
+        DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.YU_YUE_END_TIME.getType(),
+                DataDictionaryEnum.YU_YUE_END_TIME.getCode()
+        );
+        DateTime endTime = DateUtil.parseTime(endTimeDic.getValue());
         List<ApiMallProductNftVo> list = this.baseMapper.selectByState(ProductEnum.PRODUCT_NFT_OPEN.getValue());
+        if(CollUtil.isNotEmpty(list)){
+            for(ApiMallProductNftVo apiMallProductNftVo : list){
+                if(nowTime.compareTo(startTime) < 0){
+                    apiMallProductNftVo.setYuYueState(1);
+                }
+                if(nowTime.compareTo(startTime) >= 0 && nowTime.compareTo(endTime) <= 0){
+                    apiMallProductNftVo.setYuYueState(2);
+                }
+                if(nowTime.compareTo(endTime) > 0){
+                    apiMallProductNftVo.setYuYueState(3);
+                }
+            }
+        }
         return list;
     }
 
@@ -64,6 +89,25 @@
          * 预约,验证交易密码、预约产品是否开启状态、该产品是否已经预约、token是否足够
          * 冻结对应的令牌数量、生成预约记录、生成流水记录
          */
+        Integer isFrozen = mallMember.getIsFrozen();
+        if(ProductEnum.MEMBER_UNFROZEN.getValue() != isFrozen){
+            throw new FebsException("账户无法预约");
+        }
+
+        DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
+        DataDictionaryCustom startTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.YU_YUE_START_TIME.getType(),
+                DataDictionaryEnum.YU_YUE_START_TIME.getCode()
+        );
+        DateTime startTime = DateUtil.parseTime(startTimeDic.getValue());
+        DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.YU_YUE_END_TIME.getType(),
+                DataDictionaryEnum.YU_YUE_END_TIME.getCode()
+        );
+        DateTime endTime = DateUtil.parseTime(endTimeDic.getValue());
+        if(!(nowTime.compareTo(startTime) >= 0 && nowTime.compareTo(endTime) <= 0)){
+            throw new FebsException("预约未开始");
+        }
         if(!tradePassword.equals(mallMember.getTradePassword())){
             throw new FebsException("请输入正确的交易密码");
         }
@@ -75,7 +119,7 @@
             throw new FebsException("预约超时");
         }
         MallProductBuy mallProductBuy = mallProductBuyMapper.selectMemberIdAndNFTIdAndStateAndMateState(
-                memberId,productNFTId,ProductEnum.PRODUCT_BUY_ON_GOING.getValue(),null);
+                memberId,productNFTId,ProductEnum.PRODUCT_BUY_ON_GOING.getValue(),ProductEnum.PRODUCT_BUY_MATE_STATE_FAIL.getValue());
         if(ObjectUtil.isNotEmpty(mallProductBuy)){
             throw new FebsException("不可重复预约");
         }
@@ -95,7 +139,8 @@
         mallProductBuy.setState(ProductEnum.PRODUCT_BUY_ON_GOING.getValue());
         mallProductBuy.setMateState(ProductEnum.PRODUCT_BUY_MATE_STATE_FAIL.getValue());
         mallProductBuy.setNftTotal(mallProductNft.getPriceNft());
-        mallProductBuy.setNftAva(BigDecimal.ZERO);
+        mallProductBuy.setNftAva(mallProductNft.getPriceNft());
+//        mallProductBuy.setNftAva(BigDecimal.ZERO);
         mallProductBuyMapper.insert(mallProductBuy);
         //令牌 可用减少,冻结增加
         mallMemberAmount.setTokenAva(mallMemberAmount.getTokenAva().subtract(priceToken));
@@ -176,8 +221,9 @@
                 FlowTypeNewEnum.FCM_COIN.getValue(),
                 MoneyFlowTypeNewEnum.FCM_OUT_FEE.getDescrition());
 
-        mallMemberAmount.setTrendsNft(mallMemberAmount.getTrendsNft().add(nftCnt));
-        mallMemberAmountMapper.updateTrendsNftById(mallMemberAmount);
+        MallMemberAmount mallMemberAmountNft = mallMemberAmountMapper.selectByMemberId(memberId);
+        mallMemberAmountNft.setTrendsNft(mallMemberAmountNft.getTrendsNft().add(nftCnt));
+        mallMemberAmountMapper.updateTrendsNftById(mallMemberAmountNft);
         String orderNoNFT = MallUtils.getOrderNum("NFT");
         iMallMoneyFlowService.addMoneyFlow(
                 memberId,
@@ -248,8 +294,13 @@
         mallMemberAmount.setTrendsNft(mallMemberAmount.getTrendsNft().subtract(nftCnt));
         mallMemberAmountMapper.updateTrendsNftById(mallMemberAmount);
 
-        mallMemberAmount.setFrozenNft(mallMemberAmount.getFrozenNft().add(nftCntAva));
-        mallMemberAmountMapper.updateFrozenNftById(mallMemberAmount);
+        MallMemberAmount mallMemberAmountFcm = mallMemberAmountMapper.selectByMemberId(memberId);
+        mallMemberAmountFcm.setFcmCntAva(mallMemberAmountFcm.getFcmCntAva().subtract(fcmFeeCnt));
+        mallMemberAmountMapper.updateFcmCntAvaById(mallMemberAmountFcm);
+
+        MallMemberAmount mallMemberAmountFrozenNFT = mallMemberAmountMapper.selectByMemberId(memberId);
+        mallMemberAmountFrozenNFT.setFrozenNft(mallMemberAmountFrozenNFT.getFrozenNft().add(nftCntAva));
+        mallMemberAmountMapper.updateFrozenNftById(mallMemberAmountFrozenNFT);
         iMallMoneyFlowService.addMoneyFlow(
                 memberId,
                 nftCnt.negate(),
@@ -258,6 +309,14 @@
                 mallMember.getId(),
                 FlowTypeNewEnum.NFT.getValue(),
                 MoneyFlowTypeNewEnum.NFT_OUT.getDescrition());
+        iMallMoneyFlowService.addMoneyFlow(
+                memberId,
+                fcmFeeCnt.negate(),
+                MoneyFlowTypeNewEnum.NFT_OUT_FEE_FCM.getValue(),
+                orderNo,
+                mallMember.getId(),
+                FlowTypeNewEnum.FCM_COIN.getValue(),
+                MoneyFlowTypeNewEnum.NFT_OUT_FEE_FCM.getDescrition());
         iMallMoneyFlowService.addMoneyFlow(
                 memberId,
                 nftFee.negate(),
@@ -271,29 +330,53 @@
         return new FebsResponse().success();
     }
 
+    public static void main(String[] args) {
+        DateTime dateTime = DateUtil.parseTime("15:00:00");
+        DateTime dateTime2 = DateUtil.parseTime("19:00:00");
+        DateTime dateTime1 = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
+        System.out.println(dateTime);
+        System.out.println(dateTime1);
+        System.out.println(dateTime1.compareTo(dateTime));
+        System.out.println(dateTime1.compareTo(dateTime2));
+        System.out.println(dateTime1.compareTo(dateTime) >= 0 && dateTime1.compareTo(dateTime2) <= 0);
+    }
+
     @Override
     public FebsResponse orderList(ApiOrderListDto apiOrderListDto) {
         Long memberId = LoginUserUtil.getLoginUser().getId();
         List<ApiOrderListVo> objects = new ArrayList<>();
         Integer orderType = apiOrderListDto.getOrderType();
         apiOrderListDto.setMemberId(memberId);
-        //买单
-        if(2 == orderType){
-            IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize());
-            IPage<ApiOrderListVo> apiOrderListVoIPageBuy = mallProductBuyMapper.selectListInPage(page, apiOrderListDto);
-            if(CollUtil.isNotEmpty(apiOrderListVoIPageBuy.getRecords())){
-                for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageBuy.getRecords()){
-                    objects.add(apiOrderListVo);
+        DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
+        DataDictionaryCustom startTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.YU_YUE_START_TIME.getType(),
+                DataDictionaryEnum.YU_YUE_START_TIME.getCode()
+        );
+        DateTime startTime = DateUtil.parseTime(startTimeDic.getValue());
+        DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.YU_YUE_END_TIME.getType(),
+                DataDictionaryEnum.YU_YUE_END_TIME.getCode()
+        );
+        DateTime endTime = DateUtil.parseTime(endTimeDic.getValue());
+        if(nowTime.compareTo(startTime) >= 0 && nowTime.compareTo(endTime) <= 0){
+            //买单
+            if(2 == orderType){
+                IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize());
+                IPage<ApiOrderListVo> apiOrderListVoIPageBuy = mallProductBuyMapper.selectListInPage(page, apiOrderListDto);
+                if(CollUtil.isNotEmpty(apiOrderListVoIPageBuy.getRecords())){
+                    for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageBuy.getRecords()){
+                        objects.add(apiOrderListVo);
+                    }
                 }
             }
-        }
-        //卖单
-        if(1 == orderType){
-            IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize());
-            IPage<ApiOrderListVo> apiOrderListVoIPageSell = mallProductSellMapper.selectListInPage(page, apiOrderListDto);
-            if(CollUtil.isNotEmpty(apiOrderListVoIPageSell.getRecords())){
-                for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageSell.getRecords()){
-                    objects.add(apiOrderListVo);
+            //卖单
+            if(1 == orderType){
+                IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize());
+                IPage<ApiOrderListVo> apiOrderListVoIPageSell = mallProductSellMapper.selectListInPage(page, apiOrderListDto);
+                if(CollUtil.isNotEmpty(apiOrderListVoIPageSell.getRecords())){
+                    for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageSell.getRecords()){
+                        objects.add(apiOrderListVo);
+                    }
                 }
             }
         }

--
Gitblit v1.9.1