|
@@ -171,8 +171,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
if (null == detail) {
|
|
|
return HttpResponseResult.failed("未找到订单信息");
|
|
|
}
|
|
|
- if(!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
- && !OrderStatusEnum.PAYING.equals(detail.getStatus())){
|
|
|
+ if (!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
+ && !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
return HttpResponseResult.failed("订单已完成");
|
|
|
}
|
|
|
if (!StringUtil.isEmpty(detail.getTransNo())) {
|
|
@@ -213,16 +213,16 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
@Override
|
|
|
public void setOrderStatus(String orderNo, OrderStatusEnum orderStatus) {
|
|
|
UserOrderVo detail = detail(orderNo);
|
|
|
- if(OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
- || OrderStatusEnum.PAYING.equals(detail.getStatus())){
|
|
|
+ if (OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
+ || OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
|
|
|
- if(OrderStatusEnum.CLOSE.equals(orderStatus)){
|
|
|
- doOrderCancel(detail,orderStatus,"测试接口-订单关闭");
|
|
|
+ if (OrderStatusEnum.CLOSE.equals(orderStatus)) {
|
|
|
+ doOrderCancel(detail, orderStatus, "测试接口-订单关闭");
|
|
|
}
|
|
|
- if(OrderStatusEnum.FAIL.equals(orderStatus)){
|
|
|
- doOrderCancel(detail,orderStatus,"测试接口-订单交易失败");
|
|
|
+ if (OrderStatusEnum.FAIL.equals(orderStatus)) {
|
|
|
+ doOrderCancel(detail, orderStatus, "测试接口-订单交易失败");
|
|
|
}
|
|
|
- if(OrderStatusEnum.PAID.equals(orderStatus)){
|
|
|
+ if (OrderStatusEnum.PAID.equals(orderStatus)) {
|
|
|
orderSuccess(detail);
|
|
|
}
|
|
|
}
|
|
@@ -315,7 +315,6 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
//查询订单
|
|
|
UserOrderVo detail = detail(payReq.getOrderNo());
|
|
|
if (OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
- //处于付款中状态,需要拉起付款接口返回信息,并且去到汇付
|
|
|
return orderPayPaying(payReq, detail);
|
|
|
}
|
|
|
return HttpResponseResult.failed("订单状态异常");
|
|
@@ -330,9 +329,9 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
} else if (type.equals("payment.failed")) {//支付失败
|
|
|
paymentFailedHandle(hfRes);
|
|
|
} else if (type.equals("payment.close.succeeded")) {//支付关单成功
|
|
|
- paymentCloseSucceededHandle(hfRes);
|
|
|
+ orderPaymentService.paymentCloseSucceededHandle(hfRes);
|
|
|
} else if (type.equals("payment.close.failed")) {//支付关单失败
|
|
|
- paymentCloseFailedHandle(hfRes);
|
|
|
+ orderPaymentService.paymentCloseFailedHandle(hfRes);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -378,39 +377,6 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /***
|
|
|
- * 支付关单成功
|
|
|
- * @author liweifan
|
|
|
- * @param: hfRes
|
|
|
- * @updateTime 2022/4/27 15:33
|
|
|
- */
|
|
|
- private void paymentCloseSucceededHandle(JSONObject hfRes) {
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByTransNo(hfRes.getString("payment_id"));
|
|
|
- if (null == orderPayment) {
|
|
|
- return;
|
|
|
- }
|
|
|
- orderPayment.setCloseStatus(TradeStatusEnum.succeeded);
|
|
|
- orderPayment.setUpdateTime(new Date());
|
|
|
- orderPaymentService.updateById(orderPayment);
|
|
|
- }
|
|
|
-
|
|
|
- /***
|
|
|
- * 支付关单失败
|
|
|
- * @author liweifan
|
|
|
- * @param: hfRes
|
|
|
- * @updateTime 2022/4/27 15:33
|
|
|
- */
|
|
|
- private void paymentCloseFailedHandle(JSONObject hfRes) {
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByTransNo(hfRes.getString("payment_id"));
|
|
|
- if (null == orderPayment) {
|
|
|
- return;
|
|
|
- }
|
|
|
- orderPayment.setStatus(TradeStatusEnum.failed);
|
|
|
- orderPayment.setPayFailMsg("支付关单回调失败-" + hfRes.getString("error_msg"));
|
|
|
- orderPayment.setUpdateTime(new Date());
|
|
|
- orderPaymentService.updateById(orderPayment);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void pollingOrder() {
|
|
|
//查询半小时前创建的并且还未完成的订单 WAIT_PAY 待支付订单 PAYING 支付中订单
|
|
@@ -444,8 +410,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
if (null == detail) {
|
|
|
return;
|
|
|
}
|
|
|
- if(!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
- && !OrderStatusEnum.PAYING.equals(detail.getStatus())){
|
|
|
+ if (!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
+ && !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
return;
|
|
|
}
|
|
|
if (!StringUtil.isEmpty(detail.getTransNo())) {
|
|
@@ -476,6 +442,17 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
* @return: com.yonge.cooleshow.common.entity.HttpResponseResult<com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes>
|
|
|
*/
|
|
|
private HttpResponseResult<OrderPayRes> orderPayWaitPay(OrderPayReq payReq, UserOrderVo detail) {
|
|
|
+ OrderPayRes orderPayRes = new OrderPayRes();
|
|
|
+
|
|
|
+ UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo());
|
|
|
+ if (null != orderPayment && TradeStatusEnum.pending.equals(orderPayment.getStatus())
|
|
|
+ && !StringUtil.isEmpty(orderPayment.getPayInfo())) {
|
|
|
+ orderPayRes.setPay_amt(orderPayment.getPayAmt().toString());
|
|
|
+ orderPayRes.setPay_info(orderPayment.getPayInfo());
|
|
|
+ orderPayRes.setPayChannel(orderPayment.getPayChannel());
|
|
|
+ return HttpResponseResult.succeed(orderPayRes);
|
|
|
+ }
|
|
|
+
|
|
|
PaymentReq paymentReq = new PaymentReq();
|
|
|
paymentReq.setOrder_no(payReq.getOrderNo());
|
|
|
paymentReq.setPay_channel(payReq.getPayChannel().getCode());
|
|
@@ -503,76 +480,21 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
//付款请求
|
|
|
HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.executePayment(paymentReq);
|
|
|
if (responseResult.getStatus()) {
|
|
|
- OrderPayRes orderPayRes = new OrderPayRes();
|
|
|
orderPayRes.setPay_amt(detail.getActualPrice().setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
String pay_info = ((JSONObject) responseResult.getData().get("expend")).getString("pay_info");
|
|
|
orderPayRes.setPay_info(pay_info);
|
|
|
orderPayRes.setPayChannel(payReq.getPayChannel());
|
|
|
|
|
|
//入订单付款表,同时修改订单状态
|
|
|
- insertOrderPayment(responseResult, payReq);
|
|
|
+ orderPaymentService.insertOrderPayment(responseResult, payReq);
|
|
|
+
|
|
|
baseMapper.updateStatusByOrderNo(payReq.getOrderNo(), OrderStatusEnum.PAYING.getCode());
|
|
|
return HttpResponseResult.succeed(orderPayRes);
|
|
|
} else {
|
|
|
//入订单付款表,同时修改订单状态
|
|
|
- doOrderCancel(detail, OrderStatusEnum.FAIL, "订单超时");
|
|
|
- errOrderPayment(responseResult, payReq);
|
|
|
+ doOrderCancel(detail, OrderStatusEnum.FAIL, responseResult.getMsg());
|
|
|
return HttpResponseResult.failed(responseResult.getMsg());
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /***
|
|
|
- * 插入订单付款单
|
|
|
- * @author liweifan
|
|
|
- * @param: res
|
|
|
- * @param: payReq
|
|
|
- * @updateTime 2022/4/13 17:56
|
|
|
- * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
|
|
|
- */
|
|
|
- private UserOrderPayment insertOrderPayment(HttpResponseResult<Map<String, Object>> responseResult, OrderPayReq payReq) {
|
|
|
- UserOrderPayment orderPayment = new UserOrderPayment();
|
|
|
- orderPayment.setOrderNo(payReq.getOrderNo());
|
|
|
- orderPayment.setPayChannel(payReq.getPayChannel());
|
|
|
- if (responseResult.getStatus()) {
|
|
|
- Map<String, Object> res = responseResult.getData();
|
|
|
- orderPayment.setTransNo(res.get("id").toString());
|
|
|
- orderPayment.setPayAmt(
|
|
|
- new BigDecimal(res.get("pay_amt").toString()).setScale(2, RoundingMode.HALF_UP)
|
|
|
- );
|
|
|
- String pay_info = ((JSONObject) res.get("expend")).getString("pay_info");
|
|
|
- orderPayment.setPayInfo(pay_info);
|
|
|
- orderPayment.setStatus(TradeStatusEnum.pending);
|
|
|
- } else {
|
|
|
- orderPayment.setPayFailMsg(responseResult.getMsg());
|
|
|
- orderPayment.setStatus(TradeStatusEnum.failed);
|
|
|
- }
|
|
|
- orderPaymentService.save(orderPayment);
|
|
|
- return orderPayment;
|
|
|
- }
|
|
|
-
|
|
|
- /***
|
|
|
- * 处理付款请求失败
|
|
|
- * @author liweifan
|
|
|
- * @param: res
|
|
|
- * @param: payReq
|
|
|
- * @updateTime 2022/4/13 17:56
|
|
|
- * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
|
|
|
- */
|
|
|
- private UserOrderPayment errOrderPayment(HttpResponseResult<Map<String, Object>> responseResult, OrderPayReq payReq) {
|
|
|
- //查询
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo());
|
|
|
- if (null == orderPayment) {
|
|
|
- orderPayment = new UserOrderPayment();
|
|
|
- orderPayment.setOrderNo(payReq.getOrderNo());
|
|
|
- orderPayment.setPayChannel(payReq.getPayChannel());
|
|
|
- }
|
|
|
- orderPayment.setPayFailMsg(responseResult.getMsg());
|
|
|
- orderPayment.setStatus(TradeStatusEnum.failed);
|
|
|
- orderPayment.setUpdateTime(new Date());
|
|
|
-
|
|
|
- orderPaymentService.saveOrUpdate(orderPayment);
|
|
|
- return orderPayment;
|
|
|
}
|
|
|
|
|
|
/***
|
|
@@ -779,25 +701,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
userOrder.setUpdateTime(new Date());
|
|
|
baseMapper.updateById(userOrder);
|
|
|
|
|
|
-
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(userOrder.getOrderNo());
|
|
|
- if (null != orderPayment) {
|
|
|
- //更新付款单
|
|
|
- orderPayment.setStatus(TradeStatusEnum.failed);
|
|
|
- orderPayment.setPayFailMsg(StringUtil.isEmpty(reason) ? "交易取消" : reason);
|
|
|
- orderPayment.setUpdateTime(new Date());
|
|
|
- }
|
|
|
- //发送支付关单请求
|
|
|
- HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.closePayment(userOrder.getTransNo(), reason, "");
|
|
|
- if (!responseResult.getStatus()) {
|
|
|
- orderPayment.setCloseStatus(TradeStatusEnum.failed);
|
|
|
- orderPayment.setCloseFailMsg(responseResult.getMsg());
|
|
|
- orderPaymentService.updateById(orderPayment);
|
|
|
- return;
|
|
|
- } else {
|
|
|
- orderPayment.setCloseStatus(TradeStatusEnum.pending);
|
|
|
- orderPaymentService.updateById(orderPayment);
|
|
|
- }
|
|
|
+ orderPaymentService.closePayment(userOrder.getOrderNo(), reason);
|
|
|
}
|
|
|
|
|
|
void orderSuccess(UserOrderVo detail) {
|