From 9904e44eaf0b9e82afd843cfa3578c4ec7b9d66e Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 11 Mar 2025 09:38:19 +0800 Subject: [PATCH] =?UTF-8?q?0=E5=85=83=E4=BB=98=E6=AC=BE=20=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=8A=B6=E6=80=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/service/impl/PayServiceImpl.java | 80 ++++++++----------- 1 file changed, 32 insertions(+), 48 deletions(-) diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/PayServiceImpl.java b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/PayServiceImpl.java index d6767be0..a6d457f9 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/PayServiceImpl.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/PayServiceImpl.java @@ -113,6 +113,9 @@ public class PayServiceImpl implements PayService { * @return 是否是霸王餐充值 */ private boolean checkPayVip(VipPayParamDTO payParam) { + if (payParam.getAmount().compareTo(BigDecimal.ZERO) <= 0) { + throw new ValidateException("充值金额不正确"); + } if (payParam.getOrderId() != null) { OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId()); AssertUtil.isNull(orderInfo, "订单不存在"); @@ -135,7 +138,7 @@ public class PayServiceImpl implements PayService { @Override - @Transactional + @Transactional(noRollbackFor = PaySuccessException.class) public CzgResult creditPayOrder(OrderPayParamDTO payParam) { AssertUtil.isNull(payParam.getCreditBuyerId(), "挂账人不可为空"); OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); @@ -149,7 +152,7 @@ public class PayServiceImpl implements PayService { } @Override - @Transactional + @Transactional(noRollbackFor = PaySuccessException.class) public CzgResult cashPayOrder(OrderPayParamDTO payParam) { OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); orderInfoService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(), @@ -163,7 +166,7 @@ public class PayServiceImpl implements PayService { } @Override - @Transactional + @Transactional(noRollbackFor = PaySuccessException.class) public CzgResult vipPayOrder(OrderPayParamDTO payParam) { AssertUtil.isNull(payParam.getCheckOrderPay().getUserId(), "会员支付,订单用户不能为空"); OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); @@ -215,7 +218,7 @@ public class PayServiceImpl implements PayService { } @Override - @Transactional + @Transactional(noRollbackFor = PaySuccessException.class) public CzgResult> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) { OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId(); @@ -228,7 +231,7 @@ public class PayServiceImpl implements PayService { @Override - @Transactional + @Transactional(noRollbackFor = PaySuccessException.class) public CzgResult> jsPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) { OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空"); @@ -242,7 +245,7 @@ public class PayServiceImpl implements PayService { } @Override - @Transactional + @Transactional(noRollbackFor = PaySuccessException.class) public CzgResult> js2PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) { AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空"); AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空"); @@ -262,7 +265,7 @@ public class PayServiceImpl implements PayService { } @Override - @Transactional + @Transactional(noRollbackFor = PaySuccessException.class) public CzgResult> ltPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) { OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空"); @@ -276,7 +279,7 @@ public class PayServiceImpl implements PayService { } @Override - @Transactional + @Transactional(noRollbackFor = PaySuccessException.class) public CzgResult> scanPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) { OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); @@ -289,7 +292,7 @@ public class PayServiceImpl implements PayService { } @Override - @Transactional + @Transactional(noRollbackFor = PaySuccessException.class) public CzgResult> microPayOrder(OrderPayParamDTO payParam) { OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空"); @@ -487,6 +490,9 @@ public class PayServiceImpl implements PayService { @Transactional public CzgResult refundOrderBefore(OrderInfoRefundDTO param) { OrderInfo orderInfo = orderInfoService.getById(param.getOrderId()); + if (orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) { + return CzgResult.failure("订单未支付,无法退款"); + } Map returnProMap = new HashMap<>(); boolean isPay = true; String refPayOrderNo = "REFO" + IdUtil.getSnowflakeNextId(); @@ -557,45 +563,23 @@ public class PayServiceImpl implements PayService { //总退款金额 //TODO 退款 券 未处理 if (isPay) { - if (param.isModify()) { - //非现金退款 - if (!param.isCash()) { - if (orderInfo.getPayType().equals(PayEnums.VIP_PAY.getValue())) { - ShopUser shopUser = shopUserService.getShopUserInfo(orderInfo.getShopId(), orderInfo.getUserId()); - //会员支付 退钱 - ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder() - .id(shopUser.getId()) - .money(param.getRefundAmount()) - .type(1) - .relationId(orderInfo.getId()) - .bizEnum(ShopUserFlowBizEnum.ORDER_REFUND) - .build(); - shopUserService.updateMoney(orderInfo.getShopId(), shopUserMoneyEditDTO); - } else if (!orderInfo.getPayType().equals(PayEnums.CASH_PAY.getValue())) { - //退款 param.getRefundAmount() - refundOrder(orderInfo.getShopId(), orderInfo.getId(), orderInfo.getPayOrderId(), - refPayOrderNo, param.getRefundReason(), param.getRefundAmount()); - } - } - } else { - //非现金退款 - if (!param.isCash()) { - if (orderInfo.getPayType().equals(PayEnums.VIP_PAY.getValue())) { - ShopUser shopUser = shopUserService.getShopUserInfo(orderInfo.getShopId(), orderInfo.getUserId()); - //会员支付 退钱 - ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder() - .id(shopUser.getId()) - .money(param.getRefundAmount()) - .type(1) - .relationId(orderInfo.getId()) - .bizEnum(ShopUserFlowBizEnum.ORDER_REFUND) - .build(); - shopUserService.updateMoney(orderInfo.getShopId(), shopUserMoneyEditDTO); - } else if (!orderInfo.getPayType().equals(PayEnums.CASH_PAY.getValue())) { - //退款 param.getRefundAmount() - refundOrder(orderInfo.getShopId(), orderInfo.getId(), orderInfo.getPayOrderId(), - refPayOrderNo, param.getRefundReason(), param.getRefundAmount()); - } + //非现金退款 + if (!param.isCash()) { + if (orderInfo.getPayType().equals(PayEnums.VIP_PAY.getValue())) { + ShopUser shopUser = shopUserService.getShopUserInfo(orderInfo.getShopId(), orderInfo.getUserId()); + //会员支付 退钱 + ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder() + .id(shopUser.getId()) + .money(param.getRefundAmount()) + .type(1) + .relationId(orderInfo.getId()) + .bizEnum(ShopUserFlowBizEnum.ORDER_REFUND) + .build(); + shopUserService.updateMoney(orderInfo.getShopId(), shopUserMoneyEditDTO); + } else if (!orderInfo.getPayType().equals(PayEnums.CASH_PAY.getValue())) { + //退款 param.getRefundAmount() + refundOrder(orderInfo.getShopId(), orderInfo.getId(), orderInfo.getPayOrderId(), + refPayOrderNo, param.getRefundReason(), param.getRefundAmount()); } } } else {