diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java index 160dd4be0..89c798e6a 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java @@ -912,20 +912,56 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService { clearingBillInfo.setMerchantId(merchantId); clearingBillInfo.setOrderSource("1"); + // 应收金额 + BigDecimal receivableAmount = BigDecimal.ZERO; + // 应清分金额 + BigDecimal shouldClearingAmount = BigDecimal.ZERO; + // 实际清分金额 + BigDecimal actualClearingAmount = BigDecimal.ZERO; + // 手续费金额 + BigDecimal feeAmount = BigDecimal.ZERO; + // 可提现金额 + BigDecimal withdrawableAmount = BigDecimal.ZERO; + + // 清分账单详情列表 List billDetailList = Lists.newArrayList(); // 执行分账 - orderBasicInfos.forEach(x -> { + for (OrderBasicInfo orderBasicInfo : orderBasicInfos) { try { - PaymentConfirmResponse paymentConfirmResponse = doPaymentConfirm(x, adapayMemberAccount); + PaymentConfirmResponse paymentConfirmResponse = doPaymentConfirm(orderBasicInfo, adapayMemberAccount); if (paymentConfirmResponse != null && AdapayStatusEnum.SUCCEEDED.getValue().equals(paymentConfirmResponse.getStatus())) { JSONObject jsonObject = JSON.parseObject(paymentConfirmResponse.getDescription()); String orderCode = (String) jsonObject.get("orderCode"); - billDetailList.add(ClearingBillDetail.builder().clearingBillCode(clearingBillCode).orderCode(orderCode).build()); + + // 应收金额 = 订单结算金额汇总 + receivableAmount = receivableAmount.add(orderBasicInfo.getSettleAmount()); + // 应清分金额 = 订单产生的电费+服务费实际消费 汇总 + shouldClearingAmount = shouldClearingAmount.add(orderBasicInfo.getSettleAmount()); + // 实际清分金额 = 汇付清分接口返回的清分金额 + actualClearingAmount = actualClearingAmount.add(new BigDecimal(paymentConfirmResponse.getConfirm_amt())); + // 手续费金额 = 汇付清分接口返回的手续费金额 + feeAmount = feeAmount.add(new BigDecimal(paymentConfirmResponse.getFee_amt())); + // 可提现金额 = 实际清分金额 - 手续费金额 + withdrawableAmount = withdrawableAmount + .add(new BigDecimal(paymentConfirmResponse.getConfirm_amt())) + .subtract(new BigDecimal(paymentConfirmResponse.getFee_amt())); + + ClearingBillDetail clearingBillDetail = ClearingBillDetail.builder() + .clearingBillCode(clearingBillCode) + .orderCode(orderCode) + .build(); + billDetailList.add(clearingBillDetail); } } catch (Exception e) { - logger.error("订单交易确认失败:{}", x.getOrderCode(), e); + logger.error("订单交易确认失败:{}", orderBasicInfo.getOrderCode(), e); } - }); + } + + clearingBillInfo.setReceivableAmount(receivableAmount); + clearingBillInfo.setShouldClearingAmount(shouldClearingAmount); + clearingBillInfo.setFeeAmount(feeAmount); + clearingBillInfo.setWithdrawableAmount(withdrawableAmount); + clearingBillInfo.setActualClearingAmount(actualClearingAmount); // 保存清分账单 ClearingBillTransactionDTO dto = new ClearingBillTransactionDTO();