|
|
@@ -1,9 +1,7 @@
|
|
|
package org.springblade.payment.handle;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
import org.springblade.common.enums.OrderType;
|
|
|
-import org.springblade.common.enums.PaymentScene;
|
|
|
import org.springblade.common.enums.ResCode;
|
|
|
import org.springblade.common.enums.SystemConstant;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
@@ -25,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
|
-
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
@@ -60,7 +57,7 @@ public class Trade {
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
- public boolean trade(Order order, long channelId) throws Exception {
|
|
|
+ public boolean tradeForPayCode(Order order, long channelId) throws Exception {
|
|
|
/**
|
|
|
* 交易处理链,每个handle处理负责一个业务节点
|
|
|
* 1、处理各种商家折扣,计算实际交易金额
|
|
|
@@ -103,10 +100,59 @@ public class Trade {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ public SuccessParams tradeForScanPay(Order order, long channelId) throws Exception {
|
|
|
+ /**
|
|
|
+ * 交易处理链,每个handle处理负责一个业务节点
|
|
|
+ * 1、处理各种商家折扣,计算实际交易金额
|
|
|
+ * 2、用户渠道积分用以抵消交易金额
|
|
|
+ * 3、用户账户余额抵消交易金额
|
|
|
+ * 4、保存订单信息
|
|
|
+ * */
|
|
|
+ List<BaseHandle> chain = new ArrayList(){{
|
|
|
+ add(new DiscountHandle(shopService,activityService,joinRecordService));
|
|
|
+ add(new ChannelPointHandle(pointBillsService,userChannelPointService));
|
|
|
+ add(new BalanceHandle(balanceBillsService));
|
|
|
+ }} ;
|
|
|
+
|
|
|
+ BigDecimal remain = order.getMoney();
|
|
|
+
|
|
|
+ Bills bills = initBill(order,channelId);
|
|
|
+
|
|
|
+ //支付参数
|
|
|
+ SuccessParams successParams = SuccessParams.builder()
|
|
|
+ .orderType(OrderType.USER_PAY.name())
|
|
|
+ .status(SystemConstant.BillPayStatus.待付款.name())
|
|
|
+ .userId(order.getLoginUser().getId())
|
|
|
+ .totalPrice(order.getMoney())
|
|
|
+ .bills(bills)
|
|
|
+ .shopId(order.getShopId())
|
|
|
+ .channelId(channelId)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ //处理各个节点
|
|
|
+ for (BaseHandle node: chain) {
|
|
|
+ HandleData res = node.handle(remain, order,successParams);
|
|
|
+ Assert.isTrue(res.isSuccess(),()->{throw new ServiceException(ResCode.TRADE_ERROR);});
|
|
|
+ remain = res.getRemain();
|
|
|
+ successParams = res.getSuccessParams();
|
|
|
+
|
|
|
+ if(remain.compareTo(BigDecimal.ZERO)==0){
|
|
|
+ //处理积分余额数据变更
|
|
|
+ paymentService.success(successParams);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(remain.compareTo(BigDecimal.ZERO)>0){
|
|
|
+ Assert.isTrue(billsService.saveOrUpdate(successParams.getBills()),()->{throw new ServiceException(ResCode.TRADE_ERROR);});
|
|
|
+ }
|
|
|
+ return successParams;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 初始化交易账单
|
|
|
@@ -126,4 +172,6 @@ public class Trade {
|
|
|
bills.setReceiveId(order.getShopId());
|
|
|
return bills;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|