feat 同步支付方式功能

This commit is contained in:
bootx
2024-02-17 23:48:02 +08:00
parent 74b2cb70b7
commit 47ed8e9265
12 changed files with 136 additions and 32 deletions

View File

@@ -77,4 +77,10 @@ public class VoucherManager extends BaseManager<VoucherMapper, Voucher> {
.update();
}
/**
* 卡号是否存在
*/
public boolean existsByCardNo(String cardNo) {
return this.existedByField(Voucher::getCardNo, cardNo);
}
}

View File

@@ -34,6 +34,10 @@ public class VoucherService {
*/
public void voucherImport(VoucherImportParam param){
Voucher voucher = VoucherConvert.CONVERT.convert(param);
// 判断重复
if (voucherManager.existsByCardNo(param.getCardNo())) {
throw new BizException("钱包已经开通");
}
voucherManager.save(voucher);
}

View File

@@ -37,7 +37,7 @@ public class Wallet extends MpBaseEntity implements EntityBaseFunction<WalletDto
private String userId;
/** 钱包名称 */
@DbColumn("钱包名称")
@DbColumn(comment = "钱包名称")
private String name;
/** 余额 */

View File

@@ -29,21 +29,28 @@ public class WalletQueryService {
private final WalletManager walletManager;
/**
* 根据钱包ID查询Wallet
* 根据钱包ID查询钱包
*/
public WalletDto findById(Long walletId) {
return walletManager.findById(walletId).map(Wallet::toDto).orElseThrow(DataNotExistException::new);
public WalletDto findById(Long id) {
return walletManager.findById(id).map(Wallet::toDto).orElseThrow(DataNotExistException::new);
}
/**
* 获取钱包综合信息
*/
public WalletDto findById(String userId) {
public WalletDto findByUserId(String userId) {
return walletManager.findByUser(userId).map(Wallet::toDto).orElseThrow(DataNotExistException::new);
}
/**
* 查询用户 分页
* 判断用户是否开通了钱包
*/
public boolean existsByUserId(String userId) {
return walletManager.existsByUser(userId);
}
/**
* 分页
*/
public PageResult<WalletDto> page(PageParam pageParam, WalletQueryParam param) {
return MpUtil.convert2DtoPageResult(walletManager.page(pageParam, param));
@@ -51,20 +58,18 @@ public class WalletQueryService {
/**
* 获取钱包, 获取顺序: 1. 显式传入的钱包ID 2. 显式传入的用户ID 3.
*
* 获取钱包, 获取顺序: 1. 钱包ID 2. 用户ID
*/
public Wallet getWallet(WalletPayParam walletPayParam){
public Wallet getWallet(WalletPayParam param){
Wallet wallet = null;
// 首先根据钱包ID查询
if (Objects.nonNull(walletPayParam.getWalletId())) {
wallet = walletManager.findById(walletPayParam.getWalletId()).orElseThrow(null);
if (Objects.nonNull(param.getWalletId())){
wallet = walletManager.findById(param.getWalletId()).orElseThrow(DataNotExistException::new);
}
if (Objects.nonNull(wallet)){
return wallet;
if (Objects.isNull(wallet)){
wallet = walletManager.findByUser(param.getUserId()).orElseThrow(DataNotExistException::new);
}
return null;
return wallet;
}
}

View File

@@ -7,7 +7,7 @@ import cn.bootx.platform.daxpay.service.core.channel.wallet.dao.WalletManager;
import cn.bootx.platform.daxpay.service.core.channel.wallet.entity.Wallet;
import cn.bootx.platform.daxpay.service.param.channel.wallet.CreateWalletParam;
import cn.bootx.platform.daxpay.service.param.channel.wallet.WalletRechargeParam;
import cn.bootx.platform.daxpay.service.param.channel.wallet.WalletReduceParam;
import cn.bootx.platform.daxpay.service.param.channel.wallet.WalleteeDductParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -16,7 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Objects;
/**
*
* 钱包管理接口
* @author xxm
* @since 2023/6/26
*/
@@ -27,10 +27,10 @@ public class WalletService {
private final WalletManager walletManager;
/**
* 开通钱包操作,默认为启用状态, 不传输余额则默认为0
* 创建钱包操作,默认为启用状态, 不传输余额则默认为0
*/
@Transactional(rollbackFor = Exception.class)
public void createWallet(CreateWalletParam param) {
public void create(CreateWalletParam param) {
// 判断钱包是否已开通
if (walletManager.existsByUser(param.getUserId())) {
throw new BizException("钱包已经开通");
@@ -85,7 +85,7 @@ public class WalletService {
* 余额扣减
*/
@Transactional(rollbackFor = Exception.class)
public void reduce(WalletReduceParam param) {
public void deduct(WalleteeDductParam param) {
Wallet wallet = null;
if (Objects.nonNull(param.getWalletId())){
wallet = walletManager.findById(param.getWalletId()).orElseThrow(DataNotExistException::new);

View File

@@ -7,6 +7,8 @@ import cn.bootx.platform.daxpay.exception.waller.WalletLackOfBalanceException;
import cn.bootx.platform.daxpay.param.channel.WalletPayParam;
import cn.bootx.platform.daxpay.service.code.WalletCode;
import cn.bootx.platform.daxpay.service.core.channel.wallet.entity.Wallet;
import cn.bootx.platform.daxpay.service.core.channel.wallet.entity.WalletConfig;
import cn.bootx.platform.daxpay.service.core.channel.wallet.service.WalletConfigService;
import cn.bootx.platform.daxpay.service.core.channel.wallet.service.WalletPayService;
import cn.bootx.platform.daxpay.service.core.channel.wallet.service.WalletQueryService;
import cn.bootx.platform.daxpay.service.func.AbsPayStrategy;
@@ -33,6 +35,7 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT
@RequiredArgsConstructor
public class WalletPayStrategy extends AbsPayStrategy {
private final WalletConfigService walletConfigService;
private final WalletPayService walletPayService;
@@ -40,6 +43,8 @@ public class WalletPayStrategy extends AbsPayStrategy {
private Wallet wallet;
private WalletConfig walletConfig;
@Override
public PayChannelEnum getChannel() {
return PayChannelEnum.WALLET;
@@ -60,6 +65,9 @@ public class WalletPayStrategy extends AbsPayStrategy {
} catch (JSONException e) {
throw new PayFailureException("支付参数错误");
}
this.walletConfig = walletConfigService.getConfig();
// 获取钱包
this.wallet = walletQueryService.getWallet(walletPayParam);
if (Objects.isNull(this.wallet)){
@@ -69,6 +77,8 @@ public class WalletPayStrategy extends AbsPayStrategy {
if (Objects.equals(WalletCode.STATUS_FORBIDDEN, this.wallet.getStatus())) {
throw new WalletBannedException();
}
// 判断是否超过限额
// 判断余额
if (this.wallet.getBalance() < getPayChannelParam().getAmount()) {
throw new WalletLackOfBalanceException();

View File

@@ -21,17 +21,12 @@ public class WalletDto extends BaseDto implements Serializable {
private static final long serialVersionUID = -1563719305334334625L;
@Schema(description = "ID,钱包的唯一标识")
private Long id;
@Schema(description = "钱包关联的账号ID")
private Long userId;
private String userId;
@Schema(description = "商户编码")
private String mchCode;
@Schema(description = "商户应用编码")
private String mchAppCode;
/** 钱包名称 */
@Schema(description = "钱包名称")
private String name;
@Schema(description = "钱包余额")
private BigDecimal balance;

View File

@@ -4,6 +4,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* 开通钱包参数
* @author xxm
@@ -15,12 +19,16 @@ import lombok.experimental.Accessors;
public class CreateWalletParam {
@Schema(description = "用户id")
@NotBlank(message = "用户ID不可为空")
private String userId;
@Schema(description = "钱包名称")
@NotBlank(message = "钱包名称不可为空")
private String name;
@Schema(description = "钱包金额")
@NotNull(message = "钱包金额不可为空")
@Min(value = 0, message = "钱包金额不可以低于0")
private Integer balance;
}

View File

@@ -15,7 +15,7 @@ import javax.validation.constraints.NotNull;
@Data
@Accessors(chain = true)
@Schema(title = "钱包扣减参数")
public class WalletReduceParam {
public class WalleteeDductParam {
@Schema(description = "钱包ID")