This commit is contained in:
2023-09-26 15:41:05 +08:00
parent c41d8e00d0
commit 530e1d11d7
7 changed files with 132 additions and 221 deletions

View File

@@ -14,6 +14,7 @@ import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
import com.jsowell.adapay.response.RefundResponse;
import com.jsowell.adapay.service.AdapayService;
import com.jsowell.adapay.vo.OrderSettleResult;
import com.jsowell.adapay.vo.PaymentInfo;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
@@ -3162,16 +3163,19 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
String paymentId = balanceDeductionAmountVO.getPaymentId();
BigDecimal deductionAmount = balanceDeductionAmountVO.getDeductionAmount();
JSONObject json = new JSONObject();
json.put("paymentId", paymentId);
json.put("amount", deductionAmount);
// JSONObject json = new JSONObject();
// json.put("paymentId", paymentId);
// json.put("amount", deductionAmount);
PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setPaymentId(paymentId);
paymentInfo.setAmount(deductionAmount.toString());
// 记录流水
payRecordList.add(OrderPayRecord.builder()
.orderCode(orderCode)
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
.payAmount(deductionAmount)
.acquirer(AcquirerEnum.LOCAL.getValue())
.deductionRecord(json.toJSONString())
.deductionRecord(JSON.toJSONString(paymentInfo))
.createBy(dto.getMemberId())
.delFlag(DelFlagEnum.NORMAL.getValue())
.build());

View File

