|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.haha.common.constant.OrderConstants;
|
|
import com.haha.common.constant.OrderConstants;
|
|
|
import com.haha.common.enums.OrderStatus;
|
|
import com.haha.common.enums.OrderStatus;
|
|
|
|
|
+import com.haha.common.enums.PayScoreState;
|
|
|
import com.haha.common.enums.PayStatus;
|
|
import com.haha.common.enums.PayStatus;
|
|
|
import com.haha.common.enums.PaymentChannel;
|
|
import com.haha.common.enums.PaymentChannel;
|
|
|
import com.haha.common.config.CommonConfig;
|
|
import com.haha.common.config.CommonConfig;
|
|
@@ -655,6 +656,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 立即设置支付渠道,防止后续回调到达时 payChannel 为 null 而跳过扣费
|
|
|
|
|
+ order.setPayChannel(PaymentChannel.WECHAT_PAYSCORE.getCode());
|
|
|
|
|
+ order.setPayType("微信支付分");
|
|
|
|
|
+ this.updateById(order);
|
|
|
|
|
+
|
|
|
if (openId == null || openId.isEmpty()) {
|
|
if (openId == null || openId.isEmpty()) {
|
|
|
log.warn("[支付分集成] openId为空,跳过支付分服务订单创建 - orderId: {}", order.getId());
|
|
log.warn("[支付分集成] openId为空,跳过支付分服务订单创建 - orderId: {}", order.getId());
|
|
|
return order;
|
|
return order;
|
|
@@ -668,8 +674,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
order.getId(), result.getOutOrderNo());
|
|
order.getId(), result.getOutOrderNo());
|
|
|
order.setPayScoreOrderId(result.getOutOrderNo());
|
|
order.setPayScoreOrderId(result.getOutOrderNo());
|
|
|
order.setPayScoreState(result.getState());
|
|
order.setPayScoreState(result.getState());
|
|
|
- order.setPayChannel(PaymentChannel.WECHAT_PAYSCORE.getCode());
|
|
|
|
|
- order.setPayType("微信支付分");
|
|
|
|
|
this.updateById(order);
|
|
this.updateById(order);
|
|
|
} else {
|
|
} else {
|
|
|
log.warn("[支付分集成] 支付分服务订单创建失败 - orderId: {}, errorCode: {}, errorMsg: {}",
|
|
log.warn("[支付分集成] 支付分服务订单创建失败 - orderId: {}, errorCode: {}, errorMsg: {}",
|
|
@@ -1276,6 +1280,55 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 修复漏掉的支付分扣费:查询有支付分服务订单但未完成扣费的订单,重新发起扣费
|
|
|
|
|
+ *
|
|
|
|
|
+ * 适用场景:订单创建后因并发回调导致 payChannel 为 null,processPayScorePayment 跳过扣费
|
|
|
|
|
+ * 筛选条件:payScoreOrderId 已设置 + payScoreState 为 CREATED/DOING + payStatus 为 UNPAID + totalAmount > 0
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return { total, success, failed }
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Map<String, Object> repairPayScorePayments() {
|
|
|
|
|
+ List<Order> orders = lambdaQuery()
|
|
|
|
|
+ .isNotNull(Order::getPayScoreOrderId)
|
|
|
|
|
+ .ne(Order::getPayScoreOrderId, "")
|
|
|
|
|
+ .in(Order::getPayScoreState, PayScoreState.CREATED.getCode(), PayScoreState.DOING.getCode())
|
|
|
|
|
+ .eq(Order::getPayStatus, OrderConstants.PAY_STATUS_UNPAID)
|
|
|
|
|
+ .gt(Order::getTotalAmount, BigDecimal.ZERO)
|
|
|
|
|
+ .list();
|
|
|
|
|
+
|
|
|
|
|
+ int success = 0, failed = 0;
|
|
|
|
|
+ for (Order order : orders) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ BigDecimal amount = order.getPaidAmount() != null
|
|
|
|
|
+ && order.getPaidAmount().compareTo(BigDecimal.ZERO) > 0
|
|
|
|
|
+ ? order.getPaidAmount() : order.getTotalAmount();
|
|
|
|
|
+
|
|
|
|
|
+ boolean result = completeOrderWithPayScore(order.getId(), amount);
|
|
|
|
|
+ if (result) {
|
|
|
|
|
+ success++;
|
|
|
|
|
+ log.info("[支付分修复] 扣费成功 - orderId: {}, orderNo: {}, amount: {}",
|
|
|
|
|
+ order.getId(), order.getOrderNo(), amount);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ failed++;
|
|
|
|
|
+ log.warn("[支付分修复] 扣费失败 - orderId: {}, orderNo: {}",
|
|
|
|
|
+ order.getId(), order.getOrderNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ failed++;
|
|
|
|
|
+ log.error("[支付分修复] 扣费异常 - orderId: {}, error: {}", order.getId(), e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("total", orders.size());
|
|
|
|
|
+ result.put("success", success);
|
|
|
|
|
+ result.put("failed", failed);
|
|
|
|
|
+ log.info("[支付分修复] 完成 - total: {}, success: {}, failed: {}", orders.size(), success, failed);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 标准化图片URL
|
|
* 标准化图片URL
|
|
|
*/
|
|
*/
|