|
|
@@ -1538,7 +1538,7 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
* 从 order_goods 表查询已保存的商品,按微信支付分智慧零售规范构建
|
|
|
* name="商品信息", description=商品名, amount=单价(元), count=数量
|
|
|
*/
|
|
|
- private List<PayScoreCreateRequest.PostPayment> buildPostPayments(Long orderId) {
|
|
|
+ private List<PayScoreCreateRequest.PostPayment> buildPostPayments(Long orderId, BigDecimal totalAmount) {
|
|
|
List<PayScoreCreateRequest.PostPayment> payments = new ArrayList<>();
|
|
|
try {
|
|
|
List<OrderGoods> goodsList = orderGoodsMapper.selectList(
|
|
|
@@ -1572,6 +1572,20 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
payments.add(payment);
|
|
|
}
|
|
|
|
|
|
+ // 修正四舍五入累计误差:确保 sum(post_payments) 严格等于 totalAmount
|
|
|
+ if (totalAmount != null && !payments.isEmpty()) {
|
|
|
+ BigDecimal sum = payments.stream()
|
|
|
+ .map(PayScoreCreateRequest.PostPayment::getAmount)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal diff = totalAmount.subtract(sum);
|
|
|
+ if (diff.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ PayScoreCreateRequest.PostPayment last = payments.get(payments.size() - 1);
|
|
|
+ last.setAmount(last.getAmount().add(diff));
|
|
|
+ log.info("post_payments余额平账: 商品sum={}, 订单total={}, 差额={}, 调整末项amount为{}",
|
|
|
+ sum, totalAmount, diff, last.getAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
log.info("构建post_payments成功 - orderId: {}, 商品数量: {}", orderId, payments.size());
|
|
|
} catch (Exception e) {
|
|
|
log.error("构建post_payments失败 - orderId: {}", orderId, e);
|
|
|
@@ -1627,7 +1641,7 @@ public class HahaCallbackServiceImpl implements HahaCallbackService {
|
|
|
log.info("开始处理支付分扣费 - orderId: {}, payScoreOrderId: {}, amount: {}元",
|
|
|
order.getId(), order.getPayScoreOrderId(), totalAmount);
|
|
|
|
|
|
- List<PayScoreCreateRequest.PostPayment> payments = buildPostPayments(order.getId());
|
|
|
+ List<PayScoreCreateRequest.PostPayment> payments = buildPostPayments(order.getId(), totalAmount);
|
|
|
|
|
|
PayScoreResult result = payScoreService.completePayScoreOrder(order.getId(), totalAmount, payments);
|
|
|
|