mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-22 03:55:17 +08:00
汇付回调添加事务控制
This commit is contained in:
@@ -13,7 +13,6 @@ import com.jsowell.adapay.common.RefundInfo;
|
||||
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;
|
||||
@@ -45,7 +44,6 @@ import java.text.ParseException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -130,94 +128,94 @@ public class NotDelayMerchantProgramLogic extends AbstractProgramLogic {
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void balancePayOrder(PayOrderDTO dto) {
|
||||
logger.info("【{}】-余额支付订单start, param:{}", this.getClass().getSimpleName(), JSON.toJSONString(dto));
|
||||
String orderCode = dto.getOrderCode(); // 订单编号
|
||||
BigDecimal chargeAmount = dto.getPayAmount(); // 支付金额
|
||||
// 查询该会员的余额
|
||||
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(dto.getMemberId());
|
||||
BigDecimal totalAccountAmount = memberVO.getPrincipalBalance();
|
||||
|
||||
if (totalAccountAmount.compareTo(chargeAmount) < 0) {
|
||||
// 总余额小于充电金额
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_IS_INSUFFICIENT);
|
||||
}
|
||||
BigDecimal principalPay = chargeAmount;
|
||||
|
||||
// 更新会员钱包
|
||||
UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder()
|
||||
.memberId(dto.getMemberId())
|
||||
.type(MemberWalletEnum.TYPE_OUT.getValue())
|
||||
.subType(MemberWalletEnum.SUBTYPE_PAYMENT_FOR_ORDER.getValue())
|
||||
.updatePrincipalBalance(principalPay) // 使用本金支付的金额
|
||||
.relatedOrderCode(orderCode)
|
||||
.build();
|
||||
memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);
|
||||
|
||||
// 查询余额充值有剩余的记录
|
||||
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), chargeAmount);
|
||||
// 记录支订单付流水
|
||||
List<PaymentInfo> paymentInfos = Lists.newArrayList();
|
||||
BigDecimal deductionAmount = BigDecimal.ZERO;
|
||||
for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
|
||||
String paymentId = balanceDeductionAmountVO.getPaymentId();
|
||||
deductionAmount = deductionAmount.add(balanceDeductionAmountVO.getDeductionAmount());
|
||||
|
||||
PaymentInfo paymentInfo = new PaymentInfo();
|
||||
paymentInfo.setPaymentId(paymentId);
|
||||
paymentInfo.setAmount(deductionAmount.toString());
|
||||
paymentInfos.add(paymentInfo);
|
||||
}
|
||||
// 记录流水
|
||||
OrderPayRecord orderPayRecord = OrderPayRecord.builder()
|
||||
.orderCode(orderCode)
|
||||
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
|
||||
.payAmount(deductionAmount)
|
||||
.acquirer(AcquirerEnum.LOCAL.getValue())
|
||||
.deductionRecord(JSON.toJSONString(paymentInfos))
|
||||
.createBy(dto.getMemberId())
|
||||
.delFlag(DelFlagEnum.NORMAL.getValue())
|
||||
.build();
|
||||
|
||||
// 订单支付流水入库
|
||||
List<OrderPayRecord> payRecordList = Lists.newArrayList(orderPayRecord);
|
||||
orderPayRecordService.batchInsert(payRecordList);
|
||||
|
||||
// 把消费金额冻结
|
||||
for (OrderPayRecord record : payRecordList) {
|
||||
List<PaymentInfo> paymentInfoList = orderPayRecordService.parseDeductionRecord(record.getDeductionRecord());
|
||||
// 循环冻结金额
|
||||
for (PaymentInfo paymentInfo : paymentInfoList) {
|
||||
String paymentId = paymentInfo.getPaymentId();
|
||||
BigDecimal amount = new BigDecimal(paymentInfo.getAmount());
|
||||
// 余额支付 临时冻结金额
|
||||
memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
|
||||
}
|
||||
}
|
||||
|
||||
// 余额支付可以直接调支付回调方法
|
||||
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
|
||||
.orderCode(orderCode)
|
||||
.payAmount(chargeAmount)
|
||||
.payMode(dto.getPayMode())
|
||||
.startMode(dto.getStartMode())
|
||||
.acquirer(AcquirerEnum.LOCAL.getValue())
|
||||
.build();
|
||||
payOrderSuccessCallback(callbackDTO);
|
||||
|
||||
// 余额支付订单 记录会员交易流水
|
||||
MemberTransactionRecord record = MemberTransactionRecord.builder()
|
||||
.orderCode(orderCode)
|
||||
.scenarioType(ScenarioEnum.ORDER.getValue())
|
||||
.memberId(memberVO.getMemberId())
|
||||
.actionType(ActionTypeEnum.FORWARD.getValue())
|
||||
.payMode(PayModeEnum.PAYMENT_OF_BALANCE.getValue())
|
||||
.paymentInstitutions(PaymentInstitutionsEnum.LOCAL_ACCOUNTS.getValue())
|
||||
.amount(dto.getPayAmount()) // 单位元
|
||||
.build();
|
||||
memberTransactionRecordService.insertSelective(record);
|
||||
}
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void balancePayOrder(PayOrderDTO dto) {
|
||||
// logger.info("【{}】-余额支付订单start, param:{}", this.getClass().getSimpleName(), JSON.toJSONString(dto));
|
||||
// String orderCode = dto.getOrderCode(); // 订单编号
|
||||
// BigDecimal chargeAmount = dto.getPayAmount(); // 支付金额
|
||||
// // 查询该会员的余额
|
||||
// MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(dto.getMemberId());
|
||||
// BigDecimal totalAccountAmount = memberVO.getPrincipalBalance();
|
||||
//
|
||||
// if (totalAccountAmount.compareTo(chargeAmount) < 0) {
|
||||
// // 总余额小于充电金额
|
||||
// throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_IS_INSUFFICIENT);
|
||||
// }
|
||||
// BigDecimal principalPay = chargeAmount;
|
||||
//
|
||||
// // 更新会员钱包
|
||||
// UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder()
|
||||
// .memberId(dto.getMemberId())
|
||||
// .type(MemberWalletEnum.TYPE_OUT.getValue())
|
||||
// .subType(MemberWalletEnum.SUBTYPE_PAYMENT_FOR_ORDER.getValue())
|
||||
// .updatePrincipalBalance(principalPay) // 使用本金支付的金额
|
||||
// .relatedOrderCode(orderCode)
|
||||
// .build();
|
||||
// memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);
|
||||
//
|
||||
// // 查询余额充值有剩余的记录
|
||||
// List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), chargeAmount);
|
||||
// // 记录支订单付流水
|
||||
// List<PaymentInfo> paymentInfos = Lists.newArrayList();
|
||||
// BigDecimal deductionAmount = BigDecimal.ZERO;
|
||||
// for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
|
||||
// String paymentId = balanceDeductionAmountVO.getPaymentId();
|
||||
// deductionAmount = deductionAmount.add(balanceDeductionAmountVO.getDeductionAmount());
|
||||
//
|
||||
// PaymentInfo paymentInfo = new PaymentInfo();
|
||||
// paymentInfo.setPaymentId(paymentId);
|
||||
// paymentInfo.setAmount(deductionAmount.toString());
|
||||
// paymentInfos.add(paymentInfo);
|
||||
// }
|
||||
// // 记录流水
|
||||
// OrderPayRecord orderPayRecord = OrderPayRecord.builder()
|
||||
// .orderCode(orderCode)
|
||||
// .payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
|
||||
// .payAmount(deductionAmount)
|
||||
// .acquirer(AcquirerEnum.LOCAL.getValue())
|
||||
// .deductionRecord(JSON.toJSONString(paymentInfos))
|
||||
// .createBy(dto.getMemberId())
|
||||
// .delFlag(DelFlagEnum.NORMAL.getValue())
|
||||
// .build();
|
||||
//
|
||||
// // 订单支付流水入库
|
||||
// List<OrderPayRecord> payRecordList = Lists.newArrayList(orderPayRecord);
|
||||
// orderPayRecordService.batchInsert(payRecordList);
|
||||
//
|
||||
// // 把消费金额冻结
|
||||
// for (OrderPayRecord record : payRecordList) {
|
||||
// List<PaymentInfo> paymentInfoList = orderPayRecordService.parseDeductionRecord(record.getDeductionRecord());
|
||||
// // 循环冻结金额
|
||||
// for (PaymentInfo paymentInfo : paymentInfoList) {
|
||||
// String paymentId = paymentInfo.getPaymentId();
|
||||
// BigDecimal amount = new BigDecimal(paymentInfo.getAmount());
|
||||
// // 余额支付 临时冻结金额
|
||||
// memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 余额支付可以直接调支付回调方法
|
||||
// PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
|
||||
// .orderCode(orderCode)
|
||||
// .payAmount(chargeAmount)
|
||||
// .payMode(dto.getPayMode())
|
||||
// .startMode(dto.getStartMode())
|
||||
// .acquirer(AcquirerEnum.LOCAL.getValue())
|
||||
// .build();
|
||||
// payOrderSuccessCallback(callbackDTO);
|
||||
//
|
||||
// // 余额支付订单 记录会员交易流水
|
||||
// MemberTransactionRecord record = MemberTransactionRecord.builder()
|
||||
// .orderCode(orderCode)
|
||||
// .scenarioType(ScenarioEnum.ORDER.getValue())
|
||||
// .memberId(memberVO.getMemberId())
|
||||
// .actionType(ActionTypeEnum.FORWARD.getValue())
|
||||
// .payMode(PayModeEnum.PAYMENT_OF_BALANCE.getValue())
|
||||
// .paymentInstitutions(PaymentInstitutionsEnum.LOCAL_ACCOUNTS.getValue())
|
||||
// .amount(dto.getPayAmount()) // 单位元
|
||||
// .build();
|
||||
// memberTransactionRecordService.insertSelective(record);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 余额支付订单逻辑
|
||||
|
||||
Reference in New Issue
Block a user