package cc.mrbird.febs.mall.service.impl;
|
|
import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
|
import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
|
import cc.mrbird.febs.common.enumerates.MallMoneyFlowTypeEnum;
|
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
|
import cc.mrbird.febs.common.exception.FebsException;
|
import cc.mrbird.febs.common.utils.LoginUserUtil;
|
import cc.mrbird.febs.common.utils.MallUtils;
|
import cc.mrbird.febs.mall.dto.WithdrawalDto;
|
import cc.mrbird.febs.mall.entity.*;
|
import cc.mrbird.febs.mall.mapper.*;
|
import cc.mrbird.febs.mall.service.*;
|
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;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.math.BigDecimal;
|
|
/**
|
* @author wzy
|
* @date 2022-05-05
|
**/
|
@Slf4j
|
@Service
|
@RequiredArgsConstructor
|
public class MallMemberWithdrawServiceImpl extends ServiceImpl<MallMemberWithdrawMapper, MallMemberWithdraw> implements IMallMemberWithdrawService {
|
|
private final IApiMallMemberService mallMemberService;
|
private final MallMoneyFlowMapper mallMoneyFlowMapper;
|
private final MallMemberWalletMapper mallMemberWalletMapper;
|
private final IApiMallMemberWalletService memberWalletService;
|
private final MallMemberPaymentMapper mallMemberPaymentMapper;
|
private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
|
private final MallMemberBankMapper mallMemberBankMapper;
|
private final IMallMoneyFlowService mallMoneyFlowService;
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void withdrawal(WithdrawalDto withdrawalDto) {
|
Long memberId = LoginUserUtil.getLoginUser().getId();
|
MallMember mallMember = mallMemberService.getById(memberId);
|
if (StrUtil.isBlank(mallMember.getTradePassword())) {
|
throw new FebsException("未设置支付密码");
|
}
|
|
if (!mallMember.getTradePassword().equals(SecureUtil.md5(withdrawalDto.getTradePwd()))) {
|
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);
|
}
|
BigDecimal minCashOut = cashOutSettingVo.getMinCashOut();
|
if(withdrawalDto.getAmount().compareTo(minCashOut) < 0){
|
throw new FebsException("提现金额最小为"+minCashOut);
|
}
|
|
if (withdrawalDto.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
throw new FebsException("请输入正确的提现金额");
|
}
|
|
if (withdrawalDto.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
throw new FebsException("请输入正确的提现金额");
|
}
|
if(ObjectUtil.isEmpty(withdrawalDto.getBankNo())){
|
throw new FebsException("请输入地址");
|
}
|
|
BigDecimal serviceFee = cashOutSettingVo.getServiceFee();
|
String orderNo = MallUtils.getOrderNum("W");
|
//减少用户余额
|
memberWalletService.reduce(withdrawalDto.getAmount(), memberId, "balance");
|
//生成提现记录
|
MallMemberWithdraw withdraw = new MallMemberWithdraw();
|
withdraw.setWithdrawNo(orderNo);
|
withdraw.setMemberId(memberId);
|
withdraw.setAmount(withdrawalDto.getAmount());
|
withdraw.setStatus(1);
|
withdraw.setAmountFee(serviceFee);
|
withdraw.setRemark(withdrawalDto.getBankNo());
|
// withdraw.setWtihdrawTypeId(mallMemberBank.getId());
|
this.baseMapper.insert(withdraw);
|
//生成提现流水记录
|
Long subsidyAmountFlowId = mallMoneyFlowService.addMoneyFlow(
|
memberId,
|
orderNo,
|
withdrawalDto.getAmount().negate(),
|
MallMoneyFlowTypeEnum.WITHDRAW.getCode(),
|
MallMoneyFlow.STATUS_ING,
|
MallMoneyFlow.IS_RETURN_Y,
|
mallMember.getId(),
|
FlowTypeEnum.BALANCE.getValue(),
|
MallMoneyFlowTypeEnum.WITHDRAW.getName()
|
);
|
}
|
}
|