|
|
@@ -780,4 +780,59 @@ public class ProductOrderInfoServiceImpl extends ServiceImpl<ProductOrderInfoMap
|
|
|
return receiverInfo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理微信支付回调(商品订单)
|
|
|
+ * 参照服务订单支付成功逻辑,更新用户表、消费记录表
|
|
|
+ *
|
|
|
+ * @param orderNo 订单编号
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void handleWxPayCallback(String orderNo) {
|
|
|
+ log.info("商品订单微信支付回调开始处理,订单号:{}", orderNo);
|
|
|
+
|
|
|
+ // 1. 查询未支付的商品订单
|
|
|
+ LambdaQueryWrapper<ProductOrderInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(ProductOrderInfo::getOrderNo, orderNo)
|
|
|
+ .eq(ProductOrderInfo::getOrderStatus, ProductOrderStatusEnum.WAIT_PAY.getCode());
|
|
|
+ ProductOrderInfo orderInfo = productOrderInfoMapper.selectOne(queryWrapper);
|
|
|
+ if (orderInfo == null) {
|
|
|
+ log.error("商品订单 {} 不存在或已支付", orderNo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 获取用户信息
|
|
|
+ TWxUser user = wxUserService.getByOpenId(orderInfo.getOpenId());
|
|
|
+ if (user == null) {
|
|
|
+ log.error("商品订单对应的用户不存在,openId:{}", orderInfo.getOpenId());
|
|
|
+ throw new ServiceException("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 更新用户金额及下单次数
|
|
|
+ TWxUser paramUser = new TWxUser();
|
|
|
+ paramUser.setId(user.getId());
|
|
|
+ paramUser.setcOpenid(user.getcOpenid());
|
|
|
+ paramUser.setdMoney(user.getdMoney().add(orderInfo.getTotalAmount()));
|
|
|
+ paramUser.setnNum(user.getnNum() + MassageConstants.INTEGER_ONE);
|
|
|
+ wxUserService.updateById(paramUser);
|
|
|
+
|
|
|
+ // 4. 增加消费记录
|
|
|
+ TConsumptionLog tConsumptionLog = new TConsumptionLog();
|
|
|
+ tConsumptionLog.setAmount(orderInfo.getTotalAmount().negate());
|
|
|
+ tConsumptionLog.setBillNo(orderInfo.getOrderNo());
|
|
|
+ tConsumptionLog.setOpenId(orderInfo.getOpenId());
|
|
|
+ tConsumptionLog.setBillType(BillTypeEnum.WX_PAY.getCode());
|
|
|
+ tConsumptionLog.setNote("微信支付");
|
|
|
+ consumptionLogService.save(tConsumptionLog);
|
|
|
+
|
|
|
+ // 5. 更新商品订单状态:待发货,支付状态:已支付
|
|
|
+ ProductOrderInfo updateOrder = new ProductOrderInfo();
|
|
|
+ updateOrder.setId(orderInfo.getId());
|
|
|
+ updateOrder.setOrderStatus(ProductOrderStatusEnum.WAIT_DELIVERY.getCode());
|
|
|
+ updateOrder.setPayStatus(MassageConstants.INTEGER_ONE);
|
|
|
+ updateOrder.setPayTime(LocalDateTime.now());
|
|
|
+ updateById(updateOrder);
|
|
|
+ log.info("商品订单微信支付回调处理完成,订单号:{},订单状态更新为待发货,支付状态更新为已支付", orderNo);
|
|
|
+ }
|
|
|
+
|
|
|
}
|