瀏覽代碼

fix: OrderServiceImpl 中 buildPostPayments 同样的 amount/count bug

与 HahaCallbackServiceImpl 中相同的 bug — amount 用单价未乘数量,
导致微信支付分完结时 sum(post_payments) ≠ total_amount。两个调用方
(processPayScorePayment 和 completeOrderWithPayScore)都要修。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 6 小時之前
父節點
當前提交
942f9f7e0c
共有 1 個文件被更改,包括 6 次插入3 次删除
  1. 6 3
      haha-service/src/main/java/com/haha/service/impl/OrderServiceImpl.java

+ 6 - 3
haha-service/src/main/java/com/haha/service/impl/OrderServiceImpl.java

@@ -715,10 +715,13 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
             for (OrderGoods goods : goodsList) {
                 PayScoreCreateRequest.PostPayment payment = new PayScoreCreateRequest.PostPayment();
                 payment.setName("商品信息");
-                payment.setAmount(goods.getPrice() != null ? goods.getPrice()
-                        : (goods.getMoney() != null ? goods.getMoney() : BigDecimal.ZERO));
+                // amount 为行总金额(单价 × 数量),微信校验: total_amount = sum(post_payments[].amount)
+                BigDecimal unitPrice = goods.getPrice() != null ? goods.getPrice()
+                        : (goods.getMoney() != null ? goods.getMoney() : BigDecimal.ZERO);
+                int quantity = goods.getProductNum() != null ? goods.getProductNum() : 1;
+                payment.setAmount(unitPrice.multiply(BigDecimal.valueOf(quantity)));
                 payment.setDescription(goods.getProductName() != null ? goods.getProductName() : "未知商品");
-                payment.setCount(goods.getProductNum() != null ? goods.getProductNum() : 1);
+                payment.setCount(1);
                 payments.add(payment);
             }