|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.yonge.cooleshow.biz.dal.config.HuifuConfiguration;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
|
import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
|
|
@@ -61,24 +62,45 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
private static final Map<OrderTypeEnum, Function<OrderReq, HttpResponseResult<OrderCreateRes>>> orderCreate = new HashMap<>();
|
|
|
//插入订单后执行
|
|
|
private static final Map<OrderTypeEnum, Consumer<UserOrderVo>> orderAfter = new HashMap<>();
|
|
|
+ //订单完成后执行
|
|
|
+ private static final Map<OrderTypeEnum, Consumer<UserOrderVo>> orderSuccess = new HashMap<>();
|
|
|
+ //订单取消后执行
|
|
|
+ private static final Map<OrderTypeEnum, Consumer<UserOrderVo>> orderCancel = new HashMap<>();
|
|
|
|
|
|
@PostConstruct
|
|
|
private void init() {
|
|
|
+ /**********订单生成前******************/
|
|
|
//vip开通缴费
|
|
|
orderCreate.put(OrderTypeEnum.VIP, vipCardService::orderCreate);
|
|
|
|
|
|
+ /**********订单生成后******************/
|
|
|
+ //orderAfter.put(OrderTypeEnum.VIP, vipCardService::orderAfter);
|
|
|
+
|
|
|
+ /**********订单完成后******************/
|
|
|
//vip开通缴费
|
|
|
- orderAfter.put(OrderTypeEnum.VIP, vipCardService::orderAfter);
|
|
|
+ orderSuccess.put(OrderTypeEnum.VIP, vipCardService::orderSuccess);
|
|
|
+
|
|
|
+
|
|
|
+ /**********订单取消后******************/
|
|
|
+ //orderCancel.put();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public UserOrderVo detail(Long id) {
|
|
|
- return baseMapper.detailById(id);
|
|
|
+ UserOrderVo userOrderVo = baseMapper.detailById(id);
|
|
|
+ if(null != userOrderVo){
|
|
|
+ userOrderVo.setOrderDetail(orderDetailService.detail(userOrderVo.getOrderNo()));
|
|
|
+ }
|
|
|
+ return userOrderVo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public UserOrderVo detail(String orderNo) {
|
|
|
- return baseMapper.detailByOrderNo(orderNo);
|
|
|
+ UserOrderVo userOrderVo = baseMapper.detailByOrderNo(orderNo);
|
|
|
+ if(null != userOrderVo){
|
|
|
+ userOrderVo.setOrderDetail(orderDetailService.detail(userOrderVo.getOrderNo()));
|
|
|
+ }
|
|
|
+ return userOrderVo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -138,7 +160,75 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
|
|
|
@Override
|
|
|
public void orderCallback(String data) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
+ if (PayStatusEnum.succeeded.getCode().equals(jsonObject.getString("status"))) {
|
|
|
+ //订单完成
|
|
|
+ UserOrderVo detail = detail(jsonObject.getString("order_no"));
|
|
|
+ if (null == detail) {
|
|
|
+ log.error("汇付支付回调,订单未找到。 req is {}", data);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (detail.getStatus().equals(OrderStatusEnum.PAYING)) {
|
|
|
+ orderSuccess(detail);
|
|
|
+ } else {
|
|
|
+ log.error("汇付支付回调,订单状态异常。 req is {}", data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void pollingOrder() {
|
|
|
+ //查询创建时间超过半小时还在交易中的订单
|
|
|
+ List<UserOrderVo> orderList = baseMapper.selectPendingList();
|
|
|
+ for (UserOrderVo userOrder : orderList) {
|
|
|
+ //待支付订单直接取消
|
|
|
+ if (OrderStatusEnum.WAIT_PAY.equals(userOrder.getStatus())) {
|
|
|
+ waitPayOrderHandle(userOrder);
|
|
|
+ }
|
|
|
+ if (OrderStatusEnum.PAYING.equals(userOrder.getStatus())) {
|
|
|
+ payingOrderHandle(userOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
+ * 处理待支付订单
|
|
|
+ * @author liweifan
|
|
|
+ * @param: userOrder
|
|
|
+ * @updateTime 2022/4/13 16:51
|
|
|
+ */
|
|
|
+ private void waitPayOrderHandle(UserOrderVo userOrder) {
|
|
|
+ orderCancel(userOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
+ * 处理支付中订单
|
|
|
+ * @author liweifan
|
|
|
+ * @param: userOrder
|
|
|
+ * @updateTime 2022/4/13 16:51
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ void payingOrderHandle(UserOrderVo userOrder) {
|
|
|
+ //判断汇付订单状态
|
|
|
+ UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(userOrder.getOrderNo());
|
|
|
+ if (null == orderPayment) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Map<String, Object> resMap = paymentSdk.queryPayment(orderPayment.getTransNo());
|
|
|
+ //支付失败
|
|
|
+ if (PayStatusEnum.failed.getCode().equals(resMap.get("status").toString())) {
|
|
|
+ orderCancel(userOrder);
|
|
|
+ }
|
|
|
+ //支付成功
|
|
|
+ if (PayStatusEnum.succeeded.getCode().equals(resMap.get("status").toString())) {
|
|
|
+ orderSuccess(userOrder);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("轮询处理支付中订单异常,异常参数: {}", JSONObject.toJSONString(userOrder));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/***
|
|
@@ -146,8 +236,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
* @author liweifan
|
|
|
* @param: payReq
|
|
|
* @param: detail
|
|
|
- * @updateTime 2022/4/1 10:32
|
|
|
- * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<java.lang.Boolean>
|
|
|
+ * @updateTime 2022/4/13 16:59
|
|
|
+ * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes>
|
|
|
*/
|
|
|
private HttpResponseResult<OrderPayRes> orderPayWaitPay(OrderPayReq payReq, UserOrderVo detail) {
|
|
|
PaymentReq paymentReq = new PaymentReq();
|
|
@@ -177,10 +267,17 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
String pay_info = ((JSONObject) res.get("expend")).getString("pay_info");
|
|
|
orderPayRes.setPay_info(pay_info);
|
|
|
//入订单付款表,同时修改订单状态
|
|
|
- UserOrderPayment orderPayment = insertOrderPayment(res, payReq);
|
|
|
+ insertOrderPayment(res, payReq);
|
|
|
return HttpResponseResult.succeed(orderPayRes);
|
|
|
}
|
|
|
-
|
|
|
+ /***
|
|
|
+ * 插入订单付款单
|
|
|
+ * @author liweifan
|
|
|
+ * @param: res
|
|
|
+ * @param: payReq
|
|
|
+ * @updateTime 2022/4/13 17:56
|
|
|
+ * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
|
|
|
+ */
|
|
|
private UserOrderPayment insertOrderPayment(Map<String, Object> res, OrderPayReq payReq) {
|
|
|
UserOrderPayment orderPayment = new UserOrderPayment();
|
|
|
orderPayment.setOrderNo(payReq.getOrderNo());
|
|
@@ -207,7 +304,15 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
* @return: com.yonge.cooleshow.common.entity.HttpResponseResult<java.lang.Boolean>
|
|
|
*/
|
|
|
private HttpResponseResult<OrderPayRes> orderPayPaying(OrderPayReq payReq, UserOrderVo detail) {
|
|
|
- return null;
|
|
|
+ UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo());
|
|
|
+ if (PayStatusEnum.pending.equals(orderPayment.getStatus())) {
|
|
|
+ OrderPayRes orderPayRes = new OrderPayRes();
|
|
|
+ orderPayRes.setPay_info(orderPayment.getPayInfo());
|
|
|
+ orderPayRes.setPay_amt(orderPayment.getPayAmt().toString());
|
|
|
+ return HttpResponseResult.succeed(orderPayRes);
|
|
|
+ } else {
|
|
|
+ return HttpResponseResult.failed("未找到订单信息");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/***
|
|
@@ -291,4 +396,52 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /***
|
|
|
+ * 取消订单
|
|
|
+ * @author liweifan
|
|
|
+ * @param: userOrder
|
|
|
+ * @updateTime 2022/4/13 17:23
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ void orderCancel(UserOrderVo userOrder) {
|
|
|
+ userOrder.setStatus(OrderStatusEnum.CLOSE);
|
|
|
+ baseMapper.updateById(userOrder);
|
|
|
+
|
|
|
+ UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(userOrder.getOrderNo());
|
|
|
+ if (null != orderPayment) {
|
|
|
+ //更新付款单
|
|
|
+ orderPayment.setStatus(PayStatusEnum.failed);
|
|
|
+ orderPaymentService.updateById(orderPayment);
|
|
|
+ }
|
|
|
+ //调用业务
|
|
|
+ Consumer<UserOrderVo> userOrderVoConsumer = orderCancel.get(userOrder.getOrderType());
|
|
|
+ if (!Objects.isNull(userOrderVoConsumer)) {
|
|
|
+ userOrderVoConsumer.accept(userOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单完成
|
|
|
+ *
|
|
|
+ * @author liweifan
|
|
|
+ * @param: detail
|
|
|
+ * @updateTime 2022/4/13 17:17
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ void orderSuccess(UserOrderVo detail) {
|
|
|
+ detail.setStatus(OrderStatusEnum.PAID);
|
|
|
+ detail.setPayTime(new Date());
|
|
|
+ updateById(detail);
|
|
|
+ //更新付款单
|
|
|
+ UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(detail.getOrderNo());
|
|
|
+ orderPayment.setStatus(PayStatusEnum.succeeded);
|
|
|
+ orderPayment.setArrivalTime(new Date());
|
|
|
+ orderPaymentService.updateById(orderPayment);
|
|
|
+ //调用业务
|
|
|
+ Consumer<UserOrderVo> userOrderVoConsumer = orderSuccess.get(detail.getOrderType());
|
|
|
+ if (!Objects.isNull(userOrderVoConsumer)) {
|
|
|
+ userOrderVoConsumer.accept(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|