VIP改版
This commit is contained in:
@@ -3,6 +3,7 @@ package com.peanut.modules.book.controller;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
@@ -11,12 +12,14 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.MD5Utils;
|
||||
import com.peanut.common.utils.MailUtil;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.book.to.PageIdDto;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.UserInviteRegisterService;
|
||||
import com.peanut.modules.common.service.UserVipService;
|
||||
import com.peanut.modules.sys.service.SysUserTokenService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -45,19 +48,15 @@ public class MyUserController {
|
||||
@Autowired
|
||||
private MyUserService userService;
|
||||
@Autowired
|
||||
private BuyOrderService buyOrderService;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
@Autowired
|
||||
private SysUserTokenService sysUserTokenService;
|
||||
@Autowired
|
||||
private BookBuyConfigService bookBuyConfigService;
|
||||
@Autowired
|
||||
private BookService bookService;
|
||||
@Autowired
|
||||
private TransactionDetailsService transactionDetailsService;
|
||||
@Autowired
|
||||
private UserInviteRegisterService inviteRegisterService;
|
||||
@Autowired
|
||||
private UserVipService userVipService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
@@ -77,15 +76,34 @@ public class MyUserController {
|
||||
*/
|
||||
@RequestMapping("/getUserList")
|
||||
public R getUserList(@RequestBody PageIdDto p){
|
||||
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
MPJLambdaWrapper<MyUserEntity> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.and(p.getKey()!="",k->k.like(MyUserEntity::getName,p.getKey()).or().like(MyUserEntity::getTel,p.getKey()).or().like(MyUserEntity::getEmail,p.getKey()));
|
||||
if (!StringUtils.isEmpty(p.getVipType())){
|
||||
wrapper.eq(MyUserEntity::getVip,p.getVipType());
|
||||
if ("1".equals(p.getVipType())){
|
||||
List<Map<String,Object>> list = userVipService.listMaps(new MPJLambdaWrapper<UserVip>().eq(UserVip::getState,0)
|
||||
.in(UserVip::getType,4,5,6).groupBy(UserVip::getUserId)
|
||||
.select("count(1) num,user_id userId ").having("num = 3"));
|
||||
List<Integer> ids = list.stream().map(map -> (int)map.get("userId")).collect(Collectors.toList());
|
||||
wrapper.in(MyUserEntity::getId,ids);
|
||||
}else if ("2".equals(p.getVipType())){
|
||||
List<Map<String,Object>> list = userVipService.listMaps(new MPJLambdaWrapper<UserVip>().eq(UserVip::getState,0)
|
||||
.in(UserVip::getType,7,8).groupBy(UserVip::getUserId)
|
||||
.select("count(1) num,user_id userId ").having("num = 2"));
|
||||
List<Integer> ids = list.stream().map(map -> (int)map.get("userId")).collect(Collectors.toList());
|
||||
wrapper.in(MyUserEntity::getId,ids);
|
||||
}else {
|
||||
wrapper.selectAll(MyUserEntity.class);
|
||||
wrapper.leftJoin(UserVip.class,UserVip::getUserId,MyUserEntity::getId);
|
||||
wrapper.eq(UserVip::getType,p.getVipType());
|
||||
wrapper.eq(UserVip::getState,0);
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(MyUserEntity::getCreateTime);
|
||||
|
||||
Page<MyUserEntity> myUserEntityPage = userService.getBaseMapper().selectPage(new Page<MyUserEntity>(p.getPage(), p.getLimit()), wrapper);
|
||||
|
||||
for (MyUserEntity myUserEntity : myUserEntityPage.getRecords()) {
|
||||
myUserEntity.setUserVips(userVipService.list(new LambdaQueryWrapper<UserVip>()
|
||||
.eq(UserVip::getUserId,myUserEntity.getId()).eq(UserVip::getState,0)));
|
||||
}
|
||||
return R.ok().put("user",myUserEntityPage);
|
||||
}
|
||||
|
||||
@@ -601,34 +619,6 @@ public class MyUserController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 电子书购买
|
||||
*/
|
||||
@RequestMapping("/buyEbook")
|
||||
public R buyEbook(@RequestParam Map<String, Object> params){
|
||||
String msg = "";
|
||||
String bookId = (String) params.get("bookId");
|
||||
String userId = (String) params.get("userId");
|
||||
String couponId = (String) params.get("couponId");
|
||||
BookEntity book = this.bookService.getById(bookId);
|
||||
MyUserEntity user = this.userService.getById(userId);
|
||||
if(1 == book.getIsVip()){
|
||||
if(!"1".equals(user.getVip())){
|
||||
msg ="当前书籍为VIP书籍,请开通VIP后购买!";
|
||||
return R.ok().put("msg", msg).put("status","error");
|
||||
}
|
||||
}
|
||||
msg = userService.buyEbook(userId, bookId,couponId);
|
||||
|
||||
if (msg.equals("当前书籍以购买,请勿重复购买!")) {
|
||||
return R.ok().put("msg",msg).put("status","error");
|
||||
}else if (msg.equals("余额不足,请充值!")) {
|
||||
return R.ok().put("msg",msg).put("status","error");
|
||||
}else {
|
||||
return R.ok().put("msg",msg).put("status","success");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 花生币充扣
|
||||
*/
|
||||
@@ -690,45 +680,45 @@ public class MyUserController {
|
||||
* 使用虚拟币开通vip
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/openVipByVirtualCoin")
|
||||
public R openVipByVirtualCoin(@RequestParam Map<String,Object> params){
|
||||
|
||||
Integer configId = Integer.valueOf(params.get("configId").toString());
|
||||
String orderSn = params.get("orderSn").toString();
|
||||
Integer userId = Integer.valueOf(params.get("userId").toString());
|
||||
// 根据userId查找用户信息
|
||||
MyUserEntity user = this.userService.getById(userId);
|
||||
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(configId);
|
||||
String month = bookBuyConfigEntity.getMonth();
|
||||
BigDecimal amount = new BigDecimal(bookBuyConfigEntity.getRealMoney());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(user.getPeanutCoin().compareTo(amount) >= 0){
|
||||
user.setPeanutCoin(user.getPeanutCoin().subtract(amount));
|
||||
|
||||
this.userService.updateById(user);
|
||||
// 添加消费信息
|
||||
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||
transactionDetailsEntity.setRemark("购买"+bookBuyConfigEntity.getType()+",金额"+bookBuyConfigEntity.getMoney());
|
||||
transactionDetailsEntity.setUserId(user.getId());
|
||||
transactionDetailsEntity.setUserName(user.getNickname());
|
||||
transactionDetailsEntity.setChangeAmount(amount.negate());
|
||||
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
|
||||
transactionDetailsEntity.setTel(user.getTel());
|
||||
transactionDetailsEntity.setOrderType("购买会员!");
|
||||
transactionDetailsService.save(transactionDetailsEntity);
|
||||
userService.openMember(userId,Integer.valueOf(month));
|
||||
// 插入 开通记录
|
||||
buyOrderService.updateOrderStatus(userId,orderSn,"2");
|
||||
}else{
|
||||
return R.error(500,"余额不足,请检查后操作!");
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
// @RequestMapping("/openVipByVirtualCoin")
|
||||
// public R openVipByVirtualCoin(@RequestParam Map<String,Object> params){
|
||||
//
|
||||
// Integer configId = Integer.valueOf(params.get("configId").toString());
|
||||
// String orderSn = params.get("orderSn").toString();
|
||||
// Integer userId = Integer.valueOf(params.get("userId").toString());
|
||||
// // 根据userId查找用户信息
|
||||
// MyUserEntity user = this.userService.getById(userId);
|
||||
// BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(configId);
|
||||
// String month = bookBuyConfigEntity.getMonth();
|
||||
// BigDecimal amount = new BigDecimal(bookBuyConfigEntity.getRealMoney());
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// if(user.getPeanutCoin().compareTo(amount) >= 0){
|
||||
// user.setPeanutCoin(user.getPeanutCoin().subtract(amount));
|
||||
//
|
||||
// this.userService.updateById(user);
|
||||
// // 添加消费信息
|
||||
// TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||
// transactionDetailsEntity.setRemark("购买"+bookBuyConfigEntity.getType()+",金额"+bookBuyConfigEntity.getMoney());
|
||||
// transactionDetailsEntity.setUserId(user.getId());
|
||||
// transactionDetailsEntity.setUserName(user.getNickname());
|
||||
// transactionDetailsEntity.setChangeAmount(amount.negate());
|
||||
// transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
|
||||
// transactionDetailsEntity.setTel(user.getTel());
|
||||
// transactionDetailsEntity.setOrderType("购买会员!");
|
||||
// transactionDetailsService.save(transactionDetailsEntity);
|
||||
// userService.openMember(userId,Integer.valueOf(month));
|
||||
// // 插入 开通记录
|
||||
// buyOrderService.updateOrderStatus(userId,orderSn,"2");
|
||||
// }else{
|
||||
// return R.error(500,"余额不足,请检查后操作!");
|
||||
// }
|
||||
//
|
||||
// return R.ok();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user