|  | @@ -1,25 +1,26 @@
 | 
	
		
			
				|  |  |  package com.yonge.cooleshow.biz.dal.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.SysUserContractRecordDao;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.dto.req.AuthOperaReq;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.UserWithdrawalCallback;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.enums.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.sdk.WithdrawSdk;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.service.SysMessageService;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.service.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.constant.SysConfigConstant;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.UserBankCardDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.UserAccountRecordDto;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.req.WithdrawalReq;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.UserAccountRecord;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.service.SysConfigService;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.service.UserAccountService;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.UserAccountVo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.UserBankCardVo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.res.WithdrawalInfoRes;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.exception.BizException;
 | 
	
		
			
				|  |  | +import com.yonge.toolset.base.string.StringPool;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.util.StringUtil;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.payment.base.enums.TradeStatusEnum;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 | 
	
	
		
			
				|  | @@ -32,7 +33,6 @@ import com.yonge.cooleshow.biz.dal.entity.UserWithdrawal;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.UserWithdrawalVo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.search.TeacherWithdrawalSearch;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.UserWithdrawalDao;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.service.UserWithdrawalService;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
	
		
			
				|  | @@ -50,6 +50,8 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SysConfigService sysConfigService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | +    private SysUserService sysUserService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  |      private WithdrawSdk withdrawSdk;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SysMessageService sysMessageService;
 | 
	
	
		
			
				|  | @@ -94,14 +96,28 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public HttpResponseResult<Boolean> withdrawal(SysUser user, WithdrawalReq withdrawalReq) {
 | 
	
		
			
				|  |  | +        if (StringUtil.isEmpty(user.getIdCardNo())) {
 | 
	
		
			
				|  |  | +            return HttpResponseResult.failed("用户未实名认证");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //校验--提现开关
 | 
	
		
			
				|  |  | +        String withdrawalSwitch = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_SWITCH);
 | 
	
		
			
				|  |  | +        if (!YesOrNoEnum.YES.getCode().toString().equals(withdrawalSwitch)) {
 | 
	
		
			
				|  |  | +            return HttpResponseResult.failed("当前不允许提现");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //校验--判断今天提现次数
 | 
	
		
			
				|  |  | +        String withdrawalMaxCount = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_MAX_COUNT);
 | 
	
		
			
				|  |  | +        Integer count = getNowDayWithdrawalCount(user.getId());
 | 
	
		
			
				|  |  | +        if (count >= Integer.parseInt(withdrawalMaxCount)) {
 | 
	
		
			
				|  |  | +            return HttpResponseResult.failed("达到当天提现最大次数");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //校验--校验金额(金额不能小于手续费,手续费从提现金额里面扣除)
 | 
	
		
			
				|  |  |          BigDecimal withdrawalServiceFee = getWithdrawalServiceFee();
 | 
	
		
			
				|  |  | -        //校验金额
 | 
	
		
			
				|  |  | -        if (withdrawalReq.getAmountWithdrawal().floatValue() <= 0) {
 | 
	
		
			
				|  |  | +        BigDecimal actualAmount = withdrawalReq.getAmountWithdrawal().subtract(withdrawalServiceFee);
 | 
	
		
			
				|  |  | +        if (actualAmount.compareTo(BigDecimal.ZERO) <= 0) {
 | 
	
		
			
				|  |  |              return HttpResponseResult.failed("结算金额过小");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //获取用户结算金额
 | 
	
		
			
				|  |  | +        //获取用户可结算金额
 | 
	
		
			
				|  |  |          BigDecimal amountWithdrawal = getAmountUsable(user.getId());
 | 
	
		
			
				|  |  | -        //比较大小
 | 
	
		
			
				|  |  |          if (amountWithdrawal.compareTo(withdrawalReq.getAmountWithdrawal()) < 0) {
 | 
	
		
			
				|  |  |              return HttpResponseResult.failed("账户余额不足");
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -110,9 +126,13 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |          if (null == bankCardVo) {
 | 
	
		
			
				|  |  |              return HttpResponseResult.failed("未找到用户绑卡信息");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        //提现审核开关
 | 
	
		
			
				|  |  | +        String withdrawalAuthSwitch = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_AUTH_SWITCH);
 | 
	
		
			
				|  |  | +        //提现审核额度(小于该额度免审核提现)
 | 
	
		
			
				|  |  | +        String withdrawalAuthFee = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_AUTH_FEE);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //插入用户结算表
 | 
	
		
			
				|  |  | -        UserWithdrawal userWithdrawal = insertUserWithdrawal(user.getId(), withdrawalReq, bankCardVo, withdrawalServiceFee);
 | 
	
		
			
				|  |  | +        UserWithdrawal userWithdrawal = insertUserWithdrawal(user.getId(), withdrawalReq, bankCardVo, withdrawalServiceFee, withdrawalAuthSwitch, withdrawalAuthFee);
 | 
	
		
			
				|  |  |          //插入账户变更
 | 
	
		
			
				|  |  |          UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
 | 
	
		
			
				|  |  |                  user.getId(), withdrawalReq.getAmountWithdrawal(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
 | 
	
	
		
			
				|  | @@ -121,12 +141,23 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |          accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN);
 | 
	
		
			
				|  |  |          accountRecordDto.setSaveRecord(false);
 | 
	
		
			
				|  |  |          HttpResponseResult<UserAccountRecord> accountChange = userAccountService.accountChange(accountRecordDto);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          if (accountChange.getStatus()) {
 | 
	
		
			
				|  |  | -            //请求三方接口
 | 
	
		
			
				|  |  | -            withdrawSdk.withdraw(
 | 
	
		
			
				|  |  | -                    userWithdrawal.getId().toString(), bankCardVo.getName(), bankCardVo.getPhone(), user.getIdCardNo(),
 | 
	
		
			
				|  |  | -                    amountWithdrawal.multiply(new BigDecimal("100")).intValue(), bankCardVo.getBankCard(), null
 | 
	
		
			
				|  |  | -            );
 | 
	
		
			
				|  |  | +            if (YesOrNoEnum.NO.getCode().toString().equals(withdrawalAuthSwitch)
 | 
	
		
			
				|  |  | +                    || new BigDecimal(withdrawalAuthFee).compareTo(withdrawalReq.getAmountWithdrawal()) > 0) {
 | 
	
		
			
				|  |  | +                //不用审核的,需要请求三方
 | 
	
		
			
				|  |  | +                HttpResponseResult<Boolean> withdraw = withdrawSdk.withdraw(
 | 
	
		
			
				|  |  | +                        userWithdrawal.getId().toString(), bankCardVo.getName(), bankCardVo.getPhone(), user.getIdCardNo(),
 | 
	
		
			
				|  |  | +                        userWithdrawal.getActualAmount().multiply(new BigDecimal("100")).intValue(), bankCardVo.getBankCard(), null
 | 
	
		
			
				|  |  | +                );
 | 
	
		
			
				|  |  | +                if (withdraw.getStatus() && withdraw.getData()) {
 | 
	
		
			
				|  |  | +                    userWithdrawal.setTradeStatus(TradeStatusEnum.pending);
 | 
	
		
			
				|  |  | +                    updateById(userWithdrawal);
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    log.error("结算调用三方接口失败:user is {}, param is {}, res is {}", user.getId(), JSONObject.toJSONString(withdrawalReq), withdraw);
 | 
	
		
			
				|  |  | +                    throw new BizException("结算失败");
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              return HttpResponseResult.succeed(true);
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              throw new BizException("结算失败");
 | 
	
	
		
			
				|  | @@ -135,6 +166,79 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public HttpResponseResult<Boolean> doAuth(AuthOperaReq authOperaReq, SysUser sysUser) {
 | 
	
		
			
				|  |  | +        Long[] ids = StringUtil.toLongArray(StringPool.COMMA, authOperaReq.getId());
 | 
	
		
			
				|  |  | +        for (Long id : ids) {
 | 
	
		
			
				|  |  | +            UserWithdrawalVo build = detail(id);
 | 
	
		
			
				|  |  | +            if (!AuthStatusEnum.DOING.equals(build.getAuthStatus())) {
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            build.setAuthStatus(authOperaReq.getPass() ? AuthStatusEnum.PASS : AuthStatusEnum.UNPASS);
 | 
	
		
			
				|  |  | +            build.setReason(authOperaReq.getReason());
 | 
	
		
			
				|  |  | +            build.setAuthUserId(sysUser.getId());
 | 
	
		
			
				|  |  | +            build.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //请求三方
 | 
	
		
			
				|  |  | +            SysUser withdrawalUser = sysUserService.findUserById(build.getUserId());
 | 
	
		
			
				|  |  | +            Boolean flag = false;
 | 
	
		
			
				|  |  | +            if (authOperaReq.getPass()) {
 | 
	
		
			
				|  |  | +                //请求三方接口
 | 
	
		
			
				|  |  | +                HttpResponseResult<Boolean> withdraw = withdrawSdk.withdraw(
 | 
	
		
			
				|  |  | +                        build.getId().toString(), build.getBankName(), build.getPhone(), withdrawalUser.getIdCardNo(),
 | 
	
		
			
				|  |  | +                        build.getActualAmount().multiply(new BigDecimal("100")).intValue(), build.getBankCard(), null
 | 
	
		
			
				|  |  | +                );
 | 
	
		
			
				|  |  | +                if (withdraw.getStatus() && withdraw.getData()) {
 | 
	
		
			
				|  |  | +                    build.setTradeStatus(TradeStatusEnum.pending);
 | 
	
		
			
				|  |  | +                    flag = true;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //修改系统中账户
 | 
	
		
			
				|  |  | +            if (!authOperaReq.getPass() || !flag) {
 | 
	
		
			
				|  |  | +                //审核不通过,账户解冻
 | 
	
		
			
				|  |  | +                UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
 | 
	
		
			
				|  |  | +                        build.getUserId(), build.getAmount(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
 | 
	
		
			
				|  |  | +                        build.getId(), "老师结算", null
 | 
	
		
			
				|  |  | +                );
 | 
	
		
			
				|  |  | +                accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN_BACK);
 | 
	
		
			
				|  |  | +                accountRecordDto.setSaveRecord(false);
 | 
	
		
			
				|  |  | +                userAccountService.accountChange(accountRecordDto);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            updateById(build);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return HttpResponseResult.succeed();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public HttpResponseResult<Boolean> transferAccount(AuthOperaReq authOperaReq, SysUser user) {
 | 
	
		
			
				|  |  | +        UserWithdrawalVo detail = detail(Long.parseLong(authOperaReq.getId()));
 | 
	
		
			
				|  |  | +        if (detail == null) {
 | 
	
		
			
				|  |  | +            return HttpResponseResult.failed("提现记录不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (!detail.getAuthStatus().equals(AuthStatusEnum.PASS)) {
 | 
	
		
			
				|  |  | +            return HttpResponseResult.failed("提现记录未审核");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (detail.getTradeStatus().equals(TradeStatusEnum.succeeded)) {
 | 
	
		
			
				|  |  | +            return HttpResponseResult.failed("提现已经交易成功");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //不用审核的,需要请求三方
 | 
	
		
			
				|  |  | +        HttpResponseResult<Boolean> withdraw = withdrawSdk.withdraw(
 | 
	
		
			
				|  |  | +                detail.getId().toString(), detail.getBankName(), detail.getPhone(), user.getIdCardNo(),
 | 
	
		
			
				|  |  | +                detail.getActualAmount().multiply(new BigDecimal("100")).intValue(), detail.getBankCard(), null
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +        if (withdraw.getStatus() && withdraw.getData()) {
 | 
	
		
			
				|  |  | +            detail.setTradeStatus(TradeStatusEnum.pending);
 | 
	
		
			
				|  |  | +            updateById(detail);
 | 
	
		
			
				|  |  | +            return HttpResponseResult.succeed(true);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            log.error("结算调用三方接口失败:user is {}, data is {}, res is {}", user.getId(), JSONObject.toJSONString(detail), withdraw);
 | 
	
		
			
				|  |  | +            throw new BizException("结算失败");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public void callback(UserWithdrawalCallback callback, String jsonStr) {
 | 
	
		
			
				|  |  |          if (StringUtil.isEmpty(callback.getOuterOrderNo()) ||
 | 
	
		
			
				|  |  |                  StringUtil.isEmpty(callback.getStatus())) {
 | 
	
	
		
			
				|  | @@ -144,12 +248,12 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |          if (null == detail) {
 | 
	
		
			
				|  |  |              throw new BizException("参数异常,未找到交易记录,param is {}", jsonStr);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        if (!TradeStatusEnum.pending.equals(detail.getStatus())) {
 | 
	
		
			
				|  |  | +        if (!TradeStatusEnum.pending.equals(detail.getTradeStatus())) {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if ("1".equals(callback.getStatus())) {
 | 
	
		
			
				|  |  |              //交易成功
 | 
	
		
			
				|  |  | -            detail.setStatus(TradeStatusEnum.succeeded);
 | 
	
		
			
				|  |  | +            detail.setTradeStatus(TradeStatusEnum.succeeded);
 | 
	
		
			
				|  |  |              detail.setTransNo(callback.getOrderNo());
 | 
	
		
			
				|  |  |              BigDecimal actualAmount = new BigDecimal(callback.getActualAmount());
 | 
	
		
			
				|  |  |              detail.setActualAmount(actualAmount.divide(new BigDecimal("100")));
 | 
	
	
		
			
				|  | @@ -167,18 +271,18 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |              successSend(detail.getUserId(), detail.getPhone());
 | 
	
		
			
				|  |  |          } else if ("2".equals(callback.getStatus())) {
 | 
	
		
			
				|  |  |              //交易失败
 | 
	
		
			
				|  |  | -            detail.setStatus(TradeStatusEnum.failed);
 | 
	
		
			
				|  |  | +            detail.setTradeStatus(TradeStatusEnum.failed);
 | 
	
		
			
				|  |  |              detail.setErrorCode(callback.getErrorCode());
 | 
	
		
			
				|  |  |              detail.setErrorMsg(callback.getErrorMsg());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              //结算失败,账户解冻
 | 
	
		
			
				|  |  | -            UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
 | 
	
		
			
				|  |  | +            /*UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
 | 
	
		
			
				|  |  |                      detail.getUserId(), detail.getAmount(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
 | 
	
		
			
				|  |  |                      detail.getId(), "老师结算", null
 | 
	
		
			
				|  |  |              );
 | 
	
		
			
				|  |  |              accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN_BACK);
 | 
	
		
			
				|  |  |              accountRecordDto.setSaveRecord(false);
 | 
	
		
			
				|  |  | -            userAccountService.accountChange(accountRecordDto);
 | 
	
		
			
				|  |  | +            userAccountService.accountChange(accountRecordDto);*/
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -191,6 +295,16 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |          userContractRecordDao.contractCallbackUpdate(status, serialNo, url, errMsg);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 查询用户今天发起的提现次数
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param userId
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private Integer getNowDayWithdrawalCount(Long userId) {
 | 
	
		
			
				|  |  | +        return baseMapper.getNowDayWithdrawalCount(userId);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      private void successSend(Long userId, String phone) {
 | 
	
		
			
				|  |  |          Map<Long, String> receivers = new HashMap<>();
 | 
	
		
			
				|  |  |          receivers.put(userId, phone);
 | 
	
	
		
			
				|  | @@ -202,7 +316,86 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -   /* @Override
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /***
 | 
	
		
			
				|  |  | +     * 入结算表
 | 
	
		
			
				|  |  | +     * @author liweifan
 | 
	
		
			
				|  |  | +     * @param: userId
 | 
	
		
			
				|  |  | +     * @param: withdrawalReq
 | 
	
		
			
				|  |  | +     * @param: bankCardVo
 | 
	
		
			
				|  |  | +     * @param: userAccountRecord
 | 
	
		
			
				|  |  | +     * @updateTime 2022/4/7 16:46
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private UserWithdrawal insertUserWithdrawal(Long userId, WithdrawalReq withdrawalReq,
 | 
	
		
			
				|  |  | +                                                UserBankCardVo bankCardVo, BigDecimal withdrawalServiceFee,
 | 
	
		
			
				|  |  | +                                                String withdrawalAuthSwitch, String withdrawalAuthFee) {
 | 
	
		
			
				|  |  | +        UserWithdrawal userWithdrawal = new UserWithdrawal();
 | 
	
		
			
				|  |  | +        userWithdrawal.setUserId(userId);
 | 
	
		
			
				|  |  | +        userWithdrawal.setAmount(withdrawalReq.getAmountWithdrawal());
 | 
	
		
			
				|  |  | +        userWithdrawal.setPlantformFee(withdrawalServiceFee);
 | 
	
		
			
				|  |  | +        userWithdrawal.setActualAmount(withdrawalReq.getAmountWithdrawal().subtract(withdrawalServiceFee));
 | 
	
		
			
				|  |  | +        userWithdrawal.setBankCardId(bankCardVo.getId());
 | 
	
		
			
				|  |  | +        userWithdrawal.setOpenType(OpenContractEnum.lingxinpay.getCode());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (YesOrNoEnum.NO.getCode().toString().equals(withdrawalAuthSwitch)) {
 | 
	
		
			
				|  |  | +            userWithdrawal.setAuthStatus(AuthStatusEnum.PASS);
 | 
	
		
			
				|  |  | +            userWithdrawal.setAuthUserId(0L);
 | 
	
		
			
				|  |  | +            userWithdrawal.setReason("系统审核通过");
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            if (new BigDecimal(withdrawalAuthFee).compareTo(withdrawalReq.getAmountWithdrawal()) > 0) {
 | 
	
		
			
				|  |  | +                userWithdrawal.setAuthStatus(AuthStatusEnum.PASS);
 | 
	
		
			
				|  |  | +                userWithdrawal.setAuthUserId(0L);
 | 
	
		
			
				|  |  | +                userWithdrawal.setReason("系统审核通过");
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                userWithdrawal.setAuthStatus(AuthStatusEnum.DOING);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        userWithdrawal.setCreateTime(new Date());
 | 
	
		
			
				|  |  | +        userWithdrawal.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +        baseMapper.insert(userWithdrawal);
 | 
	
		
			
				|  |  | +        return userWithdrawal;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /***
 | 
	
		
			
				|  |  | +     * 获取平台结算服务费
 | 
	
		
			
				|  |  | +     * @author liweifan
 | 
	
		
			
				|  |  | +     * @param: userId
 | 
	
		
			
				|  |  | +     * @updateTime 2022/4/7 14:59
 | 
	
		
			
				|  |  | +     * @return: java.math.BigDecimal
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private BigDecimal getWithdrawalServiceFee() {
 | 
	
		
			
				|  |  | +        BigDecimal withdrawalServiceFee;
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            String configValue = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_SERVICE_FEE);
 | 
	
		
			
				|  |  | +            withdrawalServiceFee = new BigDecimal(configValue);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            e.printStackTrace();
 | 
	
		
			
				|  |  | +            log.info("获取平台配置失败 key={}", SysConfigConstant.WITHDRAWAL_SERVICE_FEE);
 | 
	
		
			
				|  |  | +            withdrawalServiceFee = new BigDecimal(0);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return withdrawalServiceFee;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /***
 | 
	
		
			
				|  |  | +     * 获取用户可结算金额
 | 
	
		
			
				|  |  | +     * @author liweifan
 | 
	
		
			
				|  |  | +     * @param: userId
 | 
	
		
			
				|  |  | +     * @param: withdrawalServiceFee
 | 
	
		
			
				|  |  | +     * @updateTime 2022/4/7 15:02
 | 
	
		
			
				|  |  | +     * @return: java.math.BigDecimal
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private BigDecimal getAmountUsable(Long userId) {
 | 
	
		
			
				|  |  | +        //查询用户账户余额
 | 
	
		
			
				|  |  | +        UserAccountVo detail = userAccountService.detail(userId);
 | 
	
		
			
				|  |  | +        BigDecimal subtract = detail.getAmountUsable();
 | 
	
		
			
				|  |  | +        if (subtract.intValue() < 0) {
 | 
	
		
			
				|  |  | +            subtract = new BigDecimal(0);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return subtract;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +       /* @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public void importExcel(List<ExcelDataReaderProperty<UserWithdrawalExport>> dataList, Long userId) {
 | 
	
		
			
				|  |  |          List<ErrMsg> errMsgList = new ArrayList<>();
 | 
	
	
		
			
				|  | @@ -290,66 +483,4 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 | 
	
		
			
				|  |  |              baseMapper.updateById(userWithdrawal);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }*/
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /***
 | 
	
		
			
				|  |  | -     * 入结算表
 | 
	
		
			
				|  |  | -     * @author liweifan
 | 
	
		
			
				|  |  | -     * @param: userId
 | 
	
		
			
				|  |  | -     * @param: withdrawalReq
 | 
	
		
			
				|  |  | -     * @param: bankCardVo
 | 
	
		
			
				|  |  | -     * @param: userAccountRecord
 | 
	
		
			
				|  |  | -     * @updateTime 2022/4/7 16:46
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private UserWithdrawal insertUserWithdrawal(Long userId, WithdrawalReq withdrawalReq,
 | 
	
		
			
				|  |  | -                                                UserBankCardVo bankCardVo, BigDecimal withdrawalServiceFee) {
 | 
	
		
			
				|  |  | -        UserWithdrawal userWithdrawal = new UserWithdrawal();
 | 
	
		
			
				|  |  | -        userWithdrawal.setUserId(userId);
 | 
	
		
			
				|  |  | -        userWithdrawal.setAmount(withdrawalReq.getAmountWithdrawal());
 | 
	
		
			
				|  |  | -        userWithdrawal.setPlantformFee(withdrawalServiceFee);
 | 
	
		
			
				|  |  | -        userWithdrawal.setBankCardId(bankCardVo.getId());
 | 
	
		
			
				|  |  | -        userWithdrawal.setOpenType(OpenContractEnum.lingxinpay.getCode());
 | 
	
		
			
				|  |  | -        userWithdrawal.setStatus(TradeStatusEnum.pending);
 | 
	
		
			
				|  |  | -        userWithdrawal.setCreateTime(new Date());
 | 
	
		
			
				|  |  | -        userWithdrawal.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | -        baseMapper.insert(userWithdrawal);
 | 
	
		
			
				|  |  | -        return userWithdrawal;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /***
 | 
	
		
			
				|  |  | -     * 获取平台结算服务费
 | 
	
		
			
				|  |  | -     * @author liweifan
 | 
	
		
			
				|  |  | -     * @param: userId
 | 
	
		
			
				|  |  | -     * @updateTime 2022/4/7 14:59
 | 
	
		
			
				|  |  | -     * @return: java.math.BigDecimal
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private BigDecimal getWithdrawalServiceFee() {
 | 
	
		
			
				|  |  | -        BigDecimal withdrawalServiceFee;
 | 
	
		
			
				|  |  | -        try {
 | 
	
		
			
				|  |  | -            String configValue = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_SERVICE_FEE);
 | 
	
		
			
				|  |  | -            withdrawalServiceFee = new BigDecimal(configValue);
 | 
	
		
			
				|  |  | -        } catch (Exception e) {
 | 
	
		
			
				|  |  | -            e.printStackTrace();
 | 
	
		
			
				|  |  | -            log.info("获取平台配置失败 key={}", SysConfigConstant.WITHDRAWAL_SERVICE_FEE);
 | 
	
		
			
				|  |  | -            withdrawalServiceFee = new BigDecimal(0);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return withdrawalServiceFee;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /***
 | 
	
		
			
				|  |  | -     * 获取用户可结算金额
 | 
	
		
			
				|  |  | -     * @author liweifan
 | 
	
		
			
				|  |  | -     * @param: userId
 | 
	
		
			
				|  |  | -     * @param: withdrawalServiceFee
 | 
	
		
			
				|  |  | -     * @updateTime 2022/4/7 15:02
 | 
	
		
			
				|  |  | -     * @return: java.math.BigDecimal
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private BigDecimal getAmountUsable(Long userId) {
 | 
	
		
			
				|  |  | -        //查询用户账户余额
 | 
	
		
			
				|  |  | -        UserAccountVo detail = userAccountService.detail(userId);
 | 
	
		
			
				|  |  | -        BigDecimal subtract = detail.getAmountUsable();
 | 
	
		
			
				|  |  | -        if (subtract.intValue() < 0) {
 | 
	
		
			
				|  |  | -            subtract = new BigDecimal(0);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return subtract;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  }
 |