|
|
|
|
@ -7,13 +7,25 @@ import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.bonus.constant.LeConstants;
|
|
|
|
|
import com.bonus.core.common.utils.LogUtil;
|
|
|
|
|
import com.bonus.core.marketing.v2.api.MarketApi;
|
|
|
|
|
import com.bonus.core.order.common.business.OrderPlaceBusiness;
|
|
|
|
|
import com.bonus.core.order.common.business.OrderResultBusiness;
|
|
|
|
|
import com.bonus.core.order.common.model.OrderDetail;
|
|
|
|
|
import com.bonus.core.order.common.model.OrderInfo;
|
|
|
|
|
import com.bonus.core.order.common.model.*;
|
|
|
|
|
import com.bonus.core.order.common.service.OrderAmountChangeService;
|
|
|
|
|
import com.bonus.core.order.common.service.OrderDeliveryService;
|
|
|
|
|
import com.bonus.core.order.common.service.OrderDetailService;
|
|
|
|
|
import com.bonus.core.order.common.service.OrderInfoService;
|
|
|
|
|
import com.bonus.core.order.custom.OrderCustomBusiness;
|
|
|
|
|
import com.bonus.core.order.mq.po.OrderSavePO;
|
|
|
|
|
import com.bonus.core.pay.api.PayApi;
|
|
|
|
|
import com.bonus.core.pay.api.TradeRecordApi;
|
|
|
|
|
import com.bonus.core.pay.api.dto.UnifyPaySelectDTO;
|
|
|
|
|
import com.bonus.core.pay.api.vo.UnifyPaySelectVO;
|
|
|
|
|
import com.bonus.core.pay.api.vo.UnifyPayVO;
|
|
|
|
|
import com.bonus.core.pay.common.constants.PayStateEnum;
|
|
|
|
|
import com.bonus.core.pay.common.model.TradeRecord;
|
|
|
|
|
import com.bonus.core.pay.common.po.PayResultPO;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
@ -48,21 +60,21 @@ public class OrderResultBusinessImpl implements OrderResultBusiness {
|
|
|
|
|
@Autowired
|
|
|
|
|
@Lazy
|
|
|
|
|
protected OrderInfoService orderInfoService;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected OrderDetailService orderDetailService;
|
|
|
|
|
@Autowired
|
|
|
|
|
@Lazy
|
|
|
|
|
protected OrderDetailService orderDetailService;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected OrderRefundDetailService orderRefundDetailService;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected OrderAmountChangeService orderAmountChangeService;
|
|
|
|
|
@Autowired
|
|
|
|
|
@Lazy
|
|
|
|
|
protected OrderAmountChangeService orderAmountChangeService;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected OrderAmountDetailService orderAmountDetailService;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected OrderDeliveryService orderDeliveryService;
|
|
|
|
|
@Autowired
|
|
|
|
|
@Lazy
|
|
|
|
|
protected OrderDeliveryService orderDeliveryService;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected MacWeighBindService macWeighBindService;
|
|
|
|
|
@ -72,12 +84,12 @@ public class OrderResultBusinessImpl implements OrderResultBusiness {
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected OrderRepairService orderRepairService;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected PayApi payApi;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected TradeRecordApi tradeRecordApi;
|
|
|
|
|
@Autowired
|
|
|
|
|
@Lazy
|
|
|
|
|
protected PayApi payApi;
|
|
|
|
|
@Autowired
|
|
|
|
|
@Lazy
|
|
|
|
|
protected TradeRecordApi tradeRecordApi;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// @Lazy
|
|
|
|
|
// protected MktCouponApi mktCouponApi;
|
|
|
|
|
@ -94,30 +106,31 @@ public class OrderResultBusinessImpl implements OrderResultBusiness {
|
|
|
|
|
@Lazy
|
|
|
|
|
protected MarketApi marketApi;
|
|
|
|
|
|
|
|
|
|
// public UnifyPaySelectVO reSyncOrderPayResult(Long orderId) {
|
|
|
|
|
// UnifyPaySelectVO unifyPaySelectVO = this.orderCustomBusiness.result().willReSyncOrderPayResult(orderId);
|
|
|
|
|
// if (unifyPaySelectVO != null) {
|
|
|
|
|
// return unifyPaySelectVO;
|
|
|
|
|
// } else {
|
|
|
|
|
// OrderInfo orderInfo = this.orderInfoService.checkAndGetOrderInfo(orderId);
|
|
|
|
|
// this.orderPlaceBusiness.orderHandlerLock(orderInfo.getMacOrderId(), 45);
|
|
|
|
|
//
|
|
|
|
|
// UnifyPaySelectVO var9;
|
|
|
|
|
// try {
|
|
|
|
|
// UnifyPaySelectVO paySelectVO = this.payApi.paySelect((new UnifyPaySelectDTO()).setOrderRechargeId(orderId));
|
|
|
|
|
// if (PayStateEnum.isFinishedState(paySelectVO.getCode())) {
|
|
|
|
|
// TradeRecord tradeRecord = this.tradeRecordApi.getTradeRecordById(paySelectVO.getTradeId());
|
|
|
|
|
// this.asyncPayResultHandler(PayResultPO.of(tradeRecord));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// var9 = paySelectVO;
|
|
|
|
|
// } finally {
|
|
|
|
|
// this.orderPlaceBusiness.orderHandlerUnLock(orderInfo.getMacOrderId());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return var9;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
public UnifyPaySelectVO reSyncOrderPayResult(Long orderId) {
|
|
|
|
|
UnifyPaySelectVO unifyPaySelectVO = this.orderCustomBusiness.result().willReSyncOrderPayResult(orderId);
|
|
|
|
|
if (unifyPaySelectVO != null) {
|
|
|
|
|
return unifyPaySelectVO;
|
|
|
|
|
} else {
|
|
|
|
|
OrderInfo orderInfo = this.orderInfoService.checkAndGetOrderInfo(orderId);
|
|
|
|
|
this.orderPlaceBusiness.orderHandlerLock(orderInfo.getMacOrderId(), 45);
|
|
|
|
|
|
|
|
|
|
UnifyPaySelectVO var9;
|
|
|
|
|
try {
|
|
|
|
|
UnifyPaySelectVO paySelectVO = this.payApi.paySelect((new UnifyPaySelectDTO()).setOrderRechargeId(orderId));
|
|
|
|
|
if (PayStateEnum.isFinishedState(paySelectVO.getCode())) {
|
|
|
|
|
TradeRecord tradeRecord = this.tradeRecordApi.getTradeRecordById(paySelectVO.getTradeId());
|
|
|
|
|
this.asyncPayResultHandler(PayResultPO.of(tradeRecord));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var9 = paySelectVO;
|
|
|
|
|
} finally {
|
|
|
|
|
this.orderPlaceBusiness.orderHandlerUnLock(orderInfo.getMacOrderId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return var9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// public UnifyRefundSelectVO reSyncOrderRefundResult(Long orderRefundId) {
|
|
|
|
|
// UnifyRefundSelectVO unifyRefundSelectVO = this.orderCustomBusiness.result().willReSyncOrderRefundResult(orderRefundId);
|
|
|
|
|
@ -143,59 +156,59 @@ public class OrderResultBusinessImpl implements OrderResultBusiness {
|
|
|
|
|
// return var9;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// public String asyncPayResultHandler(PayResultPO payResultPO) {
|
|
|
|
|
// LogUtil.info("订单异步支付|支付结果处理", payResultPO);
|
|
|
|
|
// if (!this.orderCustomBusiness.result().willHandleAsyncPayResult(payResultPO)) {
|
|
|
|
|
// return null;
|
|
|
|
|
// } else {
|
|
|
|
|
// List<OrderInfo> orderInfoList = this.orderInfoService.getOrderInfoListByTradeId(payResultPO.getTradeId());
|
|
|
|
|
// if (CollUtil.isEmpty(orderInfoList)) {
|
|
|
|
|
// log.warn("订单异步支付|支付结果处理|订单不存在 tradeId={}", payResultPO.getTradeId());
|
|
|
|
|
// return null;
|
|
|
|
|
// } else if (orderInfoList.stream().anyMatch((s) -> {
|
|
|
|
|
// return PayStateEnum.isPaidState(s.getPayState());
|
|
|
|
|
// }) && !this.orderRepeatPayCheck(payResultPO, orderInfoList)) {
|
|
|
|
|
// LogUtil.info("订单异步支付|支付结果处理|订单已支付 ", orderInfoList);
|
|
|
|
|
// return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
// } else if (((OrderInfo)orderInfoList.get(0)).getPayState().equals(payResultPO.getTradeState())) {
|
|
|
|
|
// LogUtil.info("订单异步支付|支付结果处理|订单支付状态已处理 ", orderInfoList);
|
|
|
|
|
// return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
// } else if (PayStateEnum.isPayingState(payResultPO.getTradeState())) {
|
|
|
|
|
// LogUtil.info("订单异步支付|支付结果处理|支付中 ");
|
|
|
|
|
// return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
// } else {
|
|
|
|
|
// List<Long> orderIdList = (List)orderInfoList.stream().map(OrderInfo::getOrderId).collect(Collectors.toList());
|
|
|
|
|
// List<LocalDate> orderDateList = (List)orderInfoList.stream().map(OrderInfo::getOrderDate).collect(Collectors.toList());
|
|
|
|
|
// List<OrderDetail> orderDetailList = this.orderDetailService.getOrderDetailList((List)orderIdList, (Collection)orderDateList);
|
|
|
|
|
// if (PayStateEnum.isPayingState(payResultPO.getTradeState())) {
|
|
|
|
|
// orderInfoList.forEach((s) -> {
|
|
|
|
|
// this.orderInfoService.updateOrderState(s.getOrderId(), s.getOrderDate(), payResultPO.getTradeState(), (Integer)null, (Integer)null, (String)null);
|
|
|
|
|
// });
|
|
|
|
|
// return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
// } else if (PayStateEnum.isFailedState(payResultPO.getTradeState())) {
|
|
|
|
|
// this.orderDidFailedHandler(orderInfoList, orderDetailList, payResultPO.getTradeState(), true);
|
|
|
|
|
// return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
// } else {
|
|
|
|
|
// List<OrderAmountChange> amountChangeList = this.orderAmountChangeService.listByOrderIds(orderIdList, orderDateList);
|
|
|
|
|
// UnifyPayVO payVO = UnifyPayVO.of(this.tradeRecordApi.getTradeRecordById(payResultPO.getTradeId()), this.tradeRecordApi.listChannelDetailByTradeId(payResultPO.getTradeId()));
|
|
|
|
|
// List<OrderAmountDetail> orderAmountDetails = this.orderPlaceBusiness.calcOrderRealAmount(orderInfoList, orderDetailList, amountChangeList, payVO.getRealAmount(), payVO.getDetailList());
|
|
|
|
|
// Iterator var9 = orderInfoList.iterator();
|
|
|
|
|
//
|
|
|
|
|
// while(var9.hasNext()) {
|
|
|
|
|
// OrderInfo orderInfo = (OrderInfo)var9.next();
|
|
|
|
|
// this.orderPlaceBusiness.updateOrderFieldAfterPay(orderInfo, OrderDidPayInfoDTO.of(payVO));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// this.orderInfoService.initOrderCustInfo(orderInfoList, payVO.getCustId());
|
|
|
|
|
// this.orderPlaceBusiness.save(OrderSavePO.byOrderInfo(orderInfoList, orderDetailList, ListUtil.empty(), orderAmountDetails), false, false);
|
|
|
|
|
// List<OrderDelivery> orderDeliveryList = this.orderDeliveryService.listOrderDeliveryByOrderIds(orderIdList, orderDateList);
|
|
|
|
|
// OrderMessageSend.orderV3Placed(payResultPO.getOutTradeNo(), orderInfoList, orderDetailList, orderDeliveryList, amountChangeList, orderAmountDetails);
|
|
|
|
|
// return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public String asyncPayResultHandler(PayResultPO payResultPO) {
|
|
|
|
|
LogUtil.info("订单异步支付|支付结果处理", payResultPO);
|
|
|
|
|
if (!this.orderCustomBusiness.result().willHandleAsyncPayResult(payResultPO)) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
List<OrderInfo> orderInfoList = this.orderInfoService.getOrderInfoListByTradeId(payResultPO.getTradeId());
|
|
|
|
|
if (CollUtil.isEmpty(orderInfoList)) {
|
|
|
|
|
log.warn("订单异步支付|支付结果处理|订单不存在 tradeId={}", payResultPO.getTradeId());
|
|
|
|
|
return null;
|
|
|
|
|
} else if (orderInfoList.stream().anyMatch((s) -> {
|
|
|
|
|
return PayStateEnum.isPaidState(s.getPayState());
|
|
|
|
|
}) && !this.orderRepeatPayCheck(payResultPO, orderInfoList)) {
|
|
|
|
|
LogUtil.info("订单异步支付|支付结果处理|订单已支付 ", orderInfoList);
|
|
|
|
|
return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
} else if (((OrderInfo)orderInfoList.get(0)).getPayState().equals(payResultPO.getTradeState())) {
|
|
|
|
|
LogUtil.info("订单异步支付|支付结果处理|订单支付状态已处理 ", orderInfoList);
|
|
|
|
|
return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
} else if (PayStateEnum.isPayingState(payResultPO.getTradeState())) {
|
|
|
|
|
LogUtil.info("订单异步支付|支付结果处理|支付中 ");
|
|
|
|
|
return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
} else {
|
|
|
|
|
List<Long> orderIdList = (List)orderInfoList.stream().map(OrderInfo::getOrderId).collect(Collectors.toList());
|
|
|
|
|
List<LocalDate> orderDateList = (List)orderInfoList.stream().map(OrderInfo::getOrderDate).collect(Collectors.toList());
|
|
|
|
|
List<OrderDetail> orderDetailList = this.orderDetailService.getOrderDetailList((List)orderIdList, (Collection)orderDateList);
|
|
|
|
|
if (PayStateEnum.isPayingState(payResultPO.getTradeState())) {
|
|
|
|
|
orderInfoList.forEach((s) -> {
|
|
|
|
|
this.orderInfoService.updateOrderState(s.getOrderId(), s.getOrderDate(), payResultPO.getTradeState(), (Integer)null, (Integer)null, (String)null);
|
|
|
|
|
});
|
|
|
|
|
return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
} else if (PayStateEnum.isFailedState(payResultPO.getTradeState())) {
|
|
|
|
|
this.orderDidFailedHandler(orderInfoList, orderDetailList, payResultPO.getTradeState(), true);
|
|
|
|
|
return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
} else {
|
|
|
|
|
List<OrderAmountChange> amountChangeList = this.orderAmountChangeService.listByOrderIds(orderIdList, orderDateList);
|
|
|
|
|
UnifyPayVO payVO = UnifyPayVO.of(this.tradeRecordApi.getTradeRecordById(payResultPO.getTradeId()), this.tradeRecordApi.listChannelDetailByTradeId(payResultPO.getTradeId()));
|
|
|
|
|
List<OrderAmountDetail> orderAmountDetails = this.orderPlaceBusiness.calcOrderRealAmount(orderInfoList, orderDetailList, amountChangeList, payVO.getRealAmount(), payVO.getDetailList());
|
|
|
|
|
Iterator var9 = orderInfoList.iterator();
|
|
|
|
|
|
|
|
|
|
while(var9.hasNext()) {
|
|
|
|
|
OrderInfo orderInfo = (OrderInfo)var9.next();
|
|
|
|
|
this.orderPlaceBusiness.updateOrderFieldAfterPay(orderInfo, OrderDidPayInfoDTO.of(payVO));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.orderInfoService.initOrderCustInfo(orderInfoList, payVO.getCustId());
|
|
|
|
|
this.orderPlaceBusiness.save(OrderSavePO.byOrderInfo(orderInfoList, orderDetailList, ListUtil.empty(), orderAmountDetails), false, false);
|
|
|
|
|
List<OrderDelivery> orderDeliveryList = this.orderDeliveryService.listOrderDeliveryByOrderIds(orderIdList, orderDateList);
|
|
|
|
|
OrderMessageSend.orderV3Placed(payResultPO.getOutTradeNo(), orderInfoList, orderDetailList, orderDeliveryList, amountChangeList, orderAmountDetails);
|
|
|
|
|
return ((OrderInfo)orderInfoList.get(0)).getMacOrderId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
// public void asyncRefundResultHandler(RefundResultPO refundResultPO) {
|
|
|
|
|
// LogUtil.info("订单异步退款|支付结果处理", refundResultPO);
|
|
|
|
|
|