From 34c755eb76b677201cadb2acb8ed5fff1f96dc27 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Tue, 23 Jan 2024 14:06:34 +0800
Subject: [PATCH] 发票

---
 src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java |  131 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 131 insertions(+), 0 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 1d12048..7b39e38 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
@@ -699,4 +699,135 @@
         ApiOrderBuyRecordInfoVo apiOrderBuyRecordInfoVo = mallProductBuyRecordMapper.selectByBuyRecordId(productBuyRecordId);
         return new FebsResponse().success().data(apiOrderBuyRecordInfoVo);
     }
+
+    @Override
+    @Transactional
+    public FebsResponse transGfd(ApiTransGfdDto transGfdDto) {
+        Long memberId = LoginUserUtil.getLoginUser().getId();
+        BigDecimal cnt = transGfdDto.getCnt();//兑换数量
+
+        MallMember mallMember = memberMapper.selectById(memberId);
+        String tradePassword = SecureUtil.md5(transGfdDto.getTradePassword());
+        Boolean aBoolean = operationPermissionMemberFrozen(memberId);
+        if(aBoolean){
+            throw new FebsException("用户已冻结");
+        }
+        if(!tradePassword.equals(mallMember.getTradePassword())){
+            throw new FebsException("请输入正确的交易密码");
+        }
+        MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId);
+        Integer type = transGfdDto.getType();
+        String orderNo = MallUtils.getOrderNum("GSD");
+        if(1 == type){//NFT兑换GFD
+            BigDecimal trendsNft = mallMemberAmount.getTrendsNft();
+            if(BigDecimal.ZERO.compareTo(trendsNft) >= 0){
+                throw new FebsException("NFT不足");
+            }
+            if(cnt.compareTo(trendsNft) > 0){
+                throw new FebsException("NFT不足");
+            }
+            mallMemberAmount.setTrendsNft(trendsNft.subtract(cnt));
+            mallMemberAmount.setGsd(mallMemberAmount.getGsd().add(cnt));
+            mallMemberAmountMapper.updateTrendsNftAndGsdById(mallMemberAmount);
+            iMallMoneyFlowService.addMoneyFlow(
+                    memberId,
+                    cnt,
+                    MoneyFlowTypeNewEnum.NFT_GSD.getValue(),
+                    orderNo,
+                    mallMember.getId(),
+                    FlowTypeNewEnum.GSD.getValue(),
+                    MoneyFlowTypeNewEnum.NFT_GSD.getDescrition());
+
+        }
+        if(2 == type){//GFA兑换GFD
+            BigDecimal fcmCntAva = mallMemberAmount.getFcmCntAva();
+            if(BigDecimal.ZERO.compareTo(fcmCntAva) >= 0){
+                throw new FebsException("代币不足");
+            }
+            if(cnt.compareTo(fcmCntAva) > 0){
+                throw new FebsException("代币不足");
+            }
+            DataDictionaryCustom fcmPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                    DataDictionaryEnum.FCM_PRICE.getType(),
+                    DataDictionaryEnum.FCM_PRICE.getCode());
+            BigDecimal fcmPrice = ObjectUtil.isEmpty(fcmPriceDic) ? new BigDecimal(2) : new BigDecimal(fcmPriceDic.getValue());
+            BigDecimal gsdCnt = fcmPrice.multiply(cnt);
+            mallMemberAmount.setFcmCntAva(fcmCntAva.subtract(cnt));
+            mallMemberAmount.setGsd(mallMemberAmount.getGsd().add(gsdCnt));
+            mallMemberAmountMapper.updateFcmCntAvaAndGsdById(mallMemberAmount);
+            iMallMoneyFlowService.addMoneyFlow(
+                    memberId,
+                    cnt,
+                    MoneyFlowTypeNewEnum.GFA_GSD.getValue(),
+                    orderNo,
+                    mallMember.getId(),
+                    FlowTypeNewEnum.GSD.getValue(),
+                    MoneyFlowTypeNewEnum.GFA_GSD.getDescrition());
+
+        }
+        return new FebsResponse().success();
+    }
+
+    @Override
+    @Transactional
+    public FebsResponse gfdTrans(ApiGfdTransDto transGfdDto) {
+        Long memberId = LoginUserUtil.getLoginUser().getId();
+        BigDecimal cnt = transGfdDto.getCnt();//兑换数量
+
+        MallMember mallMember = memberMapper.selectById(memberId);
+        String tradePassword = SecureUtil.md5(transGfdDto.getTradePassword());
+        Boolean aBoolean = operationPermissionMemberFrozen(memberId);
+        if(aBoolean){
+            throw new FebsException("用户已冻结");
+        }
+        if(!tradePassword.equals(mallMember.getTradePassword())){
+            throw new FebsException("请输入正确的交易密码");
+        }
+        MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId);
+        BigDecimal gsd = mallMemberAmount.getGsd();
+        if(BigDecimal.ZERO.compareTo(gsd) >= 0){
+            throw new FebsException("积分不足");
+        }
+        if(cnt.compareTo(gsd) > 0){
+            throw new FebsException("积分不足");
+        }
+        Integer type = transGfdDto.getType();
+        String orderNo = MallUtils.getOrderNum("GSD");
+        if(1 == type){//GFD兑换NFT
+            BigDecimal trendsNft = mallMemberAmount.getTrendsNft();
+            mallMemberAmount.setTrendsNft(trendsNft.add(cnt));
+            mallMemberAmount.setGsd(mallMemberAmount.getGsd().subtract(cnt));
+            mallMemberAmountMapper.updateTrendsNftAndGsdById(mallMemberAmount);
+            iMallMoneyFlowService.addMoneyFlow(
+                    memberId,
+                    cnt,
+                    MoneyFlowTypeNewEnum.GSD_NFT.getValue(),
+                    orderNo,
+                    mallMember.getId(),
+                    FlowTypeNewEnum.GSD.getValue(),
+                    MoneyFlowTypeNewEnum.GSD_NFT.getDescrition());
+
+        }
+        if(2 == type){//GFD兑换GFA
+            BigDecimal fcmCntAva = mallMemberAmount.getFcmCntAva();
+            DataDictionaryCustom fcmPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                    DataDictionaryEnum.FCM_PRICE.getType(),
+                    DataDictionaryEnum.FCM_PRICE.getCode());
+            BigDecimal fcmPrice = ObjectUtil.isEmpty(fcmPriceDic) ? new BigDecimal(2) : new BigDecimal(fcmPriceDic.getValue());
+            BigDecimal gsdCnt = cnt.divide(fcmPrice,2,BigDecimal.ROUND_DOWN);
+            mallMemberAmount.setFcmCntAva(fcmCntAva.add(gsdCnt));
+            mallMemberAmount.setGsd(mallMemberAmount.getGsd().subtract(cnt));
+            mallMemberAmountMapper.updateFcmCntAvaAndGsdById(mallMemberAmount);
+            iMallMoneyFlowService.addMoneyFlow(
+                    memberId,
+                    cnt,
+                    MoneyFlowTypeNewEnum.GSD_GFA.getValue(),
+                    orderNo,
+                    mallMember.getId(),
+                    FlowTypeNewEnum.GSD.getValue(),
+                    MoneyFlowTypeNewEnum.GSD_GFA.getDescrition());
+
+        }
+        return new FebsResponse().success();
+    }
 }

--
Gitblit v1.9.1