fix
Hentua
2023-06-04 9cf47e10044ecb29669dec48d8b649b4fb46898f
src/main/java/cc/mrbird/febs/mall/service/impl/ScoreServiceImpl.java
@@ -18,6 +18,7 @@
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.service.IScoreService;
import cc.mrbird.febs.mall.vo.*;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
@@ -26,6 +27,7 @@
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -35,8 +37,10 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author wzy
@@ -58,6 +62,7 @@
    private final MallMemberBankMapper mallMemberBankMapper;
    private final MallMemberWithdrawMapper mallMemberWithdrawMapper;
    private final IApiMallMemberService mallMemberService;
    private final MallMoneyFlowMapper mallMoneyFlowMapper;
    @Override
    public ScoreSignVo scoreSign() {
@@ -78,7 +83,7 @@
        DataDictionaryCustom signScpreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SCORE_SIGN_SETTING.getType(), DataDictionaryEnum.SCORE_SIGN_SETTING.getCode());
        if (signScpreDic != null) {
            scoreSign.setSetting(Integer.parseInt(signScpreDic.getValue()));
            scoreSign.setSetting(JSONObject.parseObject(signScpreDic.getValue(), ScoreSettingDto.class));
        }
        return scoreSign;
    }
@@ -274,7 +279,6 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void withdrawal(WithdrawalDto withdrawalDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        MallMember mallMember = mallMemberMapper.selectById(memberId);
        if (StrUtil.isBlank(mallMember.getTradePassword())) {
@@ -292,7 +296,7 @@
        }
        if (withdrawalDto.getAmount().compareTo(cashOutSettingVo.getMinCashOut()) < 0) {
            throw new FebsException("最小提现金额为"+cashOutSettingVo.getMinCashOut().setScale(2,BigDecimal.ROUND_DOWN));
            throw new FebsException("最小提现金额为"+cashOutSettingVo.getMinCashOut().setScale(2, RoundingMode.DOWN));
        }
        MallMemberBank mallMemberBank = mallMemberBankMapper.selectById(withdrawalDto.getBankId());
@@ -301,14 +305,24 @@
        }
        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
        // 可提现
        BigDecimal canMoney = wallet.getVoucherAmount();
        BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId);
        BigDecimal canMoney = wallet.getCommission();
        if (profit != null) {
            if(canMoney.compareTo(BigDecimal.ZERO) > 0) {
                canMoney = canMoney.subtract(profit);
            }
        }
        if(withdrawalDto.getAmount().compareTo(canMoney) > 0) {
            throw new FebsException("金额不足");
        }
        walletService.reduce(withdrawalDto.getAmount(), memberId, "voucherAmount");
        int flag = walletService.reduce(withdrawalDto.getAmount(), memberId, "commission");
        if (flag == 2) {
            throw new FebsException("请刷新页面后重新提现");
        }
        String orderNo = MallUtils.getOrderNum("W");
        MallMemberWithdraw withdraw = new MallMemberWithdraw();
@@ -317,11 +331,10 @@
        withdraw.setAmount(withdrawalDto.getAmount());
        withdraw.setStatus(1);
        withdraw.setAmountFee(BigDecimal.ZERO);
        withdraw.setRemark(AppContants.MEMBER_WITHDRAW_VOUCHER_AMOUNT);
        withdraw.setWtihdrawTypeId(mallMemberBank.getId());
        mallMemberWithdrawMapper.insert(withdraw);
        mallMemberService.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1, FlowTypeEnum.VOUCHER_AMOUNT.getValue());
        mallMemberService.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1, FlowTypeEnum.COMMISSION.getValue());
    }
    @Override
@@ -403,6 +416,25 @@
                break;
        }
        MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(member.getId());
        if (wallet.getPrizeScore().compareTo(new BigDecimal(scoreSetting.getMostSignIn())) > 0) {
            throw new FebsException("积分达到上限");
        }
        LambdaQueryWrapper<MallScoreSignRecord> hasSignQuery = new LambdaQueryWrapper<>();
        hasSignQuery.le(MallScoreSignRecord::getSignTime, DateUtil.endOfDay(DateUtil.endOfMonth(new Date())));
        hasSignQuery.gt(MallScoreSignRecord::getSignTime, DateUtil.beginOfDay(DateUtil.beginOfMonth(new Date())));
        hasSignQuery.eq(MallScoreSignRecord::getMemberId, member.getId());
        List<MallScoreSignRecord> hasSignTotalList = mallScoreSignRecordMapper.selectList(hasSignQuery);
        if (CollUtil.isNotEmpty(hasSignTotalList)) {
            int totalScore = hasSignTotalList.stream().mapToInt(MallScoreSignRecord::getScore).sum();
            if (totalScore + mallScoreSignRecord.getScore() > scoreSetting.getMostSignIn()) {
//                throw new FebsException("达到当月积分上限");
                mallScoreSignRecord.setScore(scoreSetting.getMostSignIn() - totalScore);
            }
        }
        mallScoreSignRecord.setMemberId(member.getId());
        mallScoreSignRecord.setTotalCnt(days);
        mallScoreSignRecord.setSignTime(new Date());