From d6772ad067b007873d7081177454cc2f7323391c Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 7 Nov 2025 17:04:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E9=97=B4=E5=A4=A9=E5=8C=BB?= =?UTF-8?q?=E5=B8=81=E3=80=81=E7=A7=AF=E5=88=86=E8=B5=A0=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserManageController.java | 85 ++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/peanut/modules/master/controller/UserManageController.java b/src/main/java/com/peanut/modules/master/controller/UserManageController.java index ce15645a..71f84c3f 100644 --- a/src/main/java/com/peanut/modules/master/controller/UserManageController.java +++ b/src/main/java/com/peanut/modules/master/controller/UserManageController.java @@ -3,14 +3,19 @@ package com.peanut.modules.master.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.peanut.common.utils.R; import com.peanut.modules.common.entity.*; +import com.peanut.modules.common.service.JfTransactionDetailsService; +import com.peanut.modules.common.service.TransactionDetailsService; import com.peanut.modules.master.service.CourseService; import com.peanut.modules.master.service.MyUserService; import com.peanut.modules.master.service.UserManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; + +import java.math.BigDecimal; import java.util.List; import java.util.Map; import org.springframework.jdbc.core.JdbcTemplate; @@ -28,12 +33,88 @@ public class UserManageController { @Autowired private UserManageService mergeService; - @Autowired private CourseService courseService; - @Autowired private MyUserService userService; + @Autowired + private TransactionDetailsService transactionDetailsService; + @Autowired + private JfTransactionDetailsService jfTransactionDetailsService; + + //天医币赠送 + @RequestMapping("/givePointBetweenUsers") + @Transactional + public R givePointBetweenUsers(@RequestBody Map params) { + MyUserEntity user = userService.getById(params.get("userId").toString()); + BigDecimal point = new BigDecimal(params.get("point").toString()); + if (point.compareTo(BigDecimal.ZERO)<=0) { + return R.error("赠送金额应大于零"); + } + if (user.getPeanutCoin().compareTo(point)<0) { + return R.error("余额不足"); + } + MyUserEntity toUser = userService.getById(params.get("toUserId").toString()); + if(toUser==null){ + return R.error("被赠送用户不存在"); + } + user.setPeanutCoin(user.getPeanutCoin().subtract(point)); + userService.updateById(user); + TransactionDetailsEntity td = new TransactionDetailsEntity(); + td.setUserId(user.getId()); + td.setOrderType("后台扣费"); + td.setChangeAmount(point.negate()); + td.setUserBalance(user.getPeanutCoin()); + td.setNote("赠送给"+toUser.getTel()+"-"+toUser.getName()+":"+point+"天医币"); + transactionDetailsService.save(td); + toUser.setPeanutCoin(toUser.getPeanutCoin().add(point)); + userService.updateById(toUser); + TransactionDetailsEntity ttd = new TransactionDetailsEntity(); + ttd.setUserId(toUser.getId()); + ttd.setOrderType("后台充值"); + ttd.setChangeAmount(point); + ttd.setUserBalance(toUser.getPeanutCoin()); + ttd.setNote(user.getTel()+"-"+user.getName()+"赠送:"+point+"天医币"); + transactionDetailsService.save(ttd); + return R.ok(); + } + + //用户之间赠送积分 + @RequestMapping("/giveJFBetweenUsers") + @Transactional + public R giveJFBetweenUsers(@RequestBody Map params) { + MyUserEntity user = userService.getById(params.get("userId").toString()); + BigDecimal jf = new BigDecimal(params.get("jf").toString()); + if (jf.compareTo(BigDecimal.ZERO)<=0) { + return R.error("赠送金额应大于零"); + } + if (user.getJf().compareTo(jf)<0) { + return R.error("余额不足"); + } + MyUserEntity toUser = userService.getById(params.get("toUserId").toString()); + if(toUser==null){ + return R.error("被赠送用户不存在"); + } + user.setJf(user.getJf().subtract(jf)); + userService.updateById(user); + JfTransactionDetails jftd = new JfTransactionDetails(); + jftd.setUserId(user.getId()); + jftd.setActType(1); + jftd.setChangeAmount(jf.negate()); + jftd.setUserBalance(user.getJf()); + jftd.setRemark("赠送给"+toUser.getTel()+"-"+toUser.getName()+":"+jf+"积分"); + jfTransactionDetailsService.save(jftd); + toUser.setJf(toUser.getJf().add(jf)); + userService.updateById(toUser); + JfTransactionDetails tjftd = new JfTransactionDetails(); + tjftd.setUserId(toUser.getId()); + tjftd.setActType(0); + tjftd.setChangeAmount(jf); + tjftd.setUserBalance(toUser.getJf()); + tjftd.setRemark(user.getTel()+"-"+user.getName()+"赠送:"+jf+"积分"); + jfTransactionDetailsService.save(tjftd); + return R.ok(); + } //数据合并 @RequestMapping("/userMerge")