|
@@ -43,30 +43,23 @@ import java.util.List;
|
|
|
@RequestMapping("/cb")
|
|
|
public class CallbackController {
|
|
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(CallbackController.class);
|
|
|
|
|
|
@Autowired
|
|
|
private IKxAppOrderService appOrderService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private OrderBizService orderBizService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private KxStoreOrderProductMapper orderProductMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private KxStoreProductMapper storeProductMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private KxGroupShopMapper groupShopMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private AdminNotifyBizService adminNotifyBizService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private AdminPrintBizService adminPrintBizService;
|
|
|
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(CallbackController.class);
|
|
|
-
|
|
|
@RequestMapping("/wxpay")
|
|
|
@SaIgnore
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -75,10 +68,10 @@ public class CallbackController {
|
|
|
WxPayOrderNotifyResult result;
|
|
|
try {
|
|
|
WxPayService wxPayService = WxPayConfiguration.getPayService(PayMethodEnum.H5);
|
|
|
- if(wxPayService == null) {
|
|
|
+ if (wxPayService == null) {
|
|
|
wxPayService = WxPayConfiguration.getPayService(PayMethodEnum.MINI);
|
|
|
}
|
|
|
- if(wxPayService == null) {
|
|
|
+ if (wxPayService == null) {
|
|
|
wxPayService = WxPayConfiguration.getPayService(PayMethodEnum.APP);
|
|
|
}
|
|
|
result = wxPayService.parseOrderNotifyResult(body);
|
|
@@ -98,17 +91,24 @@ public class CallbackController {
|
|
|
String payId = result.getTransactionId();
|
|
|
|
|
|
List<KxStoreOrderVo> KxStoreOrderList = appOrderService.selectListVoByWrapper(
|
|
|
- new QueryWrapper<KxStoreOrder>()
|
|
|
- .eq("order_id", orderNo));
|
|
|
+ new QueryWrapper<KxStoreOrder>()
|
|
|
+ .eq("order_id", orderNo));
|
|
|
|
|
|
if (CollectionUtils.isEmpty(KxStoreOrderList)) {
|
|
|
return WxPayNotifyResponse.fail("订单不存在 orderNo=" + orderNo);
|
|
|
}
|
|
|
|
|
|
KxStoreOrderVo order = KxStoreOrderList.get(0);
|
|
|
+ KxStoreOrder updateOrderDO = KxStoreOrder.builder().build();
|
|
|
+ updateOrderDO.setPayId(payId);
|
|
|
+ updateOrderDO.setPayChannel("WX");
|
|
|
+ updateOrderDO.setPayTime(new Date());
|
|
|
+ updateOrderDO.setUpdateTime(order.getPayTime());
|
|
|
|
|
|
// 检查这个订单是否已经处理过
|
|
|
if (order.getStatus() != OrderStatusType.UNPAY.getCode()) {
|
|
|
+ logger.warn("【{}】 订单状态异常:{}, 更新支付信息", orderNo, order.getStatus());
|
|
|
+ orderBizService.changeOrderStatus(orderNo, order.getStatus(), updateOrderDO);
|
|
|
return WxPayNotifyResponse.success("订单已经处理成功!");
|
|
|
}
|
|
|
|
|
@@ -121,12 +121,7 @@ public class CallbackController {
|
|
|
|
|
|
//**************** 在此之前都没有 数据库修改 操作 所以前面是直接返回错误的 **********************//
|
|
|
|
|
|
- KxStoreOrder updateOrderDO = KxStoreOrder.builder().build();
|
|
|
- updateOrderDO.setPayId(payId);
|
|
|
- updateOrderDO.setPayChannel("WX");
|
|
|
- updateOrderDO.setPayTime(new Date());
|
|
|
- updateOrderDO.setUpdateTime(order.getPayTime());
|
|
|
- if (order.getCombinationId() != null && order.getCombinationId()!=0L) {
|
|
|
+ if (order.getCombinationId() != null && order.getCombinationId() != 0L) {
|
|
|
updateOrderDO.setStatus(OrderStatusType.GROUP_SHOP_WAIT.getCode());
|
|
|
} else {
|
|
|
updateOrderDO.setStatus(OrderStatusType.WAIT_PREPARE_GOODS.getCode());
|
|
@@ -136,15 +131,15 @@ public class CallbackController {
|
|
|
List<KxStoreOrderProductVo> orderProducts = orderProductMapper.selectVoList(new QueryWrapper<KxStoreOrderProduct>().eq("order_id", order.getId()));
|
|
|
order.setProductList(orderProducts);
|
|
|
orderProducts.forEach(item -> {
|
|
|
- //增加销量
|
|
|
+ // 增加销量
|
|
|
storeProductMapper.incSales(item.getProductId(), item.getNum());
|
|
|
if (order.getCombinationId() != null) {
|
|
|
- //增加团购人数, 若想算商品数这里就获取orderSku的数量,若想算人数,这里就写1
|
|
|
+ // 增加团购人数, 若想算商品数这里就获取orderSku的数量,若想算人数,这里就写1
|
|
|
groupShopMapper.incCurrentNum(order.getCombinationId(), item.getNum());
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- //通知管理员发货
|
|
|
+ // 通知管理员发货
|
|
|
GlobalExecutor.execute(() -> {
|
|
|
adminNotifyBizService.newOrder(order);
|
|
|
adminPrintBizService.newOrderPrint(order);
|
|
@@ -161,8 +156,8 @@ public class CallbackController {
|
|
|
|
|
|
|
|
|
List<KxStoreOrderVo> KxStoreOrderList = appOrderService.selectListVoByWrapper(
|
|
|
- new QueryWrapper<KxStoreOrder>()
|
|
|
- .eq("order_id", orderNo));
|
|
|
+ new QueryWrapper<KxStoreOrder>()
|
|
|
+ .eq("order_id", orderNo));
|
|
|
|
|
|
if (CollectionUtils.isEmpty(KxStoreOrderList)) {
|
|
|
return WxPayNotifyResponse.fail("订单不存在 orderNo=" + orderNo);
|
|
@@ -182,27 +177,27 @@ public class CallbackController {
|
|
|
updateOrderDO.setPayChannel("WX");
|
|
|
updateOrderDO.setPayTime(new Date());
|
|
|
updateOrderDO.setUpdateTime(order.getPayTime());
|
|
|
- if (order.getCombinationId() != null && order.getCombinationId()!=0L) {
|
|
|
+ if (order.getCombinationId() != null && order.getCombinationId() != 0L) {
|
|
|
updateOrderDO.setStatus(OrderStatusType.GROUP_SHOP_WAIT.getCode());
|
|
|
} else {
|
|
|
updateOrderDO.setStatus(OrderStatusType.WAIT_PREPARE_GOODS.getCode());
|
|
|
}
|
|
|
orderBizService.changeOrderStatus(orderNo, OrderStatusType.UNPAY.getCode(), updateOrderDO);
|
|
|
|
|
|
- //扣款
|
|
|
+ // 扣款
|
|
|
|
|
|
List<KxStoreOrderProductVo> orderProducts = orderProductMapper.selectVoList(new QueryWrapper<KxStoreOrderProduct>().eq("order_id", order.getId()));
|
|
|
order.setProductList(orderProducts);
|
|
|
orderProducts.forEach(item -> {
|
|
|
- //增加销量
|
|
|
+ // 增加销量
|
|
|
storeProductMapper.incSales(item.getProductId(), item.getNum());
|
|
|
if (order.getCombinationId() != null) {
|
|
|
- //增加团购人数, 若想算商品数这里就获取orderSku的数量,若想算人数,这里就写1
|
|
|
+ // 增加团购人数, 若想算商品数这里就获取orderSku的数量,若想算人数,这里就写1
|
|
|
groupShopMapper.incCurrentNum(order.getCombinationId(), item.getNum());
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- //通知管理员发货
|
|
|
+ // 通知管理员发货
|
|
|
GlobalExecutor.execute(() -> {
|
|
|
adminNotifyBizService.newOrder(order);
|
|
|
adminPrintBizService.newOrderPrint(order);
|