用户间天医币、积分赠送
This commit is contained in:
@@ -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<String, Object> 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<String, Object> 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")
|
||||
|
||||
Reference in New Issue
Block a user