|
@@ -2,16 +2,19 @@ package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
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.dto.excel.UserWithdrawalExport;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.FrozenTypeEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.UserWithdrawalCallback;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.props.WithdrawalProperties;
|
|
|
+import com.yonge.cooleshow.biz.dal.sdk.WithdrawSdk;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.TeacherService;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.TeacherVo;
|
|
|
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.enums.AccountBizTypeEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.AuthStatusEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.InOrOutEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.service.SysConfigService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.UserAccountService;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.UserAccountVo;
|
|
@@ -27,6 +30,7 @@ import com.yonge.toolset.utils.string.ValueUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.core.parameters.P;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.UserWithdrawal;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.UserWithdrawalVo;
|
|
@@ -52,7 +56,10 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
private UserAccountService userAccountService;
|
|
|
@Autowired
|
|
|
private SysConfigService sysConfigService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private WithdrawalProperties withdrawalProperties;
|
|
|
+ @Autowired
|
|
|
+ private WithdrawSdk withdrawSdk;
|
|
|
|
|
|
@Override
|
|
|
public UserWithdrawalVo detail(Long id) {
|
|
@@ -91,34 +98,40 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public HttpResponseResult<Boolean> withdrawal(Long userId, WithdrawalReq withdrawalReq) {
|
|
|
+ public HttpResponseResult<Boolean> withdrawal(SysUser user, WithdrawalReq withdrawalReq) {
|
|
|
BigDecimal withdrawalServiceFee = getWithdrawalServiceFee();
|
|
|
//校验金额
|
|
|
if (withdrawalReq.getAmountWithdrawal().subtract(withdrawalServiceFee).floatValue() < 0) {
|
|
|
return HttpResponseResult.failed("提现金额过小");
|
|
|
}
|
|
|
//获取用户提现金额
|
|
|
- BigDecimal amountWithdrawal = getAmountUsable(userId);
|
|
|
+ BigDecimal amountWithdrawal = getAmountUsable(user.getId());
|
|
|
//比较大小
|
|
|
if (amountWithdrawal.compareTo(withdrawalReq.getAmountWithdrawal()) < 0) {
|
|
|
return HttpResponseResult.failed("账户余额不足");
|
|
|
}
|
|
|
//获取提现银行卡
|
|
|
- UserBankCardVo bankCardVo = bankCardDao.getBankByUserIdAndCardId(userId, withdrawalReq.getBankCardId());
|
|
|
+ UserBankCardVo bankCardVo = bankCardDao.getBankByUserIdAndCardId(user.getId(), withdrawalReq.getBankCardId());
|
|
|
if (null == bankCardVo) {
|
|
|
return HttpResponseResult.failed("未找到用户绑卡信息");
|
|
|
}
|
|
|
+
|
|
|
//插入用户提现表
|
|
|
- UserWithdrawal userWithdrawal = insertUserWithdrawal(userId, withdrawalReq, bankCardVo, withdrawalServiceFee);
|
|
|
+ UserWithdrawal userWithdrawal = insertUserWithdrawal(user.getId(), withdrawalReq, bankCardVo, withdrawalServiceFee);
|
|
|
//插入账户变更
|
|
|
UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
|
|
|
- userId, withdrawalReq.getAmountWithdrawal(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
|
|
|
+ user.getId(), withdrawalReq.getAmountWithdrawal(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
|
|
|
userWithdrawal.getId(), "老师提现", null
|
|
|
);
|
|
|
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
|
|
|
+ );
|
|
|
return HttpResponseResult.succeed(true);
|
|
|
} else {
|
|
|
throw new BizException("提现失败");
|
|
@@ -127,6 +140,58 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
+ public void callback(UserWithdrawalCallback callback, String jsonStr) {
|
|
|
+ if (StringUtil.isEmpty(callback.getOuterOrderNo()) ||
|
|
|
+ StringUtil.isEmpty(callback.getStatus())) {
|
|
|
+ throw new BizException("参数异常,参数缺失,param is {}", jsonStr);
|
|
|
+ }
|
|
|
+ UserWithdrawalVo detail = detail(Long.parseLong(callback.getOuterOrderNo().trim()));
|
|
|
+ if (null == detail) {
|
|
|
+ throw new BizException("参数异常,未找到交易记录,param is {}", jsonStr);
|
|
|
+ }
|
|
|
+ if(!TradeStatusEnum.pending.equals(detail.getStatus())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ("1".equals(callback.getStatus())) {
|
|
|
+ //交易成功
|
|
|
+ detail.setStatus(TradeStatusEnum.succeeded);
|
|
|
+ detail.setTransNo(callback.getOrderNo());
|
|
|
+ BigDecimal actualAmount = new BigDecimal(callback.getActualAmount());
|
|
|
+ detail.setActualAmount(actualAmount.divide(new BigDecimal("100")));
|
|
|
+ detail.setTransferTime(callback.getEndTime());
|
|
|
+
|
|
|
+ //审核通过,账户解冻,入账户明细
|
|
|
+ UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
|
|
|
+ detail.getUserId(), detail.getAmount(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
|
|
|
+ detail.getId(), "老师提现", null
|
|
|
+ );
|
|
|
+ accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN_DEDUCT);
|
|
|
+ accountRecordDto.setSaveRecord(true);
|
|
|
+ userAccountService.accountChange(accountRecordDto);
|
|
|
+
|
|
|
+ }else if("2".equals(callback.getStatus())){
|
|
|
+ //交易失败
|
|
|
+ detail.setStatus(TradeStatusEnum.failed);
|
|
|
+ detail.setErrorCode(callback.getErrorCode());
|
|
|
+ detail.setErrorMsg(callback.getErrorMsg());
|
|
|
+
|
|
|
+ //审核不通过,账户解冻
|
|
|
+ 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);
|
|
|
+ }else{
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ detail.setCallbackJson(jsonStr);
|
|
|
+ updateById(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void importExcel(List<ExcelDataReaderProperty<UserWithdrawalExport>> dataList, Long userId) {
|
|
|
List<ErrMsg> errMsgList = new ArrayList<>();
|
|
|
dataList.sort(Comparator.comparingInt(ExcelDataReaderProperty::getRowIndex));
|
|
@@ -171,7 +236,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
throw new ExcelException("导入异常", errMsgList);
|
|
|
}
|
|
|
authWithdrawalBancth(userWithdrawalList, userId);
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
/***
|
|
|
* 审核
|
|
@@ -179,7 +244,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
* @param: userWithdrawalList
|
|
|
* @updateTime 2022/4/20 11:18
|
|
|
*/
|
|
|
- private void authWithdrawalBancth(List<UserWithdrawal> userWithdrawalList, Long userId) {
|
|
|
+ /*private void authWithdrawalBancth(List<UserWithdrawal> userWithdrawalList, Long userId) {
|
|
|
for (UserWithdrawal userWithdrawal : userWithdrawalList) {
|
|
|
UserWithdrawal old = baseMapper.selectById(userWithdrawal.getId());
|
|
|
if (null == old || !AuthStatusEnum.DOING.equals(old.getStatus()) || AuthStatusEnum.DOING.equals(userWithdrawal.getStatus())) {
|
|
@@ -212,7 +277,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
}
|
|
|
baseMapper.updateById(userWithdrawal);
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
/***
|
|
|
* 入提现表
|
|
@@ -229,13 +294,11 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
userWithdrawal.setUserId(userId);
|
|
|
userWithdrawal.setAmount(withdrawalReq.getAmountWithdrawal());
|
|
|
userWithdrawal.setPlantformFee(withdrawalServiceFee);
|
|
|
-
|
|
|
- BigDecimal actualAmount = withdrawalReq.getAmountWithdrawal().subtract(withdrawalServiceFee);
|
|
|
- userWithdrawal.setActualAmount(actualAmount);
|
|
|
- userWithdrawal.setBankCard(bankCardVo.getBankCard());
|
|
|
+ userWithdrawal.setBankCardId(bankCardVo.getId());
|
|
|
+ userWithdrawal.setOpenType(withdrawalProperties.getOpenType());
|
|
|
+ userWithdrawal.setStatus(TradeStatusEnum.pending);
|
|
|
userWithdrawal.setCreateTime(new Date());
|
|
|
userWithdrawal.setUpdateTime(new Date());
|
|
|
- userWithdrawal.setStatus(AuthStatusEnum.DOING);
|
|
|
baseMapper.insert(userWithdrawal);
|
|
|
return userWithdrawal;
|
|
|
}
|