From 0d0a50195df058b5ce765e1791b14df545170b38 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Thu, 01 Sep 2022 14:25:25 +0800
Subject: [PATCH] 20220822

---
 src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java |   46 +++++++++++++++++++++-------------------------
 1 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java
index 9d16081..d23bbff 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MallMemberWithdrawServiceImpl.java
@@ -14,6 +14,7 @@
 import cc.mrbird.febs.mall.service.IMallMemberWithdrawService;
 import cc.mrbird.febs.mall.service.MallMemberService;
 import cc.mrbird.febs.mall.vo.CashOutSettingVo;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.crypto.SecureUtil;
 import com.alibaba.fastjson.JSONObject;
@@ -52,45 +53,40 @@
             throw new FebsException("支付密码错误");
         }
 
-        if (withdrawalDto.getAmount().compareTo(BigDecimal.valueOf(100)) < 0) {
-            throw new FebsException("最小提现金额为100");
-        }
-
-        MallMemberPayment payment = mallMemberPaymentMapper.selectByMemberId(memberId);
-        if (payment == null) {
-            throw new FebsException("未设置收款方式");
-        }
-
-        BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId);
-        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
-        if (profit != null) {
-            // 可提现
-            BigDecimal canMoney = wallet.getCommission().subtract(profit);
-
-            if(withdrawalDto.getAmount().compareTo(canMoney) > 0) {
-                throw new FebsException("提现金额不足");
-            }
-        }
 
         CashOutSettingVo cashOutSettingVo = new CashOutSettingVo();
         DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.CASHOUT_SETTING.getType(), DataDictionaryEnum.CASHOUT_SETTING.getCode());
         if (dic != null) {
             cashOutSettingVo = JSONObject.parseObject(dic.getValue(), CashOutSettingVo.class);
         }
+        DataDictionaryCustom withdrawalCnt = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.MEMBER_WITHDRAWAL_CNT.getType(), DataDictionaryEnum.MEMBER_WITHDRAWAL_CNT.getCode());
+        if (withdrawalDto.getAmount().compareTo(cashOutSettingVo.getMinCashOut()) < 0) {
+            throw new FebsException("最小提现金额为"+withdrawalCnt.getValue()+"元");
+        }
 
-        BigDecimal serviceFee = cashOutSettingVo.getServiceFee().multiply(BigDecimal.valueOf(0.01));
+        String openId = mallMember.getOpenId();
+        if(StrUtil.isEmpty(openId)){
+            throw new FebsException("没有绑定微信");
+        }
 
-        walletService.reduce(withdrawalDto.getAmount(), memberId, "commission");
-        String orderNo = MallUtils.getOrderNum("W");
+        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
+        if (ObjectUtil.isNotEmpty(wallet)) {
+            // 可提现
+            BigDecimal canMoney = wallet.getBalance();
+            if(withdrawalDto.getAmount().compareTo(canMoney) > 0) {
+                throw new FebsException("提现金额不足");
+            }
+        }
 
+        walletService.reduce(withdrawalDto.getAmount(), memberId, "balance");
+        String withdrawalNo = "TX."+MallUtils.getOrderNum();
         MallMemberWithdraw withdraw = new MallMemberWithdraw();
-        withdraw.setWithdrawNo(orderNo);
+        withdraw.setWithdrawNo(withdrawalNo);
         withdraw.setMemberId(memberId);
         withdraw.setAmount(withdrawalDto.getAmount());
         withdraw.setStatus(1);
-        withdraw.setAmountFee(serviceFee.multiply(withdrawalDto.getAmount()));
         this.baseMapper.insert(withdraw);
 
-        mallMemberService.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1, FlowTypeEnum.COMMISSION.getValue());
+        mallMemberService.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), withdrawalNo, null, null, null, 1, FlowTypeEnum.BALANCE.getValue());
     }
 }

--
Gitblit v1.9.1