From 65aaaa71100eb18e119ebefa45484175eedd1671 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Thu, 22 May 2025 14:11:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E5=A4=A9=E5=8C=BB=E5=B8=81=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=8A=A0=E5=B0=8F=E6=95=B0=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/controller/MyUserController.java | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/peanut/modules/book/controller/MyUserController.java b/src/main/java/com/peanut/modules/book/controller/MyUserController.java index b40ab205..b8ce6c35 100644 --- a/src/main/java/com/peanut/modules/book/controller/MyUserController.java +++ b/src/main/java/com/peanut/modules/book/controller/MyUserController.java @@ -630,26 +630,25 @@ public class MyUserController { @RequestMapping("/pointChange") public R pointChange(@RequestParam Map params){ String pointType = params.get("pointType"); - String pointAmount = params.get("pointAmount"); - if (Integer.valueOf(pointAmount)<=0){ - return R.error("变动金额不能为负数"); + BigDecimal pointAmount = new BigDecimal(params.get("pointAmount")); + if (pointAmount.compareTo(BigDecimal.ZERO)<=0){ + return R.error("变动金额不能为0或负数"); } String id = params.get("id"); MyUserEntity byId = userService.getById(id); - int i = 0; + BigDecimal i = BigDecimal.ZERO; if (pointType.equals("0")) { - i = byId.getPeanutCoin().intValue() + Integer.valueOf(pointAmount); - byId.setPeanutCoin(new BigDecimal(i)); + i = byId.getPeanutCoin().add(pointAmount); + byId.setPeanutCoin(i); }else { - i = byId.getPeanutCoin().intValue() - Integer.valueOf(pointAmount); - if (i >= 0) { - byId.setPeanutCoin(new BigDecimal(i)); + i = byId.getPeanutCoin().subtract(pointAmount); + if (i.compareTo(BigDecimal.ZERO)>=0) { + byId.setPeanutCoin(i); }else { return R.error("余额不足!扣除失败!"); } } - TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity(); transactionDetailsEntity.setUserId(Integer.valueOf(id)); transactionDetailsEntity.setOrderType("后台充扣操作"); @@ -657,27 +656,14 @@ public class MyUserController { transactionDetailsEntity.setUserName(byId.getNickname()); transactionDetailsEntity.setNote(params.get("note")); if (pointType.equals("0")) { - transactionDetailsEntity.setChangeAmount(new BigDecimal(Integer.valueOf(pointAmount))); + transactionDetailsEntity.setChangeAmount(pointAmount); transactionDetailsEntity.setRemark("充值"); }else { - transactionDetailsEntity.setChangeAmount(new BigDecimal(Integer.valueOf(pointAmount)).negate()); + transactionDetailsEntity.setChangeAmount(pointAmount.negate()); transactionDetailsEntity.setRemark("扣费"); } - BigDecimal balance = new BigDecimal(i); - transactionDetailsEntity.setUserBalance(balance); + transactionDetailsEntity.setUserBalance(i); transactionDetailsService.save(transactionDetailsEntity); - - - // 插入 花生币 充值记录 -// IosPayOrderEntity payPaymentOrderEntity = new IosPayOrderEntity(); -// payPaymentOrderEntity.setUserId(Integer.valueOf(id)); -// payPaymentOrderEntity.setRealAmount(new BigDecimal(byId.getPeanutCoin())); -// payPaymentOrderEntity.setRechargeAmount(new BigDecimal(i)); -// payPaymentOrderEntity.setRechargeChannel("后台手动充值"); -// payPaymentOrderEntity.setRechargeStatus("success"); -// payPaymentOrderEntity.setSuccessTime(new Date()); -// payPaymentOrderService.save(payPaymentOrderEntity); - userService.updateById(byId); return R.ok(); }