|
@@ -11,6 +11,7 @@ import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes;
|
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
|
+import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.toolset.base.result.BaseResult;
|
|
|
import com.yonge.toolset.payment.base.enums.OpenEnum;
|
|
|
import com.yonge.toolset.payment.base.enums.PayChannelEnum;
|
|
@@ -65,37 +66,8 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /***
|
|
|
- * 入订单付款表
|
|
|
- * @author liweifan
|
|
|
- * @param: paymentRes
|
|
|
- * @param: payReq
|
|
|
- * @updateTime 2022/5/11 18:47
|
|
|
- * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
|
|
|
- */
|
|
|
- private UserOrderPayment insertOrderPayment(Payment payment) {
|
|
|
- UserOrderPayment orderPayment = new UserOrderPayment();
|
|
|
- orderPayment.setOpenType(payment.getOpenType());
|
|
|
- orderPayment.setPayChannel(payment.getPayChannel());
|
|
|
- orderPayment.setOrderNo(payment.getOrderNo());
|
|
|
- orderPayment.setPaymentNo(payment.getPaymentNo());
|
|
|
- orderPayment.setTransNo(payment.getId());
|
|
|
- orderPayment.setPayAmt(
|
|
|
- new BigDecimal(payment.getPayAmt()).setScale(2, RoundingMode.HALF_UP)
|
|
|
- );
|
|
|
- orderPayment.setPayInfo(payment.getPayInfo());
|
|
|
- orderPayment.setStatus(TradeStatusEnum.pending);
|
|
|
-
|
|
|
- //查询订单下支付中的付款单,取消支付
|
|
|
- closePayment(payment.getOrderNo(), "用户发起了新的付款请求");
|
|
|
- //保存新的付款单
|
|
|
- save(orderPayment);
|
|
|
- return orderPayment;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
- public UserOrderPayment closePayment(String orderNo, String reason) {
|
|
|
+ public UserOrderPayment onlyClosePayment(String orderNo, String reason) {
|
|
|
UserOrderPayment orderPayment = baseMapper.selectOne(Wrappers.<UserOrderPayment>lambdaQuery()
|
|
|
.eq(UserOrderPayment::getOrderNo, orderNo)
|
|
|
.eq(UserOrderPayment::getStatus, TradeStatusEnum.pending));
|
|
@@ -108,10 +80,23 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
|
orderPayment.setPayFailMsg(StringUtil.isEmpty(reason) ? "交易取消" : reason);
|
|
|
orderPayment.setUpdateTime(new Date());
|
|
|
|
|
|
+ updateById(orderPayment);
|
|
|
+ return orderPayment;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserOrderPayment closePaymentAndReqOpen(String orderNo, String reason) {
|
|
|
+ UserOrderPayment orderPayment = onlyClosePayment(orderNo, reason);
|
|
|
+ if (null == orderPayment) {
|
|
|
+ return orderPayment;
|
|
|
+ }
|
|
|
//发送支付关单请求
|
|
|
- if (!StringUtil.isEmpty(orderPayment.getTransNo())) {
|
|
|
+ if (!StringUtil.isEmpty(orderPayment.getTransNo())
|
|
|
+ || !StringUtil.isEmpty(orderPayment.getPaymentNo())) {
|
|
|
ClosePayment param = new ClosePayment(orderPayment.getOpenType(), orderPayment.getPayChannel());
|
|
|
param.setId(orderPayment.getTransNo());
|
|
|
+ param.setPaymentNo(orderPayment.getPaymentNo());
|
|
|
param.setReason(reason);
|
|
|
|
|
|
try {
|
|
@@ -130,7 +115,6 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- updateById(orderPayment);
|
|
|
return orderPayment;
|
|
|
}
|
|
|
|
|
@@ -186,6 +170,7 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
|
String pay_info = paymentResBaseResult.getData().getPayInfo();
|
|
|
orderPayRes.setPay_info(pay_info);
|
|
|
orderPayRes.setPayChannel(payReq.getPayChannel());
|
|
|
+ orderPayRes.setPaymentNo(payment.getPaymentNo());
|
|
|
|
|
|
//入订单付款表
|
|
|
insertOrderPayment(paymentResBaseResult.getData());
|
|
@@ -202,24 +187,60 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
|
|
|
|
@Override
|
|
|
public void executePaymentCallBack(PaymentCallBack data) {
|
|
|
- if (TradeStatusEnum.succeeded.equals(data.getStatus())) {//支付成功
|
|
|
- paymentSucceededHandle(data);
|
|
|
- } else if (TradeStatusEnum.failed.equals(data.getStatus())) {//支付失败
|
|
|
- paymentFailedHandle(data, data.getErrMsg());
|
|
|
+ UserOrderVo userOrderVo = userOrderService.getUserOrderByPaymentNoOrTransNo(data.getPaymentNo(), data.getId());
|
|
|
+ if (OrderStatusEnum.WAIT_PAY.equals(userOrderVo.getStatus())
|
|
|
+ || OrderStatusEnum.PAYING.equals(userOrderVo.getStatus())) {
|
|
|
+ if (TradeStatusEnum.succeeded.equals(data.getStatus())) {//支付成功
|
|
|
+ paymentSucceededHandle(data);
|
|
|
+ } else if (TradeStatusEnum.failed.equals(data.getStatus())) {//支付失败
|
|
|
+ paymentFailedHandle(data, data.getErrMsg());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void closePaymentCallBack(PaymentCallBack data) {
|
|
|
- if (TradeStatusEnum.succeeded.equals(data.getStatus())) {//关单成功
|
|
|
- paymentCloseSucceededHandle(data);
|
|
|
- } else if (TradeStatusEnum.failed.equals(data.getStatus())) {//关单失败
|
|
|
- paymentCloseFailedHandle(data);
|
|
|
+ UserOrderVo userOrderVo = userOrderService.getUserOrderByPaymentNoOrTransNo(data.getPaymentNo(), data.getId());
|
|
|
+ if (OrderStatusEnum.WAIT_PAY.equals(userOrderVo.getStatus())
|
|
|
+ || OrderStatusEnum.PAYING.equals(userOrderVo.getStatus())) {
|
|
|
+ if (TradeStatusEnum.succeeded.equals(data.getStatus())) {//关单成功
|
|
|
+ paymentCloseSucceededHandle(data);
|
|
|
+ } else if (TradeStatusEnum.failed.equals(data.getStatus())) {//关单失败
|
|
|
+ paymentCloseFailedHandle(data);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/***
|
|
|
+ * 入订单付款表
|
|
|
+ * @author liweifan
|
|
|
+ * @param: paymentRes
|
|
|
+ * @param: payReq
|
|
|
+ * @updateTime 2022/5/11 18:47
|
|
|
+ * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
|
|
|
+ */
|
|
|
+ private UserOrderPayment insertOrderPayment(Payment payment) {
|
|
|
+ UserOrderPayment orderPayment = new UserOrderPayment();
|
|
|
+ orderPayment.setOpenType(payment.getOpenType());
|
|
|
+ orderPayment.setPayChannel(payment.getPayChannel());
|
|
|
+ orderPayment.setOrderNo(payment.getOrderNo());
|
|
|
+ orderPayment.setPaymentNo(payment.getPaymentNo());
|
|
|
+ orderPayment.setTransNo(payment.getId());
|
|
|
+ orderPayment.setPayAmt(
|
|
|
+ new BigDecimal(payment.getPayAmt()).setScale(2, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ orderPayment.setPayInfo(payment.getPayInfo());
|
|
|
+ orderPayment.setStatus(TradeStatusEnum.pending);
|
|
|
+
|
|
|
+ //查询订单下支付中的付款单,取消支付
|
|
|
+ closePaymentAndReqOpen(payment.getOrderNo(), "用户发起了新的付款请求");
|
|
|
+ //保存新的付款单
|
|
|
+ save(orderPayment);
|
|
|
+ return orderPayment;
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
* 处理回调-支付成功
|
|
|
* @author liweifan
|
|
|
* @param: data
|
|
@@ -263,6 +284,8 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
|
|
|
if (detail.getStatus().equals(OrderStatusEnum.WAIT_PAY)
|
|
|
|| detail.getStatus().equals(OrderStatusEnum.PAYING)) {
|
|
|
userOrderService.doOrderCancel(detail, OrderStatusEnum.FAIL, "支付回调失败:" + errMsg);
|
|
|
+ //关闭付款单
|
|
|
+ onlyClosePayment(detail.getOrderNo(), "支付回调失败:" + errMsg);
|
|
|
}
|
|
|
}
|
|
|
|