|
|
@ -3,6 +3,7 @@ package com.example.demo.serviceImpl.coin; |
|
|
import com.example.demo.Util.GoldTistV2; |
|
|
import com.example.demo.Util.GoldTistV2; |
|
|
import com.example.demo.Util.SimpleIdGenerator; |
|
|
import com.example.demo.Util.SimpleIdGenerator; |
|
|
import com.example.demo.domain.DTO.RegionWalletDTO; |
|
|
import com.example.demo.domain.DTO.RegionWalletDTO; |
|
|
|
|
|
import com.example.demo.domain.DTO.WalletDTO; |
|
|
import com.example.demo.domain.entity.User; |
|
|
import com.example.demo.domain.entity.User; |
|
|
import com.example.demo.domain.entity.UserGoldRecord; |
|
|
import com.example.demo.domain.entity.UserGoldRecord; |
|
|
import com.example.demo.domain.vo.coin.*; |
|
|
import com.example.demo.domain.vo.coin.*; |
|
|
@ -227,6 +228,53 @@ public class ConsumeServiceImpl implements ConsumeService { |
|
|
else if (consumeUser.getPermanentGold().compareTo(BigDecimal.ZERO)==0&&consumeUser.getFreeGold().compareTo(BigDecimal.ZERO)==0&&consumeUser.getTaskGold().compareTo(BigDecimal.ZERO)==0){ |
|
|
else if (consumeUser.getPermanentGold().compareTo(BigDecimal.ZERO)==0&&consumeUser.getFreeGold().compareTo(BigDecimal.ZERO)==0&&consumeUser.getTaskGold().compareTo(BigDecimal.ZERO)==0){ |
|
|
GoldTistV2.addCoinRecordNew(String.valueOf(consumeUser.getJwcode()), consumeUser.getRemark(),consumeUser.getAdminName(),consumeUser.getGoodsName());} |
|
|
GoldTistV2.addCoinRecordNew(String.valueOf(consumeUser.getJwcode()), consumeUser.getRemark(),consumeUser.getAdminName(),consumeUser.getGoodsName());} |
|
|
|
|
|
|
|
|
|
|
|
if(consumeUser.getPermanentGold().compareTo(BigDecimal.ZERO)!=0) { |
|
|
|
|
|
// 需要扣除的永久金币总量 |
|
|
|
|
|
BigDecimal remainingPermanentGold = consumeUser.getPermanentGold(); |
|
|
|
|
|
|
|
|
|
|
|
// 遍历钱包列表,依次扣款 |
|
|
|
|
|
for(RegionWalletDTO wallet : regionWallets) { |
|
|
|
|
|
// 如果剩余需要扣除的金额为0,结束循环 |
|
|
|
|
|
if(remainingPermanentGold.compareTo(BigDecimal.ZERO) <= 0) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取当前钱包的永久金币余额 |
|
|
|
|
|
BigDecimal walletBalance = wallet.getCurrentPermanentGold() != null ? wallet.getCurrentPermanentGold() : BigDecimal.ZERO; |
|
|
|
|
|
|
|
|
|
|
|
// 计算当前钱包可以扣除的金额(不超过钱包余额和剩余需要扣除的金额) |
|
|
|
|
|
BigDecimal deductAmount = BigDecimal.ZERO; |
|
|
|
|
|
if(walletBalance.compareTo(remainingPermanentGold) >= 0) { |
|
|
|
|
|
// 钱包余额足够,扣除剩余全部金额 |
|
|
|
|
|
deductAmount = remainingPermanentGold; |
|
|
|
|
|
remainingPermanentGold = BigDecimal.ZERO; |
|
|
|
|
|
} else { |
|
|
|
|
|
// 钱包余额不足,扣除全部余额 |
|
|
|
|
|
deductAmount = walletBalance; |
|
|
|
|
|
remainingPermanentGold = remainingPermanentGold.subtract(deductAmount); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果需要扣除金额大于0,执行扣款操作 |
|
|
|
|
|
if(deductAmount.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
|
|
WalletDTO updateWallet = new WalletDTO(); |
|
|
|
|
|
updateWallet.setId(wallet.getId()); |
|
|
|
|
|
// 设置需要扣除的永久金币金额 |
|
|
|
|
|
updateWallet.setPermanentGold(deductAmount); |
|
|
|
|
|
|
|
|
|
|
|
// 调用Mapper方法更新钱包余额 |
|
|
|
|
|
consumeMapper.updateRegionWallet(updateWallet); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否所有需要扣除的金额都已扣除 |
|
|
|
|
|
if(remainingPermanentGold.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
|
|
// 如果还有剩余金额未扣除,说明所有钱包余额不足 |
|
|
|
|
|
String errorMsg = "所有钱包永久金币余额不足,剩余需要扣除:" + remainingPermanentGold; |
|
|
|
|
|
log.error(errorMsg); |
|
|
|
|
|
throw new SystemException(errorMsg); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
consumeMapper.add(userGoldRecord); |
|
|
consumeMapper.add(userGoldRecord); |
|
|
consumeMapper.updateUserGold(userGoldRecord); |
|
|
consumeMapper.updateUserGold(userGoldRecord); |
|
|
User user = new User(); |
|
|
User user = new User(); |
|
|
|