超v管理
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
package com.peanut.modules.master.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.MyUserEntity;
|
||||
import com.peanut.modules.common.entity.UserVip;
|
||||
import com.peanut.modules.master.service.MyUserService;
|
||||
import com.peanut.modules.master.service.UserVipService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.transaction.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 超V管理
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController("masterUserVip")
|
||||
@RequestMapping("master/userVip")
|
||||
public class UserVipController {
|
||||
|
||||
@Autowired
|
||||
private UserVipService vipService;
|
||||
@Autowired
|
||||
private MyUserService userService;
|
||||
|
||||
@RequestMapping("/listByPage")
|
||||
public R listByPage(@RequestBody Map<String, Object> params) {
|
||||
MPJLambdaWrapper<UserVip> wrapper = new MPJLambdaWrapper();
|
||||
wrapper.selectAll(UserVip.class);
|
||||
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId, UserVip::getUserId);
|
||||
if (params.containsKey("userName")&& StringUtils.isNotEmpty(params.get("userName").toString())) {
|
||||
wrapper.eq(MyUserEntity::getName,params.get("userName"));
|
||||
}
|
||||
if (params.containsKey("tel")&& StringUtils.isNotEmpty(params.get("tel").toString())) {
|
||||
wrapper.eq(MyUserEntity::getTel,params.get("tel"));
|
||||
}
|
||||
if (params.containsKey("email")&& StringUtils.isNotEmpty(params.get("email").toString())) {
|
||||
wrapper.eq(MyUserEntity::getEmail,params.get("email"));
|
||||
}
|
||||
if (params.containsKey("type")&& StringUtils.isNotEmpty(params.get("type").toString())) {
|
||||
wrapper.eq(UserVip::getType,params.get("type"));
|
||||
}
|
||||
if (params.containsKey("state")&& StringUtils.isNotEmpty(params.get("state").toString())) {
|
||||
wrapper.eq(UserVip::getState,params.get("state"));
|
||||
}
|
||||
wrapper.orderByAsc(UserVip::getEndTime);
|
||||
Page<UserVip> page = vipService.page(new Page<>(
|
||||
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
||||
List<UserVip> userVips = page.getRecords();
|
||||
if (userVips.size() > 0){
|
||||
for (UserVip userVip : userVips) {
|
||||
userVip.setUser(userService.getById(userVip.getUserId()));
|
||||
}
|
||||
}
|
||||
return R.ok().put("result", page);
|
||||
}
|
||||
|
||||
@RequestMapping("/saveUserVip")
|
||||
@Transactional
|
||||
public R saveUserVip(@RequestBody Map<String, Object> params) {
|
||||
MyUserEntity user = userService.getById(params.get("userId").toString());
|
||||
if (user.getPeanutCoin().compareTo(new BigDecimal(params.get("point").toString()))>=0){
|
||||
if (user.getPeanutCoin().compareTo(new BigDecimal(params.get("jf").toString()))>=0){
|
||||
UserVip userVip = new UserVip();
|
||||
userVip.setUserId(Integer.parseInt(params.get("userId").toString()));
|
||||
userVip.setType(Integer.parseInt(params.get("type").toString()));
|
||||
userVip.setEndTime(DateUtils.addDateMonths(new Date(),Integer.parseInt(params.get("month").toString())));
|
||||
vipService.save(userVip);
|
||||
user.setPeanutCoin(user.getPeanutCoin().subtract(new BigDecimal(params.get("point").toString())));
|
||||
user.setJf(user.getJf().subtract(new BigDecimal(params.get("jf").toString())));
|
||||
user.setVip(params.get("type").toString());
|
||||
userService.saveOrUpdate(user);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error("积分不足");
|
||||
}
|
||||
}else {
|
||||
return R.error("花生币不足");
|
||||
}
|
||||
}
|
||||
|
||||
//延长过期时间,month为延长月数
|
||||
@RequestMapping("/extendUserVip")
|
||||
public R extendUserVip(@RequestBody Map<String, Object> params) {
|
||||
UserVip userVip = vipService.getById(params.get("userVipId").toString());
|
||||
MyUserEntity user = userService.getById(userVip.getUserId());
|
||||
if (user.getPeanutCoin().compareTo(new BigDecimal(params.get("point").toString()))>=0){
|
||||
if (user.getPeanutCoin().compareTo(new BigDecimal(params.get("jf").toString()))>=0){
|
||||
Date newEndTime = DateUtils.addDateMonths(userVip.getEndTime(),Integer.parseInt(params.get("month").toString()));
|
||||
userVip.setEndTime(newEndTime);
|
||||
vipService.saveOrUpdate(userVip);
|
||||
user.setPeanutCoin(user.getPeanutCoin().subtract(new BigDecimal(params.get("point").toString())));
|
||||
user.setJf(user.getJf().subtract(new BigDecimal(params.get("jf").toString())));
|
||||
userService.saveOrUpdate(user);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error("积分不足");
|
||||
}
|
||||
}else {
|
||||
return R.error("花生币不足");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user