|
@@ -1,11 +1,13 @@
|
|
|
package org.springblade.payment.handle;
|
|
package org.springblade.payment.handle;
|
|
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
import org.springblade.common.cache.PaymentCache;
|
|
import org.springblade.common.cache.PaymentCache;
|
|
|
import org.springblade.common.enums.AppConstant;
|
|
import org.springblade.common.enums.AppConstant;
|
|
|
import org.springblade.common.enums.OrderType;
|
|
import org.springblade.common.enums.OrderType;
|
|
|
import org.springblade.common.enums.ResCode;
|
|
import org.springblade.common.enums.ResCode;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
|
|
+import org.springblade.ldt.bills.entity.BalanceBills;
|
|
|
import org.springblade.ldt.bills.entity.Bills;
|
|
import org.springblade.ldt.bills.entity.Bills;
|
|
|
import org.springblade.ldt.user.service.IUserChannelPointService;
|
|
import org.springblade.ldt.user.service.IUserChannelPointService;
|
|
|
import org.springblade.payment.handle.entity.HandleData;
|
|
import org.springblade.payment.handle.entity.HandleData;
|
|
@@ -22,6 +24,7 @@ import org.springblade.payment.service.IPaymentService;
|
|
|
import org.springblade.webSocket.WebSocketServer;
|
|
import org.springblade.webSocket.WebSocketServer;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
@@ -34,27 +37,16 @@ import java.util.List;
|
|
|
* @since: 8/26/21 -- 5:53 PM
|
|
* @since: 8/26/21 -- 5:53 PM
|
|
|
*/
|
|
*/
|
|
|
@Component
|
|
@Component
|
|
|
|
|
+@AllArgsConstructor
|
|
|
public class Trade {
|
|
public class Trade {
|
|
|
- @Autowired
|
|
|
|
|
|
|
+
|
|
|
private IBillsService billsService;
|
|
private IBillsService billsService;
|
|
|
- @Autowired
|
|
|
|
|
- private IPointBillsService pointBillsService;
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private IBalanceBillsService balanceBillsService;
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private WebSocketServer webSocketServer;
|
|
|
|
|
- @Autowired
|
|
|
|
|
private IPaymentService paymentService;
|
|
private IPaymentService paymentService;
|
|
|
- @Autowired
|
|
|
|
|
- private IShopService shopService;
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private IActivityService activityService;
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private IJoinRecordService joinRecordService;
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private IUserChannelPointService userChannelPointService ;
|
|
|
|
|
- @Autowired
|
|
|
|
|
private DataHandle dataHandle ;
|
|
private DataHandle dataHandle ;
|
|
|
|
|
+ private BalanceHandle balanceHandle;
|
|
|
|
|
+ private ChannelPointHandle channelPointHandle;
|
|
|
|
|
+ private DiscountHandle discountHandle;
|
|
|
|
|
+ private WxPayHandle wxPayHandle;
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@@ -67,10 +59,10 @@ public class Trade {
|
|
|
* 4、剩余金额用户微信支付
|
|
* 4、剩余金额用户微信支付
|
|
|
* */
|
|
* */
|
|
|
List<BaseHandle> chain = new ArrayList(){{
|
|
List<BaseHandle> chain = new ArrayList(){{
|
|
|
- add(new DiscountHandle(shopService,activityService,joinRecordService));
|
|
|
|
|
- add(new ChannelPointHandle(pointBillsService,userChannelPointService));
|
|
|
|
|
- add(new BalanceHandle(billsService,balanceBillsService,dataHandle));
|
|
|
|
|
- add(new WxPayHandle(webSocketServer));
|
|
|
|
|
|
|
+ add(discountHandle);
|
|
|
|
|
+ add(channelPointHandle);
|
|
|
|
|
+ add(balanceHandle);
|
|
|
|
|
+ add(wxPayHandle);
|
|
|
}} ;
|
|
}} ;
|
|
|
|
|
|
|
|
BigDecimal remain = order.getMoney();
|
|
BigDecimal remain = order.getMoney();
|
|
@@ -114,9 +106,9 @@ public class Trade {
|
|
|
* 4、保存订单信息
|
|
* 4、保存订单信息
|
|
|
* */
|
|
* */
|
|
|
List<BaseHandle> chain = new ArrayList(){{
|
|
List<BaseHandle> chain = new ArrayList(){{
|
|
|
- add(new DiscountHandle(shopService,activityService,joinRecordService));
|
|
|
|
|
- add(new ChannelPointHandle(pointBillsService,userChannelPointService));
|
|
|
|
|
- add(new BalanceHandle(billsService,balanceBillsService,dataHandle));
|
|
|
|
|
|
|
+ add(discountHandle);
|
|
|
|
|
+ add(channelPointHandle);
|
|
|
|
|
+ add(balanceHandle);
|
|
|
}} ;
|
|
}} ;
|
|
|
|
|
|
|
|
BigDecimal remain = order.getMoney();
|
|
BigDecimal remain = order.getMoney();
|
|
@@ -142,6 +134,8 @@ public class Trade {
|
|
|
successParams = res.getSuccessParams();
|
|
successParams = res.getSuccessParams();
|
|
|
|
|
|
|
|
if(remain.compareTo(BigDecimal.ZERO)==0){
|
|
if(remain.compareTo(BigDecimal.ZERO)==0){
|
|
|
|
|
+ //新建事务,保存订单信息,
|
|
|
|
|
+ Assert.isTrue(dataHandle.saveOrUpdateEntity(billsService,successParams.getBills()),()->{throw new ServiceException(ResCode.TRADE_ERROR);});
|
|
|
//处理积分余额数据变更
|
|
//处理积分余额数据变更
|
|
|
paymentService.success(successParams);
|
|
paymentService.success(successParams);
|
|
|
break;
|
|
break;
|
|
@@ -151,9 +145,8 @@ public class Trade {
|
|
|
bills.setPrice(remain);
|
|
bills.setPrice(remain);
|
|
|
}
|
|
}
|
|
|
//新建事务,保存订单信息,
|
|
//新建事务,保存订单信息,
|
|
|
- Assert.isTrue(dataHandle.saveBills(billsService,successParams.getBills()),()->{throw new ServiceException(ResCode.TRADE_ERROR);});
|
|
|
|
|
|
|
+ Assert.isTrue(dataHandle.saveOrUpdateEntity(billsService,successParams.getBills()),()->{throw new ServiceException(ResCode.TRADE_ERROR);});
|
|
|
PaymentCache.putSuccessParams(Convert.toStr(successParams.getBills().getId()),successParams);
|
|
PaymentCache.putSuccessParams(Convert.toStr(successParams.getBills().getId()),successParams);
|
|
|
-
|
|
|
|
|
return successParams;
|
|
return successParams;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -181,5 +174,4 @@ public class Trade {
|
|
|
return bills;
|
|
return bills;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|