feat:离线模式允许扣成负
This commit is contained in:
1 parent
4ce7231705
commit
e12828656f
7 files changed
+17
-9
No files matched your search
+1
@@ -548,6 +548,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
reduceBuild.setPrice(order.getPayPrice());
|
||||
reduceBuild.setBizId(String.valueOf(order.getId()));
|
||||
reduceBuild.setBizType(WalletBizEnum.PAYMENT);
|
||||
reduceBuild.setForce(true);
|
||||
R<WalletTransactionEntity> reduceRes = walletTransactionService.reduceWalletBalance(reduceBuild);
|
||||
if (reduceRes.getCode() != 0 || ObjectUtil.isEmpty(reduceRes.getData())) {
|
||||
throw new RuntimeException("钱包扣款错误");
|
||||
|
||||
+3
@@ -29,4 +29,7 @@ public class WalletBalanceTransactionDto {
|
||||
@JsonProperty("bizType")
|
||||
private WalletBizEnum bizType;
|
||||
|
||||
@NotNull(message = "是否暴力消费")
|
||||
private Boolean force = false;
|
||||
|
||||
}
|
||||
+1
-1
@@ -61,7 +61,7 @@ public class WalletTransactionController {
|
||||
@Inner
|
||||
@PostMapping("/reduce-balance")
|
||||
public R<WalletTransactionEntity> reduceWalletBalance(@Valid @RequestBody WalletBalanceTransactionDto dto) {
|
||||
WalletTransactionEntity walletTransaction = walletTransactionService.reduceWalletBalance(dto.getWalletId(), dto.getPrice(), dto.getBizId(), dto.getBizType());
|
||||
WalletTransactionEntity walletTransaction = walletTransactionService.reduceWalletBalance(dto.getWalletId(), dto.getPrice(), dto.getBizId(), dto.getBizType(), dto.getForce());
|
||||
if (ObjectUtil.isEmpty(walletTransaction)) return R.failed("扣减钱包余额");
|
||||
return R.ok(walletTransaction);
|
||||
}
|
||||
|
||||
+6
-3
@@ -60,12 +60,15 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
|
||||
*
|
||||
* @param id 钱包 id
|
||||
* @param price 消费金额
|
||||
* @param force 是否强制消费(会导致扣款扣成负数)
|
||||
*/
|
||||
default int updateWhenConsumption(Long id, Integer price) {
|
||||
default int updateWhenConsumption(Long id, Integer price, Boolean force) {
|
||||
LambdaUpdateWrapper<WalletManageEntity> lambdaUpdateWrapper = new LambdaUpdateWrapper<WalletManageEntity>()
|
||||
.setSql(" balance = balance - " + price + ", total_expense = total_expense + " + price)
|
||||
.eq(WalletManageEntity::getId, id)
|
||||
.ge(WalletManageEntity::getBalance, price);
|
||||
.eq(WalletManageEntity::getId, id);
|
||||
if (ObjectUtil.isEmpty(force) || !force) {
|
||||
lambdaUpdateWrapper.ge(WalletManageEntity::getBalance, price);
|
||||
}
|
||||
return update(null, lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ public interface WalletTransactionService extends IService<WalletTransactionEnti
|
||||
* @param bizType 业务关联分类
|
||||
* @return 钱包流水
|
||||
*/
|
||||
WalletTransactionEntity reduceWalletBalance(Long walletId, Integer price, String bizId, WalletBizEnum bizType);
|
||||
WalletTransactionEntity reduceWalletBalance(Long walletId, Integer price, String bizId, WalletBizEnum bizType, Boolean force);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -84,13 +84,14 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
// @CacheEvict(value = CacheConstants.WALLET_DETAIL, key = "#walletId")
|
||||
public WalletTransactionEntity reduceWalletBalance(Long walletId, Integer price, String bizId, WalletBizEnum bizType) {
|
||||
public WalletTransactionEntity reduceWalletBalance(Long walletId, Integer price, String bizId, WalletBizEnum bizType, Boolean force) {
|
||||
if (ObjectUtil.isEmpty(force)) force = false;
|
||||
WalletManageEntity wallet = walletManageService.getById(walletId);
|
||||
if (ObjectUtil.isEmpty(wallet)) {
|
||||
log.error("|{}|,用户钱包id({})不存在.", TAG, walletId);
|
||||
throw new RuntimeException("扣款失败,用户钱包不存在");
|
||||
}
|
||||
int updateCounts = walletManageMapper.updateWhenConsumption(wallet.getId(), price);
|
||||
int updateCounts = walletManageMapper.updateWhenConsumption(wallet.getId(), price, force);
|
||||
if (updateCounts == 0) {
|
||||
log.error("|{}|,用户钱包id({})余额不足.", TAG, walletId);
|
||||
throw new RuntimeException("钱包余额不足");
|
||||
|
||||
+2
-2
@@ -92,7 +92,7 @@ public class WalletRuleTransactionServiceImpl extends ServiceImpl<WalletRuleTran
|
||||
entity.setIsRefund(YesNoEnum.NO.getCode());
|
||||
baseMapper.insert(entity);
|
||||
// 源头钱包扣减
|
||||
walletTransactionService.reduceWalletBalance(userConfig.getSourceWalletId(), body.getBalance(), String.valueOf(entity.getId()), WalletBizEnum.TRANSFER_ACCOUNTS);
|
||||
walletTransactionService.reduceWalletBalance(userConfig.getSourceWalletId(), body.getBalance(), String.valueOf(entity.getId()), WalletBizEnum.TRANSFER_ACCOUNTS, Boolean.FALSE);
|
||||
// 目标钱包增加
|
||||
walletTransactionService.addWalletBalance(userConfig.getTargetWalletId(), body.getBalance(), String.valueOf(entity.getId()), WalletBizEnum.TRANSFER_ACCOUNTS);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class WalletRuleTransactionServiceImpl extends ServiceImpl<WalletRuleTran
|
||||
// 源头钱包增加
|
||||
walletTransactionService.addWalletBalance(detail.getSourceWalletId(), detail.getBalance(), String.valueOf(detail.getId()), WalletBizEnum.TRANSFER_ACCOUNTS_REFUND);
|
||||
// 目标钱包扣减
|
||||
walletTransactionService.reduceWalletBalance(detail.getTargetWalletId(), detail.getBalance(), String.valueOf(detail.getId()), WalletBizEnum.TRANSFER_ACCOUNTS_REFUND);
|
||||
walletTransactionService.reduceWalletBalance(detail.getTargetWalletId(), detail.getBalance(), String.valueOf(detail.getId()), WalletBizEnum.TRANSFER_ACCOUNTS_REFUND, Boolean.FALSE);
|
||||
// 改状态
|
||||
WalletRuleTransactionEntity updateObj = new WalletRuleTransactionEntity();
|
||||
updateObj.setId(id);
|
||||
|
||||
Reference in new issue
Block a user