@@ -6,6 +6,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.adapay.service.AdapayService;
import com.jsowell.adapay.vo.PaymentInfo;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
@@ -227,8 +228,8 @@ public abstract class AbstractOrderLogic implements InitializingBean {
protected void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
// 订单编号
String orderCode = orderBasicInfo.getOrderCode();
// 消费金额就是订单总金额/交易记录传过来的消费金额
BigDecimal orderAmount = new BigDecimal(data.getConsumptionAmount());
// 消费金额就是订单总金额/交易记录传过来的消费金额, 四舍五入保留两位小数
BigDecimal orderAmount = new BigDecimal(data.getConsumptionAmount()).setScale(2, RoundingMode.HALF_UP);
// 付款金额 - 实际消费金额,如果有剩余,需要走退款操作 当使用余额支付时payAmount = principalPay + giftPay
BigDecimal payAmount = orderBasicInfo.getPayAmount();
@@ -406,10 +407,24 @@ public abstract class AbstractOrderLogic implements InitializingBean {
}
public static void main(String[] args) {
BigDecimal orderAmount= new BigDecimal("0.06");
List<OrderPayRecord> payRecordList = Lists.newArrayList();
payRecordList.add(OrderPayRecord.builder().deductionRecord("[{\"paymentId\":\"002212023091416010010548305359259512832\",\"amount\":0.97},{\"paymentId\":\"002212023091416110010548307874223849472\",\"amount\":1.00}]").build());
// BigDecimal orderAmount= new BigDecimal("0.06");
// List<OrderPayRecord> payRecordList = Lists.newArrayList();
String deductionRecord = "[{\"paymentId\":\"002212023091416010010548305359259512832\",\"amount\":0.97},{\"paymentId\":\"002212023091416110010548307874223849472\",\"amount\":1.00}]";
// payRecordList.add(OrderPayRecord.builder().deductionRecord(deductionRecord).build());
Object object = JSON.parse(deductionRecord);
// 都放入list里
List<PaymentInfo> resultList = Lists.newArrayList();
String s = JSON.toJSONString(object);
if (object instanceof JSONArray) {
List<PaymentInfo> paymentInfos = JSON.parseArray(s, PaymentInfo.class);
resultList.addAll(paymentInfos);
} else {
PaymentInfo paymentInfo = JSON.parseObject(s, PaymentInfo.class);
resultList.add(paymentInfo);
}
System.out.println(JSON.toJSONString(resultList));
}
/**
@@ -422,10 +437,10 @@ public abstract class AbstractOrderLogic implements InitializingBean {
BigDecimal tempAmount = new BigDecimal(orderAmount.toString()); // 临时金额
for (OrderPayRecord record : payRecordList) {
List<JSONObject> jsonObjects = parseDeductionRecord(record.getDeductionRecord());
for (JSONObject object : jsonObjects) {
String paymentId = object.getString("paymentId");
BigDecimal payAmount = object.getBigDecimal("amount"); // 此交易单支付的金额
List<PaymentInfo> paymentInfos = parseDeductionRecord(record.getDeductionRecord());
for (PaymentInfo object : paymentInfos) {
String paymentId = object.getPaymentId();
BigDecimal payAmount = new BigDecimal(object.getAmount()); // 此交易单支付的金额
// 该笔支付解冻金额
BigDecimal unfreezeAmount;
@@ -454,18 +469,21 @@ public abstract class AbstractOrderLogic implements InitializingBean {
* 解析deductionRecord
* 【公共方法】
*/
public List<JSONObject> parseDeductionRecord(String deductionRecord) {
List<JSONObject> resultList = Lists.newArrayList();
public List<PaymentInfo> parseDeductionRecord(String deductionRecord) {
List<PaymentInfo> resultList = Lists.newArrayList();
if (StringUtils.isBlank(deductionRecord)) {
return resultList;
}
Object object = JSON.parse(deductionRecord);
// 都放入list里
String s = JSON.toJSONString(object);
if (object instanceof JSONArray) {
resultList.addAll(((JSONArray) object).toList(JSONObject.class));
List<PaymentInfo> paymentInfos = JSON.parseArray(s, PaymentInfo.class);
resultList.addAll(paymentInfos);
} else {
resultList.add((JSONObject) object);
PaymentInfo paymentInfo = JSON.parseObject(s, PaymentInfo.class);
resultList.add(paymentInfo);
}
return resultList;
}

View File

@@ -1,7 +1,6 @@
package com.jsowell.pile.service.orderlogic;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.google.common.collect.ImmutableMap;
@@ -13,6 +12,7 @@ import com.jsowell.adapay.common.CreateAdaPaymentParam;
import com.jsowell.adapay.config.AbstractAdapayConfig;
import com.jsowell.adapay.factory.AdapayConfigFactory;
import com.jsowell.adapay.response.PaymentReverseResponse;
import com.jsowell.adapay.vo.PaymentInfo;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
@@ -248,24 +248,31 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), chargeAmount);
// 记录订单支付流水
JSONArray jsonArray = new JSONArray();
// JSONArray jsonArray = new JSONArray();
BigDecimal payAmt = BigDecimal.ZERO;
List<PaymentInfo> paymentInfos = Lists.newArrayList();
for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
String paymentId = balanceDeductionAmountVO.getPaymentId();
// 此交易单扣除金额
BigDecimal deductionAmount = balanceDeductionAmountVO.getDeductionAmount();
payAmt = payAmt.add(deductionAmount);
JSONObject json = new JSONObject();
json.put("paymentId", paymentId);
json.put("amount", deductionAmount);
jsonArray.add(json);
// JSONObject json = new JSONObject();
// json.put("paymentId", paymentId);
// json.put("amount", deductionAmount);
// jsonArray.add(json);
PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setPaymentId(paymentId);
paymentInfo.setAmount(deductionAmount.toString());
paymentInfos.add(paymentInfo);
}
OrderPayRecord build = OrderPayRecord.builder()
.orderCode(orderCode)
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
.payAmount(payAmt)
.acquirer(AcquirerEnum.LOCAL.getValue())
.deductionRecord(jsonArray.toJSONString())
// .deductionRecord(jsonArray.toJSONString())
.deductionRecord(JSON.toJSONString(paymentInfos))
.createBy(dto.getMemberId())
.delFlag(DelFlagEnum.NORMAL.getValue())
.build();
@@ -279,12 +286,11 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
// 把消费金额冻结
for (OrderPayRecord record : payRecordList) {
List<JSONObject> arr = parseDeductionRecord(record.getDeductionRecord());
List<PaymentInfo> paymentInfoList = parseDeductionRecord(record.getDeductionRecord());
// 循环冻结金额
for (JSONObject jsonObject : arr) {
String paymentId = jsonObject.getString("paymentId");
BigDecimal amount = jsonObject.getBigDecimal("amount");
for (PaymentInfo paymentInfo : paymentInfoList) {
String paymentId = paymentInfo.getPaymentId();
BigDecimal amount = new BigDecimal(paymentInfo.getAmount());
// 余额支付 临时冻结金额
memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
}

View File

@@ -12,6 +12,7 @@ import com.jsowell.adapay.common.CreateAdaPaymentParam;
import com.jsowell.adapay.config.AbstractAdapayConfig;
import com.jsowell.adapay.factory.AdapayConfigFactory;
import com.jsowell.adapay.response.RefundResponse;
import com.jsowell.adapay.vo.PaymentInfo;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
@@ -251,16 +252,20 @@ public class NotDelayMerchantOrderLogic extends AbstractOrderLogic{
for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
String paymentId = balanceDeductionAmountVO.getPaymentId();
BigDecimal deductionAmount = balanceDeductionAmountVO.getDeductionAmount();
JSONObject json = new JSONObject();
json.put("paymentId", paymentId);
json.put("amount", deductionAmount);
// JSONObject json = new JSONObject();
// json.put("paymentId", paymentId);
// json.put("amount", deductionAmount);
PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setPaymentId(paymentId);
paymentInfo.setAmount(deductionAmount.toString());
// 记录流水
payRecordList.add(OrderPayRecord.builder()
.orderCode(orderCode)
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
.payAmount(deductionAmount)
.acquirer(AcquirerEnum.LOCAL.getValue())
.deductionRecord(json.toJSONString())
// .deductionRecord(json.toJSONString())
.deductionRecord(JSON.toJSONString(paymentInfo))
.createBy(dto.getMemberId())
.delFlag(DelFlagEnum.NORMAL.getValue())
.build());