|
|
|
@ -204,83 +204,61 @@ public class ConsumeServiceImpl implements ConsumeService { |
|
|
|
userGoldRecord.setPayTime(new Date()); |
|
|
|
userGoldRecord.setLinkId(SimpleIdGenerator.generateId()); |
|
|
|
|
|
|
|
if (consumeUser.getPermanentGold().compareTo(BigDecimal.ZERO)!=0||consumeUser.getFreeGold().compareTo(BigDecimal.ZERO)!=0||consumeUser.getTaskGold().compareTo(BigDecimal.ZERO)!=0){ |
|
|
|
// if(consumeUser.getJwcode().equals(94226013)){ |
|
|
|
String result = GoldTistV2.addCoinNew(userGoldRecord.getJwcode().toString(), 65, |
|
|
|
(double) (userGoldRecord.getPermanentGold() + userGoldRecord.getFreeDecember() + userGoldRecord.getFreeJune() + userGoldRecord.getTaskGold()) / 100, |
|
|
|
userGoldRecord.getLinkId(), userGoldRecord.getRemark(),0, consumeUser.getAdminName(), userGoldRecord.getGoodsName()); |
|
|
|
// System.out.println("9"+result+"9"); |
|
|
|
result = result.replaceAll("[\r\n]", ""); |
|
|
|
|
|
|
|
//返回状态1加成功2减成功其他失败 -5 金币不足 -6 类型错误 -7签名错误 |
|
|
|
if (!result.equals("2")) { |
|
|
|
result = GoldTistV2.addCoinNew(userGoldRecord.getJwcode().toString(), 65, |
|
|
|
(double) (userGoldRecord.getPermanentGold() + userGoldRecord.getFreeDecember() + userGoldRecord.getFreeJune() + userGoldRecord.getTaskGold()) / 100, |
|
|
|
userGoldRecord.getLinkId(), userGoldRecord.getRemark(), 0, consumeUser.getAdminName(), userGoldRecord.getGoodsName()); |
|
|
|
//返回状态1加成功2减成功其他失败 -5 金币不足 -6 类型错误 -7签名错误 |
|
|
|
if (!result.equals("2")) { |
|
|
|
String errorMsg = "减金币失败,数据未进erp,返回状态:" + result; |
|
|
|
log.error(errorMsg); // 保留日志记录,便于问题排查 |
|
|
|
throw new SystemException(errorMsg); // 抛出系统异常,中断流程并传递错误信息 |
|
|
|
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()); |
|
|
|
UserWalletRecord userWalletRecord = new UserWalletRecord(); |
|
|
|
userWalletRecord.setJwcode(consumeUser.getJwcode()); |
|
|
|
userWalletRecord.setWalletId(wallet.getWalletId()); |
|
|
|
userWalletRecord.setAmount(-deductAmount.intValue()); |
|
|
|
userWalletRecord.setOrderCode(userGoldRecord.getOrderCode()); |
|
|
|
userWalletRecord.setDescription("购买" + consumeUser.getGoodsName()); |
|
|
|
// 设置需要扣除的永久金币金额 |
|
|
|
updateWallet.setPermanentGold(deductAmount); |
|
|
|
// 调用Mapper方法更新钱包余额 |
|
|
|
consumeMapper.updateRegionWallet(updateWallet); |
|
|
|
consumeMapper.addRegionWalletRecord(userWalletRecord); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否所有需要扣除的金额都已扣除 |
|
|
|
if(remainingPermanentGold.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
// 如果还有剩余金额未扣除,说明所有钱包余额不足 |
|
|
|
String errorMsg = "所有钱包永久金币余额不足,剩余需要扣除:" + remainingPermanentGold; |
|
|
|
log.error(errorMsg); |
|
|
|
throw new SystemException(errorMsg); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//0金币消耗,往erp传一条金币为空的记录 |
|
|
|
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());} |
|
|
|
|
|
|
|
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()); |
|
|
|
UserWalletRecord userWalletRecord = new UserWalletRecord(); |
|
|
|
userWalletRecord.setJwcode(consumeUser.getJwcode()); |
|
|
|
userWalletRecord.setWalletId(wallet.getWalletId()); |
|
|
|
userWalletRecord.setAmount(-deductAmount.intValue()); |
|
|
|
userWalletRecord.setOrderCode(userGoldRecord.getOrderCode()); |
|
|
|
userWalletRecord.setDescription("购买" + consumeUser.getGoodsName()); |
|
|
|
// 设置需要扣除的永久金币金额 |
|
|
|
updateWallet.setPermanentGold(deductAmount); |
|
|
|
// 调用Mapper方法更新钱包余额 |
|
|
|
consumeMapper.updateRegionWallet(updateWallet); |
|
|
|
consumeMapper.addRegionWalletRecord(userWalletRecord); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否所有需要扣除的金额都已扣除 |
|
|
|
if(remainingPermanentGold.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
// 如果还有剩余金额未扣除,说明所有钱包余额不足 |
|
|
|
String errorMsg = "所有钱包永久金币余额不足,剩余需要扣除:" + remainingPermanentGold; |
|
|
|
log.error(errorMsg); |
|
|
|
throw new SystemException(errorMsg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
consumeMapper.add(userGoldRecord); |
|
|
|
consumeMapper.updateUserGold(userGoldRecord); |
|
|
|
@ -310,7 +288,39 @@ public class ConsumeServiceImpl implements ConsumeService { |
|
|
|
// } |
|
|
|
//data返回订单号和创建时间 |
|
|
|
OrderResultVO resultVO = OrderResultVO.build("XF_" + orderNumber,userGoldRecord.getCreateTime()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (consumeUser.getPermanentGold().compareTo(BigDecimal.ZERO)!=0||consumeUser.getFreeGold().compareTo(BigDecimal.ZERO)!=0||consumeUser.getTaskGold().compareTo(BigDecimal.ZERO)!=0){ |
|
|
|
// if(consumeUser.getJwcode().equals(94226013)){ |
|
|
|
String result = GoldTistV2.addCoinNew(userGoldRecord.getJwcode().toString(), 65, |
|
|
|
(double) (userGoldRecord.getPermanentGold() + userGoldRecord.getFreeDecember() + userGoldRecord.getFreeJune() + userGoldRecord.getTaskGold()) / 100, |
|
|
|
userGoldRecord.getLinkId(), userGoldRecord.getRemark(),0, consumeUser.getAdminName(), userGoldRecord.getGoodsName()); |
|
|
|
// System.out.println("9"+result+"9"); |
|
|
|
result = result.replaceAll("[\r\n]", ""); |
|
|
|
|
|
|
|
//返回状态1加成功2减成功其他失败 -5 金币不足 -6 类型错误 -7签名错误 |
|
|
|
if (!result.equals("2")) { |
|
|
|
result = GoldTistV2.addCoinNew(userGoldRecord.getJwcode().toString(), 65, |
|
|
|
(double) (userGoldRecord.getPermanentGold() + userGoldRecord.getFreeDecember() + userGoldRecord.getFreeJune() + userGoldRecord.getTaskGold()) / 100, |
|
|
|
userGoldRecord.getLinkId(), userGoldRecord.getRemark(), 0, consumeUser.getAdminName(), userGoldRecord.getGoodsName()); |
|
|
|
//返回状态1加成功2减成功其他失败 -5 金币不足 -6 类型错误 -7签名错误 |
|
|
|
if (!result.equals("2")) { |
|
|
|
String errorMsg = "减金币失败,数据未进erp,返回状态:" + result; |
|
|
|
log.error(errorMsg); // 保留日志记录,便于问题排查 |
|
|
|
throw new SystemException(errorMsg); // 抛出系统异常,中断流程并传递错误信息 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//0金币消耗,往erp传一条金币为空的记录 |
|
|
|
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());} |
|
|
|
|
|
|
|
|
|
|
|
return Result.success(resultVO); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|