From b47f8a03db79bb1f6356479cd8a5cf190d7d9694 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 23 六月 2021 11:10:36 +0800 Subject: [PATCH] 礼金功能完善 --- service-vip/src/main/java/com/ks/vip/service/remote/VipOrderPayServiceImpl.java | 45 ++++++++++++++++++++++++++------------------- 1 files changed, 26 insertions(+), 19 deletions(-) diff --git a/service-vip/src/main/java/com/ks/vip/service/remote/VipOrderPayServiceImpl.java b/service-vip/src/main/java/com/ks/vip/service/remote/VipOrderPayServiceImpl.java index bd8b3f1..8ad515d 100644 --- a/service-vip/src/main/java/com/ks/vip/service/remote/VipOrderPayServiceImpl.java +++ b/service-vip/src/main/java/com/ks/vip/service/remote/VipOrderPayServiceImpl.java @@ -17,8 +17,8 @@ import com.ks.vip.util.Constant; import com.ks.vip.util.PayUtil; import org.apache.dubbo.config.annotation.Service; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.StringRedisTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.transaction.annotation.Transactional; import org.yeshi.utils.StringUtil; import org.yeshi.utils.alipay.AlipayH5PayUtil; @@ -31,10 +31,11 @@ import java.util.Date; import java.util.Map; import java.util.UUID; -import java.util.concurrent.TimeUnit; @Service(version = "1.0") public class VipOrderPayServiceImpl implements VipOrederPayService { + + Logger logger = LoggerFactory.getLogger(VipOrederPayService.class); @Resource private VipOrderMapper vipOrderMapper; @@ -133,6 +134,7 @@ String payUrl = PayUtil.createWXOrder(ip, orderId, order.getPayMoney(), goodsTitle, notifyUrl, returnUrl); return new PayWayInfoDTO(PayWayEnum.weChat, payUrl, null); } catch (Exception e) { + logger.error("鍒涘缓寰俊鏀粯鍑洪敊", e); throw new OrderPayException(OrderPayException.CODE_CREATE_PAY_ORDER_FAIL, e.getMessage()); } } @@ -152,9 +154,12 @@ @Override @Transactional(rollbackFor = Exception.class) - public VipOrder checkOrderPayState(Long id) { + public VipOrder checkOrderPayState(Long id) throws VipOrderException, OrderPayException { VipOrder order = vipOrderMapper.selectByPrimaryKey(id); - if (order == null || order.getState() == VipOrder.STATE_PAY) { + if (order == null) { + throw new VipOrderException(VipOrderException.CODE_NOT_EXIST, "璁㈠崟涓嶅瓨鍦�"); + } + if (order.getState() == VipOrder.STATE_PAY) { return order; } switch (order.getPayWay()) { @@ -162,31 +167,33 @@ case "alipay": AlipayTradeQueryResponse res = null; try { - res = AlipayH5PayUtil.queryOrder(PayUtil.getAlipayApp(), id + "", null); + res = AlipayH5PayUtil.queryOrder(PayUtil.getAlipayApp(), order.getThreeOrderId(), null); //鏀粯鎴愬姛 if (res.isSuccess() && "TRADE_SUCCESS".equalsIgnoreCase(res.getTradeStatus())) { - try { - return paySuccess(order); - } catch (Exception e) { - e.printStackTrace(); - } + return paySuccess(order); + } else { + throw new OrderPayException(OrderPayException.CODE_PAY_FAIL, "鏀粯瀹濅粯娆炬湭鎴愬姛"); } } catch (AlipayApiException e) { - e.printStackTrace(); + throw new OrderPayException(OrderPayException.CODE_API_ERROR, "鏀粯瀹濇帴鍙h姹傚嚭閿欙細" + e.getErrMsg()); } //寰俊 case "weChat": + WXPayOrderInfoV3 info = null; try { - WXPayOrderInfoV3 info = WXPayV3Util.getPayOrderInfo(id + "", PayUtil.getWXAPP()); - if (info != null && info.getTrade_state().equalsIgnoreCase("SUCCESS")) { - paySuccess(order); - return order; - } + info = WXPayV3Util.getPayOrderInfo(order.getThreeOrderId(), PayUtil.getWXAPP()); } catch (Exception e) { - e.printStackTrace(); + throw new OrderPayException(OrderPayException.CODE_API_ERROR, "寰俊鏀粯鎺ュ彛璇锋眰鍑洪敊锛�" + e.getMessage()); } + if (info != null && info.getTrade_state().equalsIgnoreCase("SUCCESS")) { + paySuccess(order); + return order; + } else { + throw new OrderPayException(OrderPayException.CODE_PAY_FAIL, "寰俊浠樻鏈垚鍔�"); + } + default: + throw new OrderPayException(OrderPayException.CODE_PAY_WAY_NOT_EXIST, "浠樻鏂瑰紡涓嶅瓨鍦�"); } - return null; } @Override -- Gitblit v1.8.0