|
|
@ -1,6 +1,18 @@ |
|
|
|
package org.jeecg.modules.rechargeInfoLog.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
|
import com.wechat.pay.contrib.apache.httpclient.util.RsaCryptoUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
import org.jeecg.common.bestpay.model.TransferBatchesDetailsRequest; |
|
|
|
import org.jeecg.common.bestpay.model.TransferBatchesRequest; |
|
|
|
import org.jeecg.common.bestpay.model.TransferBatchesResp; |
|
|
|
import org.jeecg.common.bestpay.pay.WeChatPayConfig2; |
|
|
|
import org.jeecg.common.bestpay.utils.HttpRequestUtil; |
|
|
|
import org.jeecg.common.bestpay.utils.MoneyUtil; |
|
|
|
import org.jeecg.common.constant.RedisKey; |
|
|
|
import org.jeecg.common.exception.JeecgBootException; |
|
|
|
import org.jeecg.common.util.RedisUtil; |
|
|
@ -9,6 +21,7 @@ import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService; |
|
|
|
import org.jeecg.modules.rechargeInfoLog.entity.TbRechargeInfoLog; |
|
|
|
import org.jeecg.modules.rechargeInfoLog.mapper.TbRechargeInfoLogMapper; |
|
|
|
import org.jeecg.modules.rechargeInfoLog.service.ITbRechargeInfoLogService; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
@ -16,14 +29,18 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.security.cert.X509Certificate; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description: tb_recharge_info_log |
|
|
|
* @Author: jeecg-boot |
|
|
|
* @Date: 2024-12-12 |
|
|
|
* @Date: 2024-12-12 |
|
|
|
* @Version: V1.0 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class TbRechargeInfoLogServiceImpl extends ServiceImpl<TbRechargeInfoLogMapper, TbRechargeInfoLog> implements ITbRechargeInfoLogService { |
|
|
|
|
|
|
@ -31,25 +48,36 @@ public class TbRechargeInfoLogServiceImpl extends ServiceImpl<TbRechargeInfoLogM |
|
|
|
private RedisUtil redisUtil; |
|
|
|
@Resource |
|
|
|
private IHanHaiMemberService hanHaiMemberService; |
|
|
|
|
|
|
|
@Value("${wxpay.appId}") |
|
|
|
private String appId; |
|
|
|
@Value("${wechat.transferBatchUrl}") |
|
|
|
private String transferBatchUrl; |
|
|
|
@Value("${wxpay.mchId}") |
|
|
|
private String mchId; |
|
|
|
@Value("${wechat.keyPemPath}") |
|
|
|
private String pemPath; |
|
|
|
@Value("${wxpay.serialNo}") |
|
|
|
private String wxsSerialNo; |
|
|
|
@Resource |
|
|
|
private WeChatPayConfig2 weChatPayConfig2; |
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Override |
|
|
|
public Result<?> audit(String id, boolean status, String checkInfo) { |
|
|
|
Integer n = (Integer) redisUtil.get(RedisKey.MER_WITHDRAWAL_AUDIT + id); |
|
|
|
if(n != null){ |
|
|
|
if (n != null) { |
|
|
|
throw new JeecgBootException("请勿重复点击!"); |
|
|
|
} |
|
|
|
redisUtil.set(RedisKey.MER_WITHDRAWAL_AUDIT + id,1,5); |
|
|
|
redisUtil.set(RedisKey.MER_WITHDRAWAL_AUDIT + id, 1, 5); |
|
|
|
TbRechargeInfoLog rechargeInfoLog = this.getById(id); |
|
|
|
if(rechargeInfoLog==null) { |
|
|
|
if (rechargeInfoLog == null) { |
|
|
|
throw new JeecgBootException("未找到数据"); |
|
|
|
} |
|
|
|
|
|
|
|
Long count = this.lambdaQuery() |
|
|
|
.eq(TbRechargeInfoLog::getWithdrawalId, rechargeInfoLog.getId()) |
|
|
|
.count(); |
|
|
|
if(count != null && count > 0){ |
|
|
|
if (count != null && count > 0) { |
|
|
|
throw new JeecgBootException("此提现已处理过不通过,请勿重新点击"); |
|
|
|
} |
|
|
|
|
|
|
@ -57,7 +85,7 @@ public class TbRechargeInfoLogServiceImpl extends ServiceImpl<TbRechargeInfoLogM |
|
|
|
TbRechargeInfoLog rechargeInfoLog1 = new TbRechargeInfoLog(); |
|
|
|
rechargeInfoLog1.setId(rechargeInfoLog.getId()); |
|
|
|
rechargeInfoLog1.setState(1); |
|
|
|
if(!status){ |
|
|
|
if (!status) { |
|
|
|
//审核不通过退回余额 |
|
|
|
rechargeInfoLog1.setState(3); |
|
|
|
rechargeInfoLog1.setCheckInfo(checkInfo); |
|
|
@ -67,7 +95,7 @@ public class TbRechargeInfoLogServiceImpl extends ServiceImpl<TbRechargeInfoLogM |
|
|
|
cmMemberAccount2.setId(account.getId()); |
|
|
|
cmMemberAccount2.setPrice(account.getPrice().add(money)); |
|
|
|
boolean b = hanHaiMemberService.updateById(cmMemberAccount2); |
|
|
|
if(!b){ |
|
|
|
if (!b) { |
|
|
|
throw new JeecgBootException("操作失败,请稍后重试"); |
|
|
|
} |
|
|
|
TbRechargeInfoLog merRechargeInfoLog = new TbRechargeInfoLog(); |
|
|
@ -82,15 +110,91 @@ public class TbRechargeInfoLogServiceImpl extends ServiceImpl<TbRechargeInfoLogM |
|
|
|
merRechargeInfoLog.setCheckInfo(checkInfo); |
|
|
|
merRechargeInfoLog.setWithdrawalId(rechargeInfoLog.getId()); |
|
|
|
boolean save = this.save(merRechargeInfoLog); |
|
|
|
if(!save){ |
|
|
|
if (!save) { |
|
|
|
throw new JeecgBootException("操作失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
boolean b = this.updateById(rechargeInfoLog1); |
|
|
|
if(!b){ |
|
|
|
if (!b) { |
|
|
|
throw new JeecgBootException("操作失败,请稍后重试"); |
|
|
|
} |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public Result<?> handleWithdrawal(String id) { |
|
|
|
|
|
|
|
Integer n = (Integer) redisUtil.get(RedisKey.MER_WITHDRAWAL + id); |
|
|
|
if (n != null) { |
|
|
|
throw new JeecgBootException("请勿重复点击,后果自负!"); |
|
|
|
} |
|
|
|
redisUtil.set(RedisKey.MER_WITHDRAWAL + id, 1, 5); |
|
|
|
|
|
|
|
TbRechargeInfoLog merRechargeInfoLog = this.getById(id); |
|
|
|
if (merRechargeInfoLog == null) { |
|
|
|
throw new JeecgBootException("未找到数据"); |
|
|
|
} |
|
|
|
HanHaiMember merMember = hanHaiMemberService.getById(merRechargeInfoLog.getMemberId()); |
|
|
|
//微信-商家转账到零钱 |
|
|
|
String idStr = "zx" + IdWorker.getIdStr(); |
|
|
|
TransferBatchesRequest transferBatchesRequest = new TransferBatchesRequest(); |
|
|
|
|
|
|
|
transferBatchesRequest.setAppid(appId); |
|
|
|
transferBatchesRequest.setTotalNum(1); |
|
|
|
transferBatchesRequest.setOutBatchNo(idStr); |
|
|
|
transferBatchesRequest.setBatchName("商家提现"); |
|
|
|
transferBatchesRequest.setBatchRemark(merRechargeInfoLog.getInfo()); |
|
|
|
if (StringUtils.isBlank(merRechargeInfoLog.getInfo()) || merRechargeInfoLog.getInfo().length() > 32) { |
|
|
|
transferBatchesRequest.setBatchRemark("商家提现"); |
|
|
|
} |
|
|
|
transferBatchesRequest.setTotalAmount(MoneyUtil.Yuan2Fen(merRechargeInfoLog.getMoney().doubleValue())); |
|
|
|
List<TransferBatchesDetailsRequest> transferBatchesDetailsRequests = new ArrayList<>(); |
|
|
|
TransferBatchesDetailsRequest transferBatchesDetailsRequest = new TransferBatchesDetailsRequest(); |
|
|
|
transferBatchesDetailsRequest.setOutDetailNo(merRechargeInfoLog.getId()); |
|
|
|
transferBatchesDetailsRequest.setTransferAmount(MoneyUtil.Yuan2Fen(merRechargeInfoLog.getMoney().doubleValue())); |
|
|
|
transferBatchesDetailsRequest.setTransferRemark(merRechargeInfoLog.getInfo()); |
|
|
|
if (StringUtils.isBlank(merRechargeInfoLog.getInfo()) || merRechargeInfoLog.getInfo().length() > 32) { |
|
|
|
transferBatchesDetailsRequest.setTransferRemark("商家提现"); |
|
|
|
} |
|
|
|
transferBatchesDetailsRequest.setOpenid(merMember.getAppletOpenid()); |
|
|
|
String serialNo = null; |
|
|
|
try { |
|
|
|
X509Certificate certificate = weChatPayConfig2.getVerifier().getValidCertificate(); |
|
|
|
serialNo = certificate.getSerialNumber().toString(16).toUpperCase(); |
|
|
|
String encryptOAEP = RsaCryptoUtil.encryptOAEP(merRechargeInfoLog.getRealName(), certificate); |
|
|
|
transferBatchesDetailsRequest.setUserName(encryptOAEP); |
|
|
|
} catch (Exception e) { |
|
|
|
log.info("真实姓名加密失败"); |
|
|
|
e.printStackTrace(); |
|
|
|
throw new JeecgBootException("真实姓名加密失败"); |
|
|
|
} |
|
|
|
|
|
|
|
transferBatchesDetailsRequests.add(transferBatchesDetailsRequest); |
|
|
|
transferBatchesRequest.setTransferDetailList(transferBatchesDetailsRequests); |
|
|
|
// transferBatchesRequest.setTransferSceneId("1001"); |
|
|
|
String jsonString = JSONObject.toJSONString(transferBatchesRequest); |
|
|
|
|
|
|
|
|
|
|
|
String postTransBatRequest = HttpRequestUtil.postTransBatRequest(transferBatchUrl, jsonString, serialNo, wxsSerialNo, mchId, pemPath); |
|
|
|
log.error("返回结果1:" + postTransBatRequest); |
|
|
|
TransferBatchesResp transferBatchesResp = JSON.parseObject(postTransBatRequest, TransferBatchesResp.class); |
|
|
|
log.error("返回结果2:" + transferBatchesResp); |
|
|
|
if (transferBatchesResp == null || org.apache.commons.lang3.StringUtils.isBlank(transferBatchesResp.getBatchId())) { |
|
|
|
throw new JeecgBootException("打款失败"); |
|
|
|
} |
|
|
|
|
|
|
|
TbRechargeInfoLog rechargeInfoLog1 = new TbRechargeInfoLog(); |
|
|
|
rechargeInfoLog1.setId(merRechargeInfoLog.getId()); |
|
|
|
rechargeInfoLog1.setState(2); |
|
|
|
rechargeInfoLog1.setOutBatchNo(transferBatchesResp.getOutBatchNo()); |
|
|
|
rechargeInfoLog1.setBatchId(transferBatchesResp.getBatchId()); |
|
|
|
boolean b = this.updateById(rechargeInfoLog1); |
|
|
|
if (!b) { |
|
|
|
throw new JeecgBootException("操作失败,请稍后重试"); |
|
|
|
} |
|
|
|
return Result.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
} |