|
|
@@ -34,15 +34,12 @@ import shop.alien.util.common.constant.PaymentEnum;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
import java.io.UncheckedIOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.PrivateKey;
|
|
|
import java.security.PublicKey;
|
|
|
import java.security.Signature;
|
|
|
-import java.util.Base64;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
|
@@ -158,7 +155,7 @@ public class WeChatPaymentMininProgramStrategyImpl implements PaymentStrategy {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R createPrePayOrder(String price, String subject, String payer, String orderNo, Integer storeId, Integer couponId, Integer payerId) throws Exception {
|
|
|
+ public R createPrePayOrder(String price, String subject, String payer, String orderNo, Integer storeId, Integer couponId, Integer payerId,String tablewareFee,String discountAmount,String payAmount) throws Exception {
|
|
|
// 本系统调用:通过 storeId 从 MySQL 获取店铺支付配置
|
|
|
if (storeId == null) {
|
|
|
log.warn("createPrePayOrder 缺少 storeId,无法获取支付配置");
|
|
|
@@ -202,23 +199,19 @@ public class WeChatPaymentMininProgramStrategyImpl implements PaymentStrategy {
|
|
|
if (publicKey == null) {
|
|
|
return R.fail("店铺微信支付公钥未配置或加载失败");
|
|
|
}
|
|
|
- log.info("storeOrder:"+storeOrder.toString());
|
|
|
- if(storeOrder.getPayTradeNo() != null && org.apache.commons.lang3.StringUtils.isNotBlank(storeOrder.getPayTradeNo())) {
|
|
|
- log.info("执行查询");
|
|
|
- QueryByWxTradeNoRequest q = new QueryByWxTradeNoRequest();
|
|
|
- q.transactionId = storeOrder.getPayTradeNo();
|
|
|
- q.mchid = mchId;
|
|
|
- try {
|
|
|
- DirectAPIv3QueryResponse wxOrder = searchOrderRun(q, config, privateKey, publicKey);
|
|
|
- if (wxOrder != null && "SUCCESS".equals(wxOrder.tradeState)) {
|
|
|
- return R.fail("该支付单已在微信侧支付成功,请勿重复发起支付");
|
|
|
- }
|
|
|
- } catch (WXPayUtility.ApiException e) {
|
|
|
- if (e.getStatusCode() != 404 && !"ORDER_NOT_EXIST".equals(e.getErrorCode())) {
|
|
|
- log.error("预支付前查询微信订单失败 out_trade_no={}, status={}, code={}, msg={}",
|
|
|
- storeOrder.getPayTradeNo(), e.getStatusCode(), e.getErrorCode(), e.getErrorMessage());
|
|
|
- return R.fail("查询微信支付订单失败:" + (e.getErrorMessage() != null ? e.getErrorMessage() : e.getMessage()));
|
|
|
- }
|
|
|
+ QueryByWxTradeNoRequest q = new QueryByWxTradeNoRequest();
|
|
|
+ q.transactionId = storeOrder.getPayTradeNo();
|
|
|
+ q.mchid = mchId;
|
|
|
+ try {
|
|
|
+ DirectAPIv3QueryResponse wxOrder = searchOrderRun(q, config, privateKey, publicKey);
|
|
|
+ if (wxOrder != null && "SUCCESS".equals(wxOrder.tradeState)) {
|
|
|
+ return R.fail("该支付单已在微信侧支付成功,请勿重复发起支付");
|
|
|
+ }
|
|
|
+ } catch (WXPayUtility.ApiException e) {
|
|
|
+ if (e.getStatusCode() != 404 && !"ORDER_NOT_EXIST".equals(e.getErrorCode())) {
|
|
|
+ log.error("预支付前查询微信订单失败 out_trade_no={}, status={}, code={}, msg={}",
|
|
|
+ storeOrder.getPayTradeNo(), e.getStatusCode(), e.getErrorCode(), e.getErrorMessage());
|
|
|
+ return R.fail("查询微信支付订单失败:" + (e.getErrorMessage() != null ? e.getErrorMessage() : e.getMessage()));
|
|
|
}
|
|
|
}
|
|
|
String newPayTradeNo = "WX" + storeOrder.getId() + "_" + System.currentTimeMillis();
|
|
|
@@ -227,6 +220,9 @@ public class WeChatPaymentMininProgramStrategyImpl implements PaymentStrategy {
|
|
|
log.info("未支付场景已换新微信商户单号 orderNo={}, payTradeNo={}", orderNo, newPayTradeNo);
|
|
|
storeOrder.setCouponId(couponId);
|
|
|
storeOrder.setPayUserId(payerId);
|
|
|
+ storeOrder.setTablewareFee(new BigDecimal(tablewareFee));
|
|
|
+ storeOrder.setDiscountAmount(new BigDecimal(discountAmount));
|
|
|
+ storeOrder.setPayAmount(new BigDecimal(payAmount));
|
|
|
if (!storeOrderService.updateById(storeOrder)) {
|
|
|
log.error("更新订单失败 orderNo={}", orderNo);
|
|
|
return R.fail("更新订单失败");
|
|
|
@@ -350,6 +346,8 @@ public class WeChatPaymentMininProgramStrategyImpl implements PaymentStrategy {
|
|
|
if (storeOrder != null && storeOrder.getPayStatus() != 1) {
|
|
|
storeOrder.setPayStatus(1);
|
|
|
storeOrder.setOrderStatus(1);
|
|
|
+ storeOrder.setPayType(1);
|
|
|
+ storeOrder.setPayTime(new Date());
|
|
|
if (storeOrderService.updateById(storeOrder)) {
|
|
|
log.info("小程序更新订单成功,订单号outTradeNo:{}", outTradeNo);
|
|
|
if (storeOrder.getCouponId() != null && storeOrder.getPayUserId() != null) {
|