Sfoglia il codice sorgente

正常情况下下单冻结用户余额或积分

july 4 anni fa
parent
commit
397fd668cf

+ 4 - 59
ldt-core/src/main/java/org/springblade/common/utils/GlobalExceptionHandler.java

@@ -2,28 +2,19 @@ package org.springblade.common.utils;
 
 import com.yeepay.yop.sdk.exception.YopServiceException;
 import org.apache.commons.lang3.ObjectUtils;
-import org.springblade.common.enums.AppConstant;
 import org.springblade.core.tool.api.R;
-import org.springblade.ldt.bills.entity.BalanceBills;
-import org.springblade.ldt.bills.entity.Bills;
-import org.springblade.ldt.bills.entity.FrozenRec;
-import org.springblade.ldt.bills.entity.PointBills;
 import org.springblade.ldt.bills.service.IBalanceBillsService;
 import org.springblade.ldt.bills.service.IBillsService;
 import org.springblade.ldt.bills.service.IFrozenRecService;
 import org.springblade.ldt.bills.service.IPointBillsService;
-import org.springblade.ldt.user.entity.LoginUser;
-import org.springblade.ldt.user.entity.UserChannelPoint;
 import org.springblade.ldt.user.service.ILoginUserService;
 import org.springblade.ldt.user.service.IUserChannelPointService;
