|
@@ -10,6 +10,7 @@ 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.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.support.DistributedLock;
|
|
|
import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.UserBankCardDao;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.UserAccountRecordDto;
|
|
@@ -19,6 +20,7 @@ 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.cooleshow.common.enums.CacheNameEnum;
|
|
|
import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.toolset.base.string.StringPool;
|
|
@@ -26,6 +28,7 @@ import com.yonge.toolset.base.util.StringUtil;
|
|
|
import com.yonge.toolset.payment.base.enums.TradeStatusEnum;
|
|
|
import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.yonge.toolset.utils.string.ValueUtil;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -38,6 +41,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -60,6 +64,8 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
private SysUserContractRecordDao userContractRecordDao;
|
|
|
@Autowired
|
|
|
private IdGeneratorService idGeneratorService;
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
|
|
|
@Override
|
|
|
public UserWithdrawalVo detail(Long id) {
|
|
@@ -108,18 +114,18 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
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("当前不允许提现");
|
|
|
+ return HttpResponseResult.failed("当前不允许结算");
|
|
|
}
|
|
|
- //校验--判断今天提现次数
|
|
|
+ //校验--判断今天结算次数
|
|
|
String withdrawalMaxCount = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_MAX_COUNT);
|
|
|
Integer count = getNowDayWithdrawalCount(user.getId());
|
|
|
if (count >= Integer.parseInt(withdrawalMaxCount)) {
|
|
|
- return HttpResponseResult.failed("达到当天提现最大次数");
|
|
|
+ return HttpResponseResult.failed("达到当天结算最大次数");
|
|
|
}
|
|
|
- //校验--校验金额(金额不能小于手续费,手续费从提现金额里面扣除)
|
|
|
+ //校验--校验金额(金额不能小于手续费,手续费从结算金额里面扣除)
|
|
|
BigDecimal withdrawalServiceFee = getWithdrawalServiceFee();
|
|
|
BigDecimal actualAmount = withdrawalReq.getAmountWithdrawal().subtract(withdrawalServiceFee);
|
|
|
if (actualAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
@@ -135,9 +141,9 @@ 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);
|
|
|
|
|
|
//插入用户结算表
|
|
@@ -179,68 +185,86 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public HttpResponseResult<Boolean> doAuth(AuthOperaReq authOperaReq, SysUser sysUser) {
|
|
|
+ public HttpResponseResult<Boolean> batchAuth(AuthOperaReq authOperaReq, SysUser sysUser) {
|
|
|
Long[] ids = StringUtil.toLongArray(StringPool.COMMA, authOperaReq.getId());
|
|
|
for (Long id : ids) {
|
|
|
- UserWithdrawalVo build = detail(id);
|
|
|
- if (null == build || !AuthStatusEnum.DOING.equals(build.getAuthStatus())) {
|
|
|
- continue;
|
|
|
+ AuthOperaReq param = new AuthOperaReq();
|
|
|
+ param.setId(id.toString());
|
|
|
+ param.setReason(authOperaReq.getReason());
|
|
|
+ param.setPass(authOperaReq.getPass());
|
|
|
+
|
|
|
+ try {
|
|
|
+ DistributedLock.of(redissonClient)
|
|
|
+ .runIfLockCanGet(CacheNameEnum.LOCK_WITHDRAWAL.getRedisKey(id.toString())
|
|
|
+ , () -> doAuth(param, sysUser), 60L, TimeUnit.SECONDS);
|
|
|
+ } catch (BizException e) {
|
|
|
+ return HttpResponseResult.failed(e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return HttpResponseResult.failed("结算失败");
|
|
|
}
|
|
|
- build.setAuthStatus(authOperaReq.getPass() ? AuthStatusEnum.PASS : AuthStatusEnum.UNPASS);
|
|
|
- build.setReason(authOperaReq.getReason());
|
|
|
- build.setAuthUserId(sysUser.getId());
|
|
|
- build.setUpdateTime(new Date());
|
|
|
- build.setAuthTime(new Date());
|
|
|
-
|
|
|
- //请求三方
|
|
|
- SysUser withdrawalUser = sysUserService.findUserById(build.getUserId());
|
|
|
- Boolean flag = false;
|
|
|
- if (authOperaReq.getPass()) {
|
|
|
- //请求三方接口
|
|
|
-
|
|
|
- //交易流水号生成
|
|
|
- Long transNo = idGeneratorService.generatorId("withdrawNo");
|
|
|
+ }
|
|
|
+ return HttpResponseResult.succeed();
|
|
|
+ }
|
|
|
|
|
|
- HttpResponseResult<Boolean> withdraw = withdrawSdk.withdraw(
|
|
|
- transNo.toString(), build.getRealName(), build.getPhone(), withdrawalUser.getIdCardNo(),
|
|
|
- build.getActualAmount().multiply(new BigDecimal("100")).intValue(), build.getBankCard(), null
|
|
|
- );
|
|
|
- if (withdraw.getStatus() && withdraw.getData()) {
|
|
|
- build.setTradeStatus(TradeStatusEnum.pending);
|
|
|
- build.setTransNo(transNo.toString());
|
|
|
- flag = true;
|
|
|
- } else {
|
|
|
- build.setTradeStatus(TradeStatusEnum.failed);
|
|
|
- build.setErrorMsg("请求三方接口返回失败");
|
|
|
- }
|
|
|
- }
|
|
|
- //修改系统中账户
|
|
|
- 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);
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void doAuth(AuthOperaReq authOperaReq, SysUser sysUser) {
|
|
|
+ UserWithdrawalVo build = detail(Long.parseLong(authOperaReq.getId()));
|
|
|
+ if (null == build || !AuthStatusEnum.DOING.equals(build.getAuthStatus())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ build.setAuthStatus(authOperaReq.getPass() ? AuthStatusEnum.PASS : AuthStatusEnum.UNPASS);
|
|
|
+ build.setReason(authOperaReq.getReason());
|
|
|
+ build.setAuthUserId(sysUser.getId());
|
|
|
+ build.setUpdateTime(new Date());
|
|
|
+ build.setAuthTime(new Date());
|
|
|
+
|
|
|
+ //请求三方
|
|
|
+ SysUser withdrawalUser = sysUserService.findUserById(build.getUserId());
|
|
|
+ Boolean flag = false;
|
|
|
+ if (authOperaReq.getPass()) {
|
|
|
+ //请求三方接口
|
|
|
+ //交易流水号生成
|
|
|
+ Long transNo = idGeneratorService.generatorId("withdrawNo");
|
|
|
+
|
|
|
+ HttpResponseResult<Boolean> withdraw = withdrawSdk.withdraw(
|
|
|
+ transNo.toString(), build.getRealName(), build.getPhone(), withdrawalUser.getIdCardNo(),
|
|
|
+ build.getActualAmount().multiply(new BigDecimal("100")).intValue(), build.getBankCard(), null
|
|
|
+ );
|
|
|
+ if (withdraw.getStatus() && withdraw.getData()) {
|
|
|
+ build.setTradeStatus(TradeStatusEnum.pending);
|
|
|
+ build.setTransNo(transNo.toString());
|
|
|
+ flag = true;
|
|
|
+ } else {
|
|
|
+ build.setTradeStatus(TradeStatusEnum.failed);
|
|
|
+ build.setErrorMsg("请求三方接口返回失败");
|
|
|
}
|
|
|
- updateById(build);
|
|
|
}
|
|
|
- return HttpResponseResult.succeed();
|
|
|
+ //修改系统中账户
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public HttpResponseResult<Boolean> transferAccount(AuthOperaReq authOperaReq, SysUser user) {
|
|
|
UserWithdrawalVo detail = detail(Long.parseLong(authOperaReq.getId()));
|
|
|
if (detail == null) {
|
|
|
- return HttpResponseResult.failed("提现记录不存在");
|
|
|
+ return HttpResponseResult.failed("结算记录不存在");
|
|
|
}
|
|
|
if (!AuthStatusEnum.PASS.equals(detail.getAuthStatus())) {
|
|
|
- return HttpResponseResult.failed("提现记录未审核");
|
|
|
+ return HttpResponseResult.failed("结算记录未审核");
|
|
|
}
|
|
|
if (TradeStatusEnum.succeeded.equals(detail.getTradeStatus())) {
|
|
|
- return HttpResponseResult.failed("提现已经交易成功");
|
|
|
+ return HttpResponseResult.failed("结算已经交易成功");
|
|
|
}
|
|
|
|
|
|
//交易流水号生成
|
|
@@ -316,7 +340,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查询用户今天发起的提现次数
|
|
|
+ * 查询用户今天发起的结算次数
|
|
|
*
|
|
|
* @param userId
|
|
|
* @return
|