用户开课
用户vip
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
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.CourseEntity;
|
||||
import com.peanut.modules.common.entity.UserCourseBuyEntity;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
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;
|
||||
@@ -28,6 +29,9 @@ public class UserManageController {
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
private MyUserService userService;
|
||||
|
||||
//数据合并
|
||||
@RequestMapping("/userMerge")
|
||||
public R userMerge(@RequestBody Map<String, Object> params) {
|
||||
@@ -40,13 +44,47 @@ public class UserManageController {
|
||||
return mergeService.addUserCourseBuy(userCourseBuyEntity);
|
||||
}
|
||||
|
||||
//课程列表带下级
|
||||
//课程列表
|
||||
@RequestMapping("/courseAndChildrenList")
|
||||
public R courseAndChildrenList(@RequestBody Map<String, Object> params) {
|
||||
List<CourseEntity> list = courseService.courseAndChildrenList(params);
|
||||
return R.ok().put("list",list);
|
||||
}
|
||||
|
||||
//课程目录列表
|
||||
@RequestMapping("/catalogueListByCourse")
|
||||
public R catalogueListByCourse(@RequestBody Map<String, Object> params) {
|
||||
List<CourseCatalogueEntity> list = courseService.catalogueListByCourse(params);
|
||||
return R.ok().put("list",list);
|
||||
}
|
||||
|
||||
//获取用户已有课程列表
|
||||
@RequestMapping("/getUserCourseList")
|
||||
public R getUserCourseList(@RequestBody Map<String, Object> params) {
|
||||
Page<Map<String,Object>> page = courseService.getUserCourseList(params);
|
||||
return R.ok().put("result",page);
|
||||
}
|
||||
|
||||
//获取vip用户列表
|
||||
@RequestMapping("/getVipList")
|
||||
public R getVipList(@RequestBody Map<String, Object> params) {
|
||||
Page<Map<String,Object>> page = userService.getVipList(params);
|
||||
return R.ok().put("result",page);
|
||||
}
|
||||
|
||||
//获取vip历史开通记录
|
||||
@RequestMapping("/getVipHistoryList")
|
||||
public R getVipHistoryList(@RequestBody Map<String, Object> params) {
|
||||
Page<UserVip> page = userService.getVipHistoryList(params);
|
||||
return R.ok().put("result",page);
|
||||
}
|
||||
|
||||
//获取vip历史开通记录
|
||||
@RequestMapping("/activateVIP")
|
||||
public R activateVIP(@RequestBody UserVipLog vipLog) {
|
||||
return userService.activateVIP(vipLog);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ package com.peanut.modules.master.service;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.CourseEntity;
|
||||
import com.peanut.modules.common.entity.ShopProduct;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.to.ParamTo;
|
||||
|
||||
import java.util.List;
|
||||
@@ -33,4 +32,8 @@ public interface CourseService extends IService<CourseEntity> {
|
||||
R getCourseLableLinkList(Map<String,Object> param);
|
||||
|
||||
Page<ShopProduct> getProductListForCourse(Map<String,Object> param);
|
||||
|
||||
List<CourseCatalogueEntity> catalogueListByCourse(Map<String, Object> params);
|
||||
|
||||
Page<Map<String,Object>> getUserCourseList(Map<String, Object> params);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,20 @@
|
||||
package com.peanut.modules.master.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.MyUserEntity;
|
||||
import com.peanut.modules.common.entity.UserVip;
|
||||
import com.peanut.modules.common.entity.UserVipLog;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface MyUserService extends IService<MyUserEntity> {
|
||||
|
||||
Page<Map<String,Object>> getVipList(Map<String, Object> params);
|
||||
|
||||
Page<UserVip> getVipHistoryList(Map<String, Object> params);
|
||||
|
||||
R activateVIP(UserVipLog vipLog);
|
||||
|
||||
}
|
||||
|
||||
@@ -204,14 +204,6 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
|
||||
LambdaQueryWrapper<CourseEntity> cwrapper = new LambdaQueryWrapper<>();
|
||||
cwrapper.like(CourseEntity::getTitle,params.get("title"));
|
||||
List<CourseEntity> courseList = this.list(cwrapper);
|
||||
if (courseList!=null && courseList.size() > 0){
|
||||
for (CourseEntity c : courseList) {
|
||||
LambdaQueryWrapper<CourseCatalogueEntity> catalogueWrapper = new LambdaQueryWrapper<>();
|
||||
catalogueWrapper.eq(CourseCatalogueEntity::getCourseId,c.getId());
|
||||
List<CourseCatalogueEntity> catalogueList = courseCatalogueDao.selectList(catalogueWrapper);
|
||||
c.setCourseCatalogueEntityList(catalogueList);
|
||||
}
|
||||
}
|
||||
return courseList;
|
||||
}
|
||||
|
||||
@@ -305,6 +297,35 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
|
||||
return resPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CourseCatalogueEntity> catalogueListByCourse(Map<String, Object> params) {
|
||||
LambdaQueryWrapper<CourseCatalogueEntity> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CourseCatalogueEntity::getCourseId,params.get("courseId"));
|
||||
queryWrapper.orderByAsc(CourseCatalogueEntity::getSort);
|
||||
List<CourseCatalogueEntity> list = courseCatalogueDao.selectList(queryWrapper);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Map<String,Object>> getUserCourseList(Map<String, Object> params) {
|
||||
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||
Integer page = Integer.valueOf(params.get("page").toString());
|
||||
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.selectAll(CourseEntity.class);
|
||||
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueName");
|
||||
wrapper.selectAs(UserCourseBuyEntity::getStartTime,"startTime");
|
||||
wrapper.selectAs(UserCourseBuyEntity::getEndTime,"endTime");
|
||||
wrapper.rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCourseId,CourseEntity::getId);
|
||||
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getId,UserCourseBuyEntity::getCatalogueId);
|
||||
if (StringUtils.isNotBlank(params.get("title").toString())){
|
||||
wrapper.like(CourseEntity::getTitle,params.get("title"));
|
||||
}
|
||||
wrapper.eq(UserCourseBuyEntity::getUserId,params.get("userId"));
|
||||
wrapper.orderByAsc(CourseEntity::getSort);
|
||||
Page<Map<String,Object>> pageRes = this.pageMaps(new Page<>(page, limit), wrapper);
|
||||
return pageRes;
|
||||
}
|
||||
|
||||
private CourseMedicine getPCourseMedicine(CourseMedicine m){
|
||||
if (m.getPid()!=0){
|
||||
CourseMedicine pm = medicalDao.selectById(m.getPid());
|
||||
|
||||
@@ -1,13 +1,116 @@
|
||||
package com.peanut.modules.master.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.DateUtil;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.utils.ShiroUtils;
|
||||
import com.peanut.modules.common.dao.MyUserDao;
|
||||
import com.peanut.modules.common.entity.MyUserEntity;
|
||||
import com.peanut.modules.common.dao.UserVipDao;
|
||||
import com.peanut.modules.common.dao.UserVipLogDao;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.master.service.MyUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service("masterMyUserService")
|
||||
public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> implements MyUserService {
|
||||
|
||||
@Autowired
|
||||
public MyUserDao userDao;
|
||||
@Autowired
|
||||
public UserVipDao userVipDao;
|
||||
@Autowired
|
||||
public UserVipLogDao userVipLogDao;
|
||||
|
||||
@Override
|
||||
public Page<Map<String,Object>> getVipList(Map<String, Object> params) {
|
||||
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||
Integer page = Integer.valueOf(params.get("page").toString());
|
||||
MPJLambdaWrapper<MyUserEntity> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.selectAll(MyUserEntity.class);
|
||||
wrapper.selectAs(UserVip::getStartTime,"startTime");
|
||||
wrapper.selectAs(UserVip::getEndTime,"endTime");
|
||||
wrapper.leftJoin(UserVip.class,UserVip::getUserId,MyUserEntity::getId);
|
||||
wrapper.eq(MyUserEntity::getVip,params.get("type"));
|
||||
wrapper.eq(UserVip::getState,0);
|
||||
if (StringUtils.isNotBlank(params.get("userWords").toString())){
|
||||
wrapper.and(t->t.like(MyUserEntity::getName,params.get("userWords")).or().like(MyUserEntity::getNickname,params.get("userWords"))
|
||||
.or().like(MyUserEntity::getEmail,params.get("userWords")).or().like(MyUserEntity::getTel,params.get("userWords")));
|
||||
}
|
||||
Page<Map<String,Object>> pageRes = userDao.selectMapsPage(new Page<>(page, limit), wrapper);
|
||||
return pageRes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<UserVip> getVipHistoryList(Map<String, Object> params) {
|
||||
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||
Integer page = Integer.valueOf(params.get("page").toString());
|
||||
MPJLambdaWrapper<UserVip> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.eq(UserVip::getUserId,params.get("userId"));
|
||||
wrapper.orderByDesc(UserVip::getEndTime);
|
||||
if (StringUtils.isNotBlank(params.get("startTime").toString())){
|
||||
wrapper.ge(UserVip::getStartTime, params.get("startTime"));
|
||||
}
|
||||
if (StringUtils.isNotBlank(params.get("endTime").toString())){
|
||||
wrapper.ge(UserVip::getEndTime, params.get("endTime"));
|
||||
}
|
||||
Page<UserVip> pageRes = userVipDao.selectPage(new Page<>(page, limit), wrapper);
|
||||
return pageRes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R activateVIP(UserVipLog vipLog) {
|
||||
MyUserEntity user = userDao.selectOne(new LambdaQueryWrapper<MyUserEntity>().eq(MyUserEntity::getId,vipLog.getUserId()));
|
||||
if ("2".equals(user.getVip())){
|
||||
if (vipLog.getType()==3) {
|
||||
return R.error("当前为医学vip,只能升级成超级vip");
|
||||
}
|
||||
}
|
||||
if ("3".equals(user.getVip())){
|
||||
if (vipLog.getType()==2) {
|
||||
return R.error("当前为国学vip,只能升级成超级vip");
|
||||
}
|
||||
}
|
||||
if (user.getPeanutCoin().compareTo(vipLog.getPoint())<0){
|
||||
return R.error("虚拟币不足");
|
||||
}
|
||||
if (user.getJf().compareTo(vipLog.getJf())<0){
|
||||
return R.error("积分不足");
|
||||
}
|
||||
//先将原VIP失效
|
||||
List<UserVip> userVip = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,vipLog.getUserId()).eq(UserVip::getState,0));
|
||||
if (userVip.size()>0){
|
||||
for (UserVip u : userVip) {
|
||||
u.setState(1);;
|
||||
userVipDao.updateById(u);
|
||||
}
|
||||
}
|
||||
//添加生成VIP记录
|
||||
vipLog.setAdminId(Integer.parseInt(ShiroUtils.getUserId().toString()));
|
||||
userVipLogDao.insert(vipLog);
|
||||
//扣除虚拟币和积分
|
||||
user.setPeanutCoin(user.getPeanutCoin().subtract(vipLog.getPoint()));
|
||||
user.setJf(user.getJf().subtract(vipLog.getJf()));
|
||||
userDao.updateById(user);
|
||||
//新建用户vip
|
||||
UserVip newUserVip = new UserVip();
|
||||
newUserVip.setUserId(vipLog.getUserId());
|
||||
newUserVip.setType(vipLog.getType());
|
||||
newUserVip.setStartTime(new Date());
|
||||
newUserVip.setEndTime(DateUtils.addDays(newUserVip.getStartTime(),vipLog.getDays()));
|
||||
userVipDao.insert(newUserVip);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user