-import org.springblade.payment.entity.SuccessParams;
+import org.springblade.payment.handle.handler.CancelTradeHandle;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import java.util.Objects;
-
 
 /**
  * @author July
@@ -35,12 +26,7 @@ import java.util.Objects;
 @ControllerAdvice
 @ResponseBody
 public class GlobalExceptionHandler {
-	private ILoginUserService loginUserService;
-	private IBillsService billsService;
-	private IPointBillsService pointBillsService;
-	private IBalanceBillsService balanceBillsService;
-	private IFrozenRecService frozenRecService;
-	private IUserChannelPointService userChannelPointService;
+	private CancelTradeHandle cancelTradeHandle;
 
 	@ExceptionHandler(YopServiceException.class)
 	public R defaultErrorHandler(YopServiceException e) {
@@ -50,49 +36,8 @@ public class GlobalExceptionHandler {
 	@Transactional
 	@ExceptionHandler(TradeException.class)
 	public R tradeErrorHandler(TradeException e) {
-		SuccessParams successParams = e.getSuccessParams();
-
-		if (ObjectUtils.isNotEmpty(successParams)) {
-			Bills bills = successParams.getBills();
-			synchronized (bills.getId().toString().intern()) {
-				FrozenRec frozenRec = frozenRecService.getById(bills.getId());
-				UserChannelPoint channelPoint = userChannelPointService.getById(successParams.getChannelId());
-
-				//修改用户冻结余额或积分
-				LoginUser user = loginUserService.getById(bills.getPayId());
-				if (ObjectUtils.isNotEmpty(user)) {
-					if (Objects.equals(frozenRec.getFrozenType(), "point")) {
-						user.setChannelPoint(user.getChannelPoint().add(frozenRec.getFrozenNum()));
-						user.setFrozenPoint(user.getFrozenPoint().subtract(frozenRec.getFrozenNum()));
-						if (ObjectUtils.isNotEmpty(channelPoint)) {
-							channelPoint.setAvailable(channelPoint.getAvailable().add(frozenRec.getFrozenNum()));
-							userChannelPointService.saveOrUpdate(channelPoint);
-						}
-					} else if (Objects.equals(frozenRec.getFrozenType(), "balance")) {
-						user.setBalance(user.getBalance().add(frozenRec.getFrozenNum()));
-						user.setFrozenBalance(user.getFrozenBalance().subtract(frozenRec.getFrozenNum()));
-					}
-				}
-
-				if (ObjectUtils.isNotEmpty(frozenRec)) {
-					frozenRecService.removeById(frozenRec);
-				}
-				loginUserService.saveOrUpdate(user);
-			}
-			bills.setPayStatus(AppConstant.BillPayStatus.取消付款.name());
-			billsService.saveOrUpdate(bills);
-
-			PointBills pointBills = pointBillsService.getById(successParams.getPointBillsId());
-			if (ObjectUtils.isNotEmpty(pointBills)) {
-				pointBills.setPayStatus(AppConstant.BillPayStatus.取消付款.name());
-				pointBillsService.saveOrUpdate(pointBills);
-			}
-
-			BalanceBills balanceBills = balanceBillsService.getById(successParams.getBalanceBillsId());
-			if (ObjectUtils.isNotEmpty(balanceBills)) {
-				balanceBills.setPayStatus(AppConstant.BillPayStatus.取消付款.name());
-				balanceBillsService.saveOrUpdate(balanceBills);
-			}
+		if (ObjectUtils.isNotEmpty(e.getSuccessParams())) {
+			cancelTradeHandle.handle(e.getSuccessParams());
 		}
 		return R.fail(e.getResultCode(), e.getMessage());
 	}

+ 83 - 0
ldt-core/src/main/java/org/springblade/payment/handle/handler/CancelTradeHandle.java

@@ -0,0 +1,83 @@
+package org.springblade.payment.handle.handler;
+
+import lombok.AllArgsConstructor;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springblade.common.enums.AppConstant;
+import org.springblade.ldt.bills.entity.BalanceBills;
+import org.springblade.ldt.bills.entity.Bills;
+import org.springblade.ldt.bills.entity.FrozenRec;
+import org.springblade.ldt.bills.entity.PointBills;
+import org.springblade.ldt.bills.service.IBalanceBillsService;
+import org.springblade.ldt.bills.service.IBillsService;
+import org.springblade.ldt.bills.service.IFrozenRecService;
+import org.springblade.ldt.bills.service.IPointBillsService;
+import org.springblade.ldt.user.entity.LoginUser;
+import org.springblade.ldt.user.entity.UserChannelPoint;
+import org.springblade.ldt.user.service.ILoginUserService;
+import org.springblade.ldt.user.service.IUserChannelPointService;
+import org.springblade.payment.entity.SuccessParams;
+import org.springframework.stereotype.Component;
+
+import java.util.Objects;
+
+/**
+ * @author July
+ * @version 1.0.0
+ * @ClassName CancelTradeHandle.java
+ * @Description 取消交易处理
+ * @createTime 2021年11月01日 15:14:00
+ */
+@Component
+@AllArgsConstructor
+public class CancelTradeHandle {
+
+	private ILoginUserService loginUserService;
+	private IBillsService billsService;
+	private IPointBillsService pointBillsService;
+	private IBalanceBillsService balanceBillsService;
+	private IFrozenRecService frozenRecService;
+	private IUserChannelPointService userChannelPointService;
+
+	public void handle(SuccessParams successParams) {
+		Bills bills = successParams.getBills();
+		synchronized (bills.getId().toString().intern()) {
+			FrozenRec frozenRec = frozenRecService.getById(bills.getId());
+			UserChannelPoint channelPoint = userChannelPointService.getById(successParams.getChannelId());
+
+			//修改用户冻结余额或积分
+			LoginUser user = loginUserService.getById(bills.getPayId());
+			if (ObjectUtils.isNotEmpty(user)) {
+				if (Objects.equals(frozenRec.getFrozenType(), "point")) {
+					user.setChannelPoint(user.getChannelPoint().add(frozenRec.getFrozenNum()));
+					user.setFrozenPoint(user.getFrozenPoint().subtract(frozenRec.getFrozenNum()));
+					if (ObjectUtils.isNotEmpty(channelPoint)) {
+						channelPoint.setAvailable(channelPoint.getAvailable().add(frozenRec.getFrozenNum()));
+						userChannelPointService.saveOrUpdate(channelPoint);
+					}
+				} else if (Objects.equals(frozenRec.getFrozenType(), "balance")) {
+					user.setBalance(user.getBalance().add(frozenRec.getFrozenNum()));
+					user.setFrozenBalance(user.getFrozenBalance().subtract(frozenRec.getFrozenNum()));
+				}
+			}
+
+			if (ObjectUtils.isNotEmpty(frozenRec)) {
+				frozenRecService.removeById(frozenRec);
+			}
+			loginUserService.saveOrUpdate(user);
+		}
+		bills.setPayStatus(AppConstant.BillPayStatus.取消付款.name());
+		billsService.saveOrUpdate(bills);
+
+		PointBills pointBills = pointBillsService.getById(successParams.getPointBillsId());
+		if (ObjectUtils.isNotEmpty(pointBills)) {
+			pointBills.setPayStatus(AppConstant.BillPayStatus.取消付款.name());
+			pointBillsService.saveOrUpdate(pointBills);
+		}
+
+		BalanceBills balanceBills = balanceBillsService.getById(successParams.getBalanceBillsId());
+		if (ObjectUtils.isNotEmpty(balanceBills)) {
+			balanceBills.setPayStatus(AppConstant.BillPayStatus.取消付款.name());
+			balanceBillsService.saveOrUpdate(balanceBills);
+		}
+	}
+}