mirror of
https://gitee.com/dromara/dax-pay
synced 2026-08-07 05:35:47 +08:00
feat 储值卡支持冻结, 多卡同时支付扣款支持优先级
This commit is contained in:
@@ -24,19 +24,37 @@ public interface VoucherCode {
|
||||
String LOG_ACTIVE = "active";
|
||||
|
||||
/**
|
||||
* 储值卡日志-支付
|
||||
* 钱包日志-预冻结额度
|
||||
*/
|
||||
String LOG_FREEZE_BALANCE = "freeze";
|
||||
|
||||
/**
|
||||
* 钱包日志-解冻额度
|
||||
*/
|
||||
String LOG_UNFREEZE_BALANCE = "unfreeze";
|
||||
|
||||
/**
|
||||
* 钱包日志-解冻并扣减余额
|
||||
*/
|
||||
String LOG_REDUCE_AND_UNFREEZE_BALANCE = "reduceAndUnfreeze";
|
||||
|
||||
/**
|
||||
* 钱包日志-直接支付
|
||||
*/
|
||||
String LOG_PAY = "pay";
|
||||
/**
|
||||
* 钱包日志-取消支付
|
||||
*/
|
||||
String LOG_CLOSE_PAY = "closePay";
|
||||
|
||||
/**
|
||||
* 储值卡日志-退款
|
||||
* 钱包日志-退款到本卡中
|
||||
*/
|
||||
String LOG_CLOSE = "close";
|
||||
|
||||
String LOG_REFUND_SELF = "refundSelf";
|
||||
/**
|
||||
* 储值卡日志-退款
|
||||
* 钱包日志-统一退款到指定卡中
|
||||
*/
|
||||
String LOG_REFUND = "refund";
|
||||
String LOG_REFUND_ONE = "refundOne";
|
||||
|
||||
/**
|
||||
* 储值卡日志-Admin余额变动
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.bootx.platform.daxpay.core.channel.base.entity;
|
||||
|
||||
import cn.bootx.mybatis.table.modify.mybatis.mysq.annotation.DbMySqlIndex;
|
||||
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
|
||||
import cn.bootx.platform.daxpay.code.pay.PayStatusCode;
|
||||
import lombok.Data;
|
||||
@@ -21,6 +22,7 @@ import java.time.LocalDateTime;
|
||||
public class BasePayment extends MpBaseEntity {
|
||||
|
||||
/** 交易记录ID */
|
||||
@DbMySqlIndex(comment = "交易记录索引")
|
||||
private Long paymentId;
|
||||
|
||||
/** 交易金额 */
|
||||
@@ -30,6 +32,7 @@ public class BasePayment extends MpBaseEntity {
|
||||
private BigDecimal refundableBalance;
|
||||
|
||||
/** 关联的业务id */
|
||||
@DbMySqlIndex(comment = "业务id索引")
|
||||
private String businessId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,7 @@ public class VoucherManager extends BaseManager<VoucherMapper, Voucher> {
|
||||
return this.lambdaQuery()
|
||||
.ge(Objects.nonNull(param.getStartTime()), Voucher::getStartTime, param.getStartTime())
|
||||
.le(Objects.nonNull(param.getEndTime()), Voucher::getEndTime, param.getEndTime())
|
||||
.eq(Objects.nonNull(param.getEnduring()), Voucher::getEnduring, param.getEnduring())
|
||||
.eq(Objects.nonNull(param.getEnduring()), Voucher::isEnduring, param.getEnduring())
|
||||
.like(StrUtil.isNotBlank(param.getCardNo()), Voucher::getCardNo, param.getCardNo())
|
||||
.like(Objects.nonNull(param.getBatchNo()), Voucher::getBatchNo, param.getBatchNo())
|
||||
.orderByDesc(MpIdEntity::getId)
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
package cn.bootx.platform.daxpay.core.channel.voucher.entity;
|
||||
|
||||
import cn.bootx.mybatis.table.modify.annotation.DbColumn;
|
||||
import cn.bootx.mybatis.table.modify.mybatis.mysq.annotation.DbMySqlFieldType;
|
||||
import cn.bootx.mybatis.table.modify.mybatis.mysq.constants.MySqlFieldTypeEnum;
|
||||
import cn.bootx.platform.common.core.function.EntityBaseFunction;
|
||||
import cn.bootx.platform.common.mybatisplus.handler.JacksonRawTypeHandler;
|
||||
import cn.bootx.platform.daxpay.core.channel.base.entity.BasePayment;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.convert.VoucherConvert;
|
||||
import cn.bootx.platform.daxpay.dto.channel.voucher.VoucherPaymentDto;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 储值卡支付记录
|
||||
*
|
||||
@@ -18,11 +25,15 @@ import lombok.experimental.Accessors;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName("pay_voucher_payment")
|
||||
@TableName(value = "pay_voucher_payment",autoResultMap = true)
|
||||
public class VoucherPayment extends BasePayment implements EntityBaseFunction<VoucherPaymentDto> {
|
||||
|
||||
/** 储值卡id列表 */
|
||||
private String voucherIds;
|
||||
/** 储值卡扣款记录列表 */
|
||||
@DbColumn(comment = "储值卡扣款列表")
|
||||
@DbMySqlFieldType(MySqlFieldTypeEnum.LONGTEXT)
|
||||
@TableField(typeHandler = JacksonRawTypeHandler.class)
|
||||
private List<VoucherRecord> voucherRecords;
|
||||
|
||||
|
||||
@Override
|
||||
public VoucherPaymentDto toDto() {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.bootx.platform.daxpay.core.channel.voucher.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 储值卡扣款记录列表
|
||||
* @author xxm
|
||||
* @since 2023/6/29
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class VoucherRecord {
|
||||
|
||||
/** 卡号 */
|
||||
private String cardNo;
|
||||
|
||||
/** 扣款金额 */
|
||||
private BigDecimal amount;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.bootx.platform.daxpay.core.channel.voucher.service;
|
||||
|
||||
import cn.bootx.platform.common.core.exception.DataNotExistException;
|
||||
import cn.bootx.platform.common.core.function.CollectorsFunction;
|
||||
import cn.bootx.platform.common.core.util.BigDecimalUtil;
|
||||
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
|
||||
import cn.bootx.platform.daxpay.code.paymodel.VoucherCode;
|
||||
@@ -10,9 +11,11 @@ import cn.bootx.platform.daxpay.core.channel.voucher.dao.VoucherPaymentManager;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.entity.Voucher;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.entity.VoucherLog;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.entity.VoucherPayment;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.entity.VoucherRecord;
|
||||
import cn.bootx.platform.daxpay.core.payment.entity.Payment;
|
||||
import cn.bootx.platform.daxpay.exception.payment.PayFailureException;
|
||||
import cn.bootx.platform.daxpay.param.channel.voucher.VoucherPayParam;
|
||||
import cn.bootx.platform.daxpay.param.channel.voucher.VoucherRefundParam;
|
||||
import cn.bootx.platform.daxpay.param.pay.PayWayParam;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONException;
|
||||
@@ -20,6 +23,7 @@ import cn.hutool.json.JSONUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -88,52 +92,121 @@ public class VoucherPayService {
|
||||
/**
|
||||
* 支付前冻结余额
|
||||
*/
|
||||
public void freezeBalance(BigDecimal amount, Payment payment, List<Voucher> vouchers){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付成功
|
||||
*/
|
||||
public void paySuccess(Long paymentId){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接支付
|
||||
*/
|
||||
public void pay(BigDecimal amount, Payment payment, List<Voucher> vouchers) {
|
||||
vouchers.sort((o1, o2) -> BigDecimalUtil.compareTo(o1.getBalance(), o2.getBalance()));
|
||||
public List<VoucherRecord> freezeBalance(BigDecimal amount, Payment payment, List<Voucher> vouchers){
|
||||
List<VoucherLog> voucherLogs = new ArrayList<>();
|
||||
|
||||
List<VoucherRecord> voucherRecords = new ArrayList<>();
|
||||
for (Voucher voucher : vouchers) {
|
||||
// 待支付余额为零, 不在处理后面的储值卡
|
||||
if (BigDecimalUtil.compareTo(amount, BigDecimal.ZERO) < 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
BigDecimal balance = voucher.getBalance();
|
||||
// 日志
|
||||
VoucherLog voucherLog = new VoucherLog().setPaymentId(payment.getId())
|
||||
.setBusinessId(payment.getBusinessId())
|
||||
.setType(VoucherCode.LOG_PAY)
|
||||
.setVoucherId(voucher.getId())
|
||||
.setVoucherNo(voucher.getCardNo());
|
||||
VoucherLog voucherLog = new VoucherLog()
|
||||
.setPaymentId(payment.getId())
|
||||
.setBusinessId(payment.getBusinessId())
|
||||
.setType(VoucherCode.LOG_FREEZE_BALANCE)
|
||||
.setVoucherId(voucher.getId())
|
||||
.setVoucherNo(voucher.getCardNo());
|
||||
|
||||
// 待支付额大于储值卡余额. 全冻结
|
||||
if (BigDecimalUtil.compareTo(amount, balance) == 1) {
|
||||
amount = amount.subtract(balance);
|
||||
voucher.setFreezeBalance(balance);
|
||||
voucherLog.setAmount(balance);
|
||||
}
|
||||
else {
|
||||
amount = BigDecimal.ZERO;
|
||||
voucher.setFreezeBalance(amount);
|
||||
voucherLog.setAmount(amount);
|
||||
}
|
||||
voucherRecords.add(new VoucherRecord().setCardNo(voucher.getCardNo()).setAmount(voucher.getFreezeBalance()));
|
||||
voucherLogs.add(voucherLog);
|
||||
}
|
||||
voucherManager.updateAllById(vouchers);
|
||||
voucherLogManager.saveAll(voucherLogs);
|
||||
return voucherRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付成功, 对冻结的金额进行扣款
|
||||
*/
|
||||
public void paySuccess(Long paymentId){
|
||||
voucherPaymentManager.findByPaymentId(paymentId).ifPresent(voucherPayment -> {
|
||||
|
||||
List<VoucherLog> voucherLogs = new ArrayList<>();
|
||||
for (Voucher voucher : vouchers) {
|
||||
// 待支付余额为零, 不在处理后面的储值卡
|
||||
if (BigDecimalUtil.compareTo(amount, BigDecimal.ZERO) < 1) {
|
||||
break;
|
||||
}
|
||||
BigDecimal balance = voucher.getBalance();
|
||||
// 日志
|
||||
VoucherLog voucherLog = new VoucherLog()
|
||||
.setPaymentId(payment.getId())
|
||||
.setBusinessId(payment.getBusinessId())
|
||||
.setType(VoucherCode.LOG_FREEZE_BALANCE)
|
||||
.setVoucherId(voucher.getId())
|
||||
.setVoucherNo(voucher.getCardNo());
|
||||
|
||||
// 待支付额大于储值卡余额. 全冻结
|
||||
if (BigDecimalUtil.compareTo(amount, balance) == 1) {
|
||||
amount = amount.subtract(balance);
|
||||
voucher.setFreezeBalance(balance);
|
||||
voucherLog.setAmount(balance);
|
||||
} else {
|
||||
voucher.setFreezeBalance(balance.subtract(amount));
|
||||
voucherLog.setAmount(amount);
|
||||
}
|
||||
voucherLogs.add(voucherLog);
|
||||
}
|
||||
voucherManager.updateAllById(vouchers);
|
||||
voucherLogManager.saveAll(voucherLogs);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接支付
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<VoucherRecord> pay(BigDecimal amount, Payment payment, List<Voucher> vouchers) {
|
||||
List<VoucherLog> voucherLogs = new ArrayList<>();
|
||||
List<VoucherRecord> voucherRecords = new ArrayList<>();
|
||||
for (Voucher voucher : vouchers) {
|
||||
// 待支付余额为零, 不在处理后面的储值卡
|
||||
if (BigDecimalUtil.compareTo(amount, BigDecimal.ZERO) < 1) {
|
||||
break;
|
||||
}
|
||||
BigDecimal balance = voucher.getBalance();
|
||||
// 日志
|
||||
VoucherLog voucherLog = new VoucherLog()
|
||||
.setPaymentId(payment.getId())
|
||||
.setBusinessId(payment.getBusinessId())
|
||||
.setType(VoucherCode.LOG_PAY)
|
||||
.setVoucherId(voucher.getId())
|
||||
.setVoucherNo(voucher.getCardNo());
|
||||
|
||||
// 记录当前卡扣了多少钱
|
||||
BigDecimal amountRecord;
|
||||
// 待支付额大于储值卡余额. 全扣光
|
||||
if (BigDecimalUtil.compareTo(amount, balance) == 1) {
|
||||
amountRecord = voucher.getBalance();
|
||||
amount = amount.subtract(balance);
|
||||
voucher.setBalance(BigDecimal.ZERO);
|
||||
voucherLog.setAmount(balance);
|
||||
}
|
||||
else {
|
||||
amountRecord = balance.subtract(amount);
|
||||
amount = BigDecimal.ZERO;
|
||||
voucher.setBalance(balance.subtract(amount));
|
||||
voucherLog.setAmount(amount);
|
||||
}
|
||||
voucherLogs.add(voucherLog);
|
||||
voucherRecords.add(new VoucherRecord().setCardNo(voucher.getCardNo()).setAmount(amountRecord));
|
||||
}
|
||||
voucherManager.updateAllById(vouchers);
|
||||
voucherLogManager.saveAll(voucherLogs);
|
||||
return voucherRecords;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +214,11 @@ public class VoucherPayService {
|
||||
* 取消支付, 可配置解除冻结金额
|
||||
* @param freeze 是否是冻结模式, 是的话对冻结金额进行解冻, 不是的话返还扣减的金额
|
||||
*/
|
||||
public void close(Long paymentId,boolean freeze) {
|
||||
public void close(Long paymentId, boolean freeze) {
|
||||
|
||||
VoucherPayment voucherPayment = voucherPaymentManager.findByPaymentId(paymentId).orElseThrow(DataNotExistException::new);
|
||||
|
||||
|
||||
// 查找支付记录日志
|
||||
List<VoucherLog> voucherLogs = voucherLogManager.findByPaymentIdAndType(paymentId, VoucherCode.LOG_PAY);
|
||||
// 查出关联的储值卡
|
||||
@@ -158,7 +235,7 @@ public class VoucherPayService {
|
||||
.setBusinessId(voucherLog.getBusinessId())
|
||||
.setVoucherId(voucher.getId())
|
||||
.setVoucherNo(voucher.getCardNo())
|
||||
.setType(VoucherCode.LOG_CLOSE);
|
||||
.setType(VoucherCode.LOG_CLOSE_PAY);
|
||||
logs.add(log);
|
||||
}
|
||||
voucherManager.updateAllById(vouchers);
|
||||
@@ -166,25 +243,100 @@ public class VoucherPayService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款 TODO 延长卡的有效期,
|
||||
* 退款
|
||||
* 全额退款支持分别退回到原有卡和统一退回到某张卡中, 默认退回到原有卡中
|
||||
* 部分退款, 会退到指定的一张卡上, 如果不指定, 则自动退到有效期最久的卡上
|
||||
*/
|
||||
public void refund(Long paymentId, BigDecimal amount) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void refund(Long paymentId, BigDecimal amount, VoucherRefundParam voucherRefundParam) {
|
||||
VoucherPayment voucherPayment = voucherPaymentManager.findByPaymentId(paymentId)
|
||||
.orElseThrow(() -> new PayFailureException("储值卡支付记录不存在"));
|
||||
.orElseThrow(() -> new PayFailureException("储值卡支付记录不存在"));
|
||||
// 全部退款还是部分退款
|
||||
if (BigDecimalUtil.compareTo(amount,voucherPayment.getAmount())==0){
|
||||
// 是否全部退到一张卡中
|
||||
if (voucherRefundParam.isRefundToOne()){
|
||||
this.refundToOne(voucherPayment, voucherRefundParam.getRefundVoucherNo());
|
||||
} else {
|
||||
// 退回到原有卡中
|
||||
this.refundToRaw(voucherPayment);
|
||||
}
|
||||
} else {
|
||||
this.refundToOne(voucherPayment, voucherRefundParam.getRefundVoucherNo());
|
||||
}
|
||||
}
|
||||
|
||||
Long voucherId = Long.valueOf(voucherPayment.getVoucherIds().split(",")[0]);
|
||||
Voucher voucher = voucherManager.findById(voucherId).orElseThrow(DataNotExistException::new);
|
||||
|
||||
voucher.setBalance(voucher.getBalance().add(amount));
|
||||
|
||||
VoucherLog log = new VoucherLog().setAmount(amount)
|
||||
.setPaymentId(paymentId)
|
||||
.setBusinessId(voucherPayment.getBusinessId())
|
||||
.setVoucherId(voucher.getId())
|
||||
.setVoucherNo(voucher.getCardNo())
|
||||
.setType(VoucherCode.LOG_REFUND);
|
||||
/**
|
||||
* 全部退款到一张卡中
|
||||
*/
|
||||
private void refundToOne(VoucherPayment voucherPayment, String refundVoucherNo){
|
||||
// 获取储值卡扣款信息
|
||||
List<VoucherRecord> voucherRecords = voucherPayment.getVoucherRecords();
|
||||
Map<String, BigDecimal> voucherRecordMap = voucherRecords.stream()
|
||||
.collect(Collectors.toMap(VoucherRecord::getCardNo, VoucherRecord::getAmount, CollectorsFunction::retainLatest));
|
||||
List<String> cardNoList = voucherRecords.stream()
|
||||
.map(VoucherRecord::getCardNo)
|
||||
.collect(Collectors.toList());
|
||||
List<Voucher> vouchers = voucherManager.findByCardNoList(cardNoList);
|
||||
// 筛选出来要进行退款的卡
|
||||
Voucher voucher = vouchers.stream()
|
||||
.filter(vr -> Objects.equals(vr.getCardNo(), refundVoucherNo))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new PayFailureException("退款卡号不存在"));
|
||||
// 将金额全部推到指定的卡上
|
||||
voucher.setBalance(voucher.getBalance().add(voucherPayment.getAmount()));
|
||||
// 记录日志
|
||||
List<VoucherLog> voucherLogs = new ArrayList<>();
|
||||
for (Voucher v : vouchers) {
|
||||
BigDecimal voucherAmount = voucherRecordMap.get(v.getCardNo());
|
||||
VoucherLog voucherLog = new VoucherLog()
|
||||
.setType(VoucherCode.LOG_REFUND_SELF)
|
||||
.setVoucherId(voucher.getId())
|
||||
.setVoucherNo(voucher.getCardNo())
|
||||
.setAmount(voucherAmount)
|
||||
.setPaymentId(voucherPayment.getPaymentId())
|
||||
.setBusinessId(voucherPayment.getBusinessId())
|
||||
.setRemark(String.format("退款金额 %.2f, 退款到卡号: %s 储值卡中", voucherAmount, voucher.getCardNo()));
|
||||
// 接收退款的卡
|
||||
if (Objects.equals(v,voucher)){
|
||||
voucherLog.setAmount(voucherPayment.getAmount())
|
||||
.setType(VoucherCode.LOG_REFUND_SELF)
|
||||
.setRemark(String.format("退款金额 %.2f, 退款到卡号: %s 储值卡中", voucherAmount, voucher.getCardNo()))
|
||||
}
|
||||
}
|
||||
voucherManager.updateById(voucher);
|
||||
voucherLogManager.save(log);
|
||||
voucherLogManager.saveAll(voucherLogs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款到原有的卡中
|
||||
*/
|
||||
private void refundToRaw(VoucherPayment voucherPayment){
|
||||
// 获取储值卡扣款信息
|
||||
List<VoucherRecord> voucherRecords = voucherPayment.getVoucherRecords();
|
||||
List<String> cardNoList = voucherRecords.stream()
|
||||
.map(VoucherRecord::getCardNo)
|
||||
.collect(Collectors.toList());
|
||||
Map<String, BigDecimal> voucherRecordMap = voucherRecords.stream()
|
||||
.collect(Collectors.toMap(VoucherRecord::getCardNo, VoucherRecord::getAmount, CollectorsFunction::retainLatest));
|
||||
List<Voucher> vouchers = voucherManager.findByCardNoList(cardNoList);
|
||||
|
||||
// 退款 和 记录日志
|
||||
List<VoucherLog> voucherLogs = new ArrayList<>();
|
||||
for (Voucher voucher : vouchers) {
|
||||
BigDecimal voucherAmount = voucherRecordMap.get(voucher.getCardNo());
|
||||
voucher.setBalance(voucherAmount.add(voucher.getBalance()));
|
||||
|
||||
voucherLogs.add(new VoucherLog()
|
||||
.setType(VoucherCode.LOG_REFUND_SELF)
|
||||
.setVoucherId(voucher.getId())
|
||||
.setVoucherNo(voucher.getCardNo())
|
||||
.setAmount(voucherAmount)
|
||||
.setPaymentId(voucherPayment.getPaymentId())
|
||||
.setBusinessId(voucherPayment.getBusinessId())
|
||||
.setRemark(String.format("退款金额 %.2f ", voucherAmount)));
|
||||
}
|
||||
voucherManager.updateAllById(vouchers);
|
||||
voucherLogManager.saveAll(voucherLogs);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,9 +345,9 @@ public class VoucherPayService {
|
||||
private boolean check(List<Voucher> vouchers) {
|
||||
// 判断有效期
|
||||
return vouchers.stream()
|
||||
.filter(voucher -> !Objects.equals(voucher.isEnduring(), true))
|
||||
.allMatch(voucher -> LocalDateTimeUtil.between(LocalDateTime.now(), voucher.getStartTime(),
|
||||
voucher.getEndTime()));
|
||||
.filter(voucher -> !Objects.equals(voucher.isEnduring(), true))
|
||||
.allMatch(voucher -> LocalDateTimeUtil.between(LocalDateTime.now(), voucher.getStartTime(),
|
||||
voucher.getEndTime()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,14 +2,13 @@ package cn.bootx.platform.daxpay.core.channel.voucher.service;
|
||||
|
||||
import cn.bootx.platform.common.core.exception.BizException;
|
||||
import cn.bootx.platform.common.core.util.BigDecimalUtil;
|
||||
import cn.bootx.platform.common.mybatisplus.base.MpIdEntity;
|
||||
import cn.bootx.platform.daxpay.code.pay.PayStatusCode;
|
||||
import cn.bootx.platform.daxpay.core.payment.entity.Payment;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.dao.VoucherPaymentManager;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.entity.Voucher;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.entity.VoucherPayment;
|
||||
import cn.bootx.platform.daxpay.param.pay.PayWayParam;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.entity.VoucherRecord;
|
||||
import cn.bootx.platform.daxpay.core.payment.entity.Payment;
|
||||
import cn.bootx.platform.daxpay.param.pay.PayParam;
|
||||
import cn.bootx.platform.daxpay.param.pay.PayWayParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -18,7 +17,6 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 储值卡支付记录
|
||||
@@ -36,19 +34,14 @@ public class VoucherPaymentService {
|
||||
/**
|
||||
* 添加支付记录
|
||||
*/
|
||||
public void savePayment(Payment payment, PayParam payParam, PayWayParam payMode, List<Voucher> vouchers) {
|
||||
String voucherIds = vouchers.stream()
|
||||
.map(MpIdEntity::getId)
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
VoucherPayment walletPayment = new VoucherPayment().setVoucherIds(voucherIds);
|
||||
walletPayment.setPaymentId(payment.getId())
|
||||
public void savePayment(Payment payment, PayParam payParam, PayWayParam payMode, List<VoucherRecord> voucherRecords) {
|
||||
VoucherPayment voucherPayment = new VoucherPayment().setVoucherRecords(voucherRecords);
|
||||
voucherPayment.setPaymentId(payment.getId())
|
||||
.setBusinessId(payParam.getBusinessId())
|
||||
.setAmount(payMode.getAmount())
|
||||
.setRefundableBalance(payMode.getAmount())
|
||||
.setPayStatus(payment.getPayStatus());
|
||||
voucherPaymentManager.save(walletPayment);
|
||||
voucherPaymentManager.save(voucherPayment);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.bootx.platform.daxpay.core.pay.strategy;
|
||||
|
||||
import cn.bootx.platform.daxpay.code.pay.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.entity.VoucherRecord;
|
||||
import cn.bootx.platform.daxpay.core.pay.func.AbsPayStrategy;
|
||||
import cn.bootx.platform.daxpay.core.payment.service.PaymentService;
|
||||
import cn.bootx.platform.daxpay.core.channel.voucher.entity.Voucher;
|
||||
@@ -54,12 +55,13 @@ public class VoucherStrategy extends AbsPayStrategy {
|
||||
*/
|
||||
@Override
|
||||
public void doPayHandler() {
|
||||
List<VoucherRecord> voucherRecords;
|
||||
if (this.getPayment().isAsyncPayMode()){
|
||||
voucherPayService.freezeBalance(this.getPayWayParam().getAmount(), this.getPayment(), this.vouchers);
|
||||
voucherRecords = voucherPayService.freezeBalance(this.getPayWayParam().getAmount(), this.getPayment(), this.vouchers);
|
||||
} else {
|
||||
voucherPayService.pay(this.getPayWayParam().getAmount(), this.getPayment(), this.vouchers);
|
||||
voucherRecords = voucherPayService.pay(this.getPayWayParam().getAmount(), this.getPayment(), this.vouchers);
|
||||
}
|
||||
voucherPaymentService.savePayment(this.getPayment(), getPayParam(), getPayWayParam(), vouchers);
|
||||
voucherPaymentService.savePayment(this.getPayment(), getPayParam(), getPayWayParam(), voucherRecords);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +89,7 @@ public class VoucherStrategy extends AbsPayStrategy {
|
||||
*/
|
||||
@Override
|
||||
public void doRefundHandler() {
|
||||
voucherPayService.refund(this.getPayment().getId(), this.getPayWayParam().getAmount());
|
||||
voucherPayService.refund(this.getPayment().getId(), this.getPayWayParam().getAmount(),null);
|
||||
voucherPaymentService.updateRefund(this.getPayment().getId(), this.getPayWayParam().getAmount());
|
||||
paymentService.updateRefundSuccess(this.getPayment(), this.getPayWayParam().getAmount(),
|
||||
PayChannelEnum.VOUCHER);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.bootx.platform.daxpay.param.channel.voucher;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 储值卡退款参数
|
||||
* @author xxm
|
||||
* @since 2023/6/29
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "储值卡退款参数")
|
||||
public class VoucherRefundParam {
|
||||
|
||||
@Schema(description = "是否统一退款到指定卡中")
|
||||
private boolean refundToOne;
|
||||
|
||||
@Schema(description = "统一退款到的卡号")
|
||||
private String refundVoucherNo;
|
||||
|
||||
}
|
||||
@@ -25,5 +25,4 @@ public class WalletPayParam implements Serializable {
|
||||
@Schema(description = "用户ID")
|
||||
private Long userId;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.bootx.platform.daxpay.param.channel.wallet;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 钱包退款参数
|
||||
* @author xxm
|
||||
* @since 2023/6/29
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "钱包退款参数")
|
||||
public class WalletRefundParam {
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package cn.bootx.platform.daxpay.param.refund;
|
||||
|
||||
import cn.bootx.platform.daxpay.code.pay.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.dto.payment.RefundableInfo;
|
||||
import cn.bootx.platform.daxpay.param.channel.voucher.VoucherRefundParam;
|
||||
import cn.bootx.platform.daxpay.param.channel.wallet.WalletRefundParam;
|
||||
import cn.bootx.platform.daxpay.param.pay.PayWayParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -29,6 +31,13 @@ public class RefundModeParam {
|
||||
@Schema(description = "支付金额")
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* @see VoucherRefundParam
|
||||
* @see WalletRefundParam
|
||||
*/
|
||||
@Schema(description = "扩展参数的json字符串")
|
||||
private String extraParamsJson;
|
||||
|
||||
/**
|
||||
* 转换成支付方式参数
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user