From 3307f3c3359225d4723e015c42c58baf65dbdb08 Mon Sep 17 00:00:00 2001 From: "1215525055@qq.com" <1215525055@qq.com> Date: Sun, 2 Mar 2025 11:48:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=A5=97=E9=A4=90?= =?UTF-8?q?=E5=8C=85=E7=9A=84=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD,=20?= =?UTF-8?q?=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AccountRechargeController.java | 1 - .../AccountRechargeAppController.java | 22 ++++++++++++++ .../remote/IOperatorPluginRemoteService.java | 30 +++++++++++++++++-- .../impl/AccountRechargeServiceImpl.java | 30 +++++++++++-------- .../util/task/WxPayResultCheckTask.java | 29 ++++++++++++++++++ 5 files changed, 96 insertions(+), 16 deletions(-) diff --git a/src/main/java/cn/com/tenlion/operator/controller/api/accountrecharge/AccountRechargeController.java b/src/main/java/cn/com/tenlion/operator/controller/api/accountrecharge/AccountRechargeController.java index 925f33f..828c7f5 100644 --- a/src/main/java/cn/com/tenlion/operator/controller/api/accountrecharge/AccountRechargeController.java +++ b/src/main/java/cn/com/tenlion/operator/controller/api/accountrecharge/AccountRechargeController.java @@ -101,7 +101,6 @@ public class AccountRechargeController extends DefaultBaseController { return new SuccessResult(); } - @ApiOperation(value = "修改账户充值", notes = "修改账户充值接口") @ApiImplicitParams({ @ApiImplicitParam(name = "accountRechargeId", value = "账户充值ID", paramType = "path") diff --git a/src/main/java/cn/com/tenlion/operator/controller/app/api/accountrecharge/AccountRechargeAppController.java b/src/main/java/cn/com/tenlion/operator/controller/app/api/accountrecharge/AccountRechargeAppController.java index 708d654..71b36fb 100644 --- a/src/main/java/cn/com/tenlion/operator/controller/app/api/accountrecharge/AccountRechargeAppController.java +++ b/src/main/java/cn/com/tenlion/operator/controller/app/api/accountrecharge/AccountRechargeAppController.java @@ -1,7 +1,10 @@ package cn.com.tenlion.operator.controller.app.api.accountrecharge; +import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayDTO; +import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargePayResultDTO; import ink.wgink.annotation.CheckRequestBodyAnnotation; import ink.wgink.common.base.DefaultBaseController; +import ink.wgink.exceptions.ParamsException; import ink.wgink.interfaces.consts.ISystemConstant; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.result.ErrorResult; @@ -12,6 +15,7 @@ import cn.com.tenlion.operator.pojo.dtos.accountrecharge.AccountRechargeDTO; import cn.com.tenlion.operator.pojo.vos.accountrecharge.AccountRechargeVO; import cn.com.tenlion.operator.service.accountrecharge.IAccountRechargeService; import io.swagger.annotations.*; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -34,6 +38,24 @@ public class AccountRechargeAppController extends DefaultBaseController { @Autowired private IAccountRechargeService accountRechargeService; + @ApiOperation(value = "确认付款按钮触发", notes = "确认付款按钮触发接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("recharge-result" + ISystemConstant.RELEASE_SUFFIX + "/{accountRechargeId}") + public synchronized AccountRechargePayResultDTO getRecharge(@PathVariable("accountRechargeId") String accountRechargeId, @RequestBody AccountRechargeVO accountRechargeVO) { + return accountRechargeService.queryOnlineSuccess(accountRechargeId, accountRechargeVO); + } + + @ApiOperation(value = "保存充值", notes = "保存充值接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("save-account" + ISystemConstant.RELEASE_SUFFIX) + @CheckRequestBodyAnnotation + public AccountRechargePayDTO saveAccount(@RequestBody AccountRechargeVO accountRechargeVO) { + if (StringUtils.isBlank(accountRechargeVO.getUserId())) { + throw new ParamsException("用户ID不能为空"); + } + return accountRechargeService.saveAccount(accountRechargeVO.getThirdParty(), accountRechargeVO); + } + @ApiOperation(value = "新增账户充值", notes = "新增账户充值接口") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "token", paramType = "header") diff --git a/src/main/java/cn/com/tenlion/operator/remote/IOperatorPluginRemoteService.java b/src/main/java/cn/com/tenlion/operator/remote/IOperatorPluginRemoteService.java index 879fc35..79ba4f5 100644 --- a/src/main/java/cn/com/tenlion/operator/remote/IOperatorPluginRemoteService.java +++ b/src/main/java/cn/com/tenlion/operator/remote/IOperatorPluginRemoteService.java @@ -16,11 +16,35 @@ import java.util.List; @RemoteService public interface IOperatorPluginRemoteService { - @RemotePostMethod("/resource/packageorder/update") - SuccessResult updateOrder(@RemoteServerParams String server, - @RemoteJsonBodyParams PackageOrderAppVO appVO, + /** + * 关闭套餐包订单 + * @param server + * @param accessToken + * @return + */ + @RemotePostMethod("/resource/packageorder/update-close/{packageNo}") + SuccessResult updateClose(@RemoteServerParams String server, + @RemotePathParams("packageNo") String packageNo, + @RemoteQueryParams("access_token") String accessToken); + + /** + * 更改到账状态 + * @param server + * @param accessToken + * @return + */ + @RemotePostMethod("/resource/packageorder/update-pay/{packageNo}") + SuccessResult updatePay(@RemoteServerParams String server, + @RemotePathParams("packageNo") String packageNo, @RemoteQueryParams("access_token") String accessToken); + /** + * 创建套餐包购买记录 + * @param server + * @param appVO + * @param accessToken + * @return + */ @RemotePostMethod("/resource/packageorder/save") SuccessResult saveOrder(@RemoteServerParams String server, @RemoteJsonBodyParams PackageOrderAppVO appVO, diff --git a/src/main/java/cn/com/tenlion/operator/service/accountrecharge/impl/AccountRechargeServiceImpl.java b/src/main/java/cn/com/tenlion/operator/service/accountrecharge/impl/AccountRechargeServiceImpl.java index 8f0345c..ff6bdbe 100644 --- a/src/main/java/cn/com/tenlion/operator/service/accountrecharge/impl/AccountRechargeServiceImpl.java +++ b/src/main/java/cn/com/tenlion/operator/service/accountrecharge/impl/AccountRechargeServiceImpl.java @@ -309,6 +309,13 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA params.put("reconciliationTime", ""); params.put("gmtModified", DateUtil.getTime()); accountRechargeDao.updateCheck(params); + AccountRechargeDTO dto = get(accountRechargeId); + // 创建套餐包关闭支付 + if(!StringUtils.isEmpty(dto.getPackageInfoId())) { + String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); + SuccessResult result = operatorPluginRemoteService.updateClose(systemApiPathProperties.getOperatorPlugin(), accountRechargeId, accessToken); + System.out.println("调用套餐包关闭结果 : " + result); + } } @Override @@ -349,15 +356,16 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA AccountRechargeDTO dto = get(accountRechargeId); // 绑定了套餐包 & 已对账 & 已到账 if(!StringUtils.isEmpty(dto.getPackageInfoId()) && dto.getReconciliationStatus().equals("1") && dto.getRechargeCheck().equals("2")) { - // 远程更改套餐包的到账状态 - PackageOrderAppVO appVO = new PackageOrderAppVO(); - appVO.setAccountItemId(dto.getAccountItemId()); - appVO.setPackageInfoId(dto.getPackageInfoId()); - appVO.setUserId(dto.getCreator()); - appVO.setAccountRechargeId(dto.getAccountRechargeId()); - + // 远程更改套餐包的付款到账状态 String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); - operatorPluginRemoteService.updateOrder(systemApiPathProperties.getOperatorPlugin(), appVO, accessToken); + SuccessResult result = operatorPluginRemoteService.updatePay(systemApiPathProperties.getOperatorPlugin(), accountRechargeId, accessToken); + System.out.println("调用套餐包到账结果 : " + result); + } + // 绑定了套餐包 & 已对账 & 已关闭 + if(!StringUtils.isEmpty(dto.getPackageInfoId()) && dto.getReconciliationStatus().equals("1") && dto.getRechargeCheck().equals("-1")) { + String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); + SuccessResult result = operatorPluginRemoteService.updateClose(systemApiPathProperties.getOperatorPlugin(), accountRechargeId, accessToken); + System.out.println("调用套餐包关闭结果 : " + result); } } @@ -422,7 +430,8 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA appVO.setAccountRechargeId(payDTO.getAccountRechargeId()); String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken(); - operatorPluginRemoteService.saveOrder(systemApiPathProperties.getOperatorPlugin(), appVO, accessToken); + SuccessResult result = operatorPluginRemoteService.saveOrder(systemApiPathProperties.getOperatorPlugin(), appVO, accessToken); + System.out.println("调用套餐包创建结果 : " + result); } } return payDTO; @@ -600,9 +609,6 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA updateCheck(dto.getAccountRechargeId(), RechargeCheckEnum.RECHARGE_SUCCESS, "线上充值", accountItemId, orderId, successTime); // 3. 调用第三方接口, 告知充值到账 sysCallbackService.save("项目充值到账", systemApiPathProperties.getCopyright() + "api/pay/recharge-success/user-id/" + dto.getAccountId(), null); - // 2025年2月28日10:34:10 CBC 新增 套餐包购买 - - } } diff --git a/src/main/java/cn/com/tenlion/operator/util/task/WxPayResultCheckTask.java b/src/main/java/cn/com/tenlion/operator/util/task/WxPayResultCheckTask.java index 7440e23..5d59b11 100644 --- a/src/main/java/cn/com/tenlion/operator/util/task/WxPayResultCheckTask.java +++ b/src/main/java/cn/com/tenlion/operator/util/task/WxPayResultCheckTask.java @@ -12,6 +12,7 @@ import cn.com.tenlion.operator.util.pay.PayUtil; import cn.com.tenlion.operator.util.pay.WXPay; import ink.wgink.interfaces.consts.ISystemConstant; import org.apache.commons.lang3.StringUtils; +import org.quartz.DisallowConcurrentExecution; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +24,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; +@DisallowConcurrentExecution // 防止定时任务并行执行【防止1个没有执行完,另一个又开始了】 @Component public class WxPayResultCheckTask { @@ -37,6 +39,33 @@ public class WxPayResultCheckTask { iAccountRechargeStaticService = this.iAccountRechargeService; } + /** + * 线上已支付订单的核对(10分钟之内的) + */ + @Scheduled(fixedDelay = 60 * 1000 * 2) + public void updateStatus() { + LOG.debug("检查支付宝和微信,已支付未核对的订单"); + // 未充值的订单 + List accountRechargePOS = iAccountRechargeService.listPOByRechargeCheck(RechargeCheckEnum.RECHARGED); + accountRechargePOS.forEach(po -> { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime gmtCreateDateTime = LocalDateTime.parse(po.getGmtCreate(), DateTimeFormatter.ofPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD_HH_MM_SS)); + if (StringUtils.equals(po.getThirdParty(), ThirdPartyEnum.WX.getValue()) && now.isAfter(gmtCreateDateTime.plusMinutes(10))) { + PayResultDTO payResultDTO = WXPay.queryPay(po.getAccountRechargeId()); + // 成功 + if (payResultDTO.getOrderStatus().equals("1") && payResultDTO.getMoney().equals(PayUtil.buiderMoney(po.getRechargeMoney())) ) { + iAccountRechargeStaticService.saveConfirmOnline(po.getAccountRechargeId(), payResultDTO.getOrderId(), payResultDTO.getOrderSuccessTime()); + } + } else if (StringUtils.equals(po.getThirdParty(), ThirdPartyEnum.ZFB.getValue()) && now.isAfter(gmtCreateDateTime.plusMinutes(10))) { + PayResultDTO payResultDTO = ALiPay.queryPay(po.getAccountRechargeId()); + // 成功 + if (payResultDTO.getOrderStatus().equals("1") && payResultDTO.getMoney().equals(PayUtil.buiderMoney(po.getRechargeMoney())) ) { + iAccountRechargeStaticService.saveConfirmOnline(po.getAccountRechargeId(), payResultDTO.getOrderId(), payResultDTO.getOrderSuccessTime()); + } + } + }); + } + /** * 超过10分钟未支付的关闭 * 充值时间