VIP改版

This commit is contained in:
wuchunlei
2025-02-21 15:47:50 +08:00
parent 0e8b4d2e0e
commit 6908c092a5
38 changed files with 973 additions and 1797 deletions

View File

@@ -1,12 +1,9 @@
package com.peanut.modules.book.controller;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -27,7 +24,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
* @author yl
* @email yl328572838@163.com
@@ -391,85 +387,7 @@ public class BookChapterContentController {
return R.ok();
}
/**
* 鉴权获取章节
*
* @param bookid
* @param userId
* @return
*/
@RequestMapping("/getBooksCatal")
public R getBooksCatal(@RequestParam("id") Integer id,
@RequestParam("bookid") Integer bookid,
@RequestParam("userId") Integer userId) {
// TODO 验证 当前请求的书 是否存在免费章节数
BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid);
Integer freeChapterCount = bookEntity.getFreeChapterCount();
//TODO 0-免费 1-会免(改为电子书听书) 2-付费 // 阅读章节数 大于 免费章节数
Integer isVip = bookEntity.getIsVip();
if ((bookid > freeChapterCount) || freeChapterCount == 0) {
// 书籍为 会免
if (isVip == 1) {
//查询用户身份
MyUserEntity user = myUserService.getById(userId);
String vip = user.getVip();
if (!"1".equals(vip)) {
return R.error("当前为VIP");
}
}
}
if (isVip == 2) {
// 鉴权 查询权限表中 用户是否开通
boolean b = myUserService.bookAuthenticate(bookid, userId);
if (!b) {
return R.error(500, "请购买书籍!");
}
}
if (isVip == 3) {
boolean b = myUserService.bookAuthenticate(bookid, userId);
if (!b) {
List<BookChapterEntity> book = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", bookid));
ArrayList<Object> chapterList = new ArrayList<>();
int chapterIndex = 0;
for (BookChapterEntity chapter : book) {
if (chapterIndex >= freeChapterCount) {
break; // 取出前freeChapterCount条记录后退出循环
}
//获取条数记录取出对应name,url
Map<String, Object> map = new HashMap<>();
map.put("name", chapter.getChapter());
map.put("url", chapter.getVoices());
chapterList.add(map);
chapterIndex++;
}
return R.ok("当前为试听章节:" + chapterList).put("bookCatalogue", chapterList).put("image", bookEntity.getImages()).put("chapterIndex", chapterIndex);
}
}
List<BookChapterEntity> book = bookChapterService.getBaseMapper().selectList(new QueryWrapper<BookChapterEntity>()
.eq("book_id", bookid));
ArrayList<Object> chapterList = new ArrayList<>();
for (BookChapterEntity chapter : book) {
Map<String, Object> map = new HashMap<>();
map.put("name", chapter.getChapter());
map.put("url", chapter.getVoices());
chapterList.add(map);
}
return R.ok().put("bookCatalogue", chapterList).put("image", bookEntity.getImages());
}
/**
* 获取章节音频地址
@@ -495,147 +413,6 @@ public class BookChapterContentController {
return R.ok().put("chapter", chapter_info);
}
/**
* app 获取电子书章节内容 2.0 (在用鉴权)
*/
@RequestMapping("/appBooksChapterContent1")
public R getBooksCatalogue1(@RequestParam("chapterid") Integer id,
@RequestParam("bookid") Integer bookid,
@RequestParam("userId") Integer userId) {
// TODO 验证 当前请求的书 是否存在免费章节数
BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid);
Integer freeChapterCount = bookEntity.getFreeChapterCount();
BookChapterEntity bookChapterEntity = bookChapterService.getBaseMapper().selectById(id);
Integer number = bookChapterEntity.getNumber();
//TODO 0-免费 1-会免(改为电子书听书) 2-付费 // 阅读章节数 大于 免费章节数
Integer isVip = bookEntity.getIsVip();
Boolean canListen = bookEntity.getCanListen();
//todo 暂未开通听书功能
// if (canListen==false) {
// return R.error1("暂未开通听书功能");
// }
if ((number > freeChapterCount) || freeChapterCount == 0) {
// 书籍为 会免
if (isVip == 1) {
//查询用户身份
MyUserEntity user = myUserService.getById(userId);
String vip = user.getVip();
if (!"1".equals(vip)) {
return R.error("当前为VIP");
}
}
if (canListen == true) {
boolean b = myUserService.bookAuthenticate(bookid, userId);
if (!b) {
return R.error("未购买书籍!");
}
}
}
if (isVip == 2) {
// 鉴权 查询权限表中 用户是否开通
boolean b = myUserService.bookAuthenticate(bookid, userId);
if (!b) {
return R.error(500, "请购买书籍!").put("code", 500);
}
}
ArrayList<Object> chapterList = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("name", bookChapterEntity.getChapter());
map.put("url", bookChapterEntity.getVoices());
map.put("bookid", bookChapterEntity.getBookId());
map.put("chapterid", bookChapterEntity.getId());
//todo sort先注释调
// map.put("sort",bookChapterEntity.getSort());
chapterList.add(map);
return R.ok().put("bookCatalogue", chapterList).put("image", bookEntity.getImages());
}
/**
* app 获取电子书章节内容
*/
@RequestMapping("/appGetBookChapterContent")
public R getBookCatalogue(@RequestParam("chapterid") Integer chapterid,
@RequestParam("bookid") Integer bookid,
@RequestParam("userId") Integer userId) {
// TODO 验证 当前请求的书 是否存在免费章节数
BookEntity bookEntity = bookService.getBaseMapper().selectById(bookid);
Integer freeChapterCount = bookEntity.getFreeChapterCount();
Integer isVip = bookEntity.getIsVip(); // 0-免费 1-会免 2-付费
BookChapterEntity bookChapterEntity = bookChapterService.getBaseMapper().selectById(chapterid);
Integer number = bookChapterEntity.getNumber();
// 阅读章节数 大于 免费章节数
if ((number > freeChapterCount) || freeChapterCount == 0) {
if (isVip == 1) {
MyUserEntity user = myUserService.getById(userId);
String vip = user.getVip();
if (!"1".equals(vip)) {
return R.error(500, "当前书籍为会员书籍,请开通会员或购买!");
}
}
if (isVip == 2) {
boolean b = myUserService.bookAuthenticate(bookid, userId);
if (!b) {
return R.error(500, "请购买此书籍!");
}
}
}
ArrayList<Object> list = new ArrayList<>();
List<BookChapterContentEntity> bookChapterContentEntities = bookChapterContentService.getBaseMapper().selectList(new QueryWrapper<BookChapterContentEntity>()
.eq("book_id", bookid)
.eq("book_chatper_id", chapterid));
for (BookChapterContentEntity bookChapterContentEntity : bookChapterContentEntities) {
String content = bookChapterContentEntity.getContent();
String substring = "";
if (bookChapterContentEntity.getOtherContent() != null) {
substring = bookChapterContentEntity.getOtherContent().replace("<p>", "").replace("</p>", "");
}
StringBuffer stringBuffer = new StringBuffer(substring);
if (stringBuffer.indexOf("title") != -1) {
stringBuffer.insert(stringBuffer.indexOf("title"), "width=\"100%\"");
}
if (bookChapterContentEntity.getNumber() == 1) {
Integer bookChatperId = bookChapterContentEntity.getBookChatperId();
BookChapterEntity chapterEntity = bookChapterService.getById(bookChatperId);
String chapter = chapterEntity.getChapter();
content = bookChapterContentEntity.getContent().replace(chapter, "");
}
bookChapterContentEntity.setPicAndWord(content.replaceAll(" ", "") + stringBuffer);
list.add(bookChapterContentEntity);
}
return R.ok().put("bookCatalogue", list);
}
//生成电子书 目录
@RequestMapping("/getWordChapterParagraph")
public R getWordChapterParagraph(@RequestParam Map<String, Object> params) {

View File

@@ -3,7 +3,6 @@ import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -157,87 +156,6 @@ public class BookController {
return R.ok().put("book",book_info);
}
/**
* 信息
*/
@RequestMapping("/appinfo/{id}/{userId}")
// @RequiresPermissions("book:book:info")
public R appinfo(@PathVariable("id") Integer id,
@PathVariable("userId") Integer userId) {
BookEntity book = bookService.getById(id);
book.setIsBuy(true);
boolean b = myUserService.bookAuthen(id, userId);
if (!b) {
// 无权限
book.setIsBuy(false);
}
//书籍详情返回,购买状态,免费章节数
String authorName = "";
String publisherName = "";
String authorId = book.getAuthorId();
String[] authorIds = authorId.split(",");
List<String> authorList = Arrays.asList(authorIds);
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
for (AuthorEntity authorEntity : authorEntities) {
authorName += "," + authorEntity.getAuthorName();
}
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
String publisherId = book.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
//查询书籍阅读进度
BookReadRateEntity bookReadRateEntity = bookReadRateService.getBaseMapper().selectOne(new QueryWrapper<BookReadRateEntity>()
.eq("book_id", id)
.eq("user_id", userId)
);
if (bookReadRateEntity != null) {
Integer chapterId = bookReadRateEntity.getChapterId();
String chapterName = bookReadRateEntity.getChapterName();
book.setChapterName(chapterName);
book.setChapterId(chapterId);
// 查询 书籍 章节 number
BookChapterEntity bookChapterEntity = bookChapterService.getById(chapterId);
if (bookChapterEntity != null) {
Integer number = bookChapterEntity.getNumber();
book.setChapterNum(number);
}
}
//查询书籍是否加入书架
Integer integer = bookShelfService.getBaseMapper().selectCount(new QueryWrapper<BookShelfEntity>()
.eq("book_id", id)
.eq("user_id", userId));
boolean flag = false;
if (integer > 0) {
flag = true;
}
book.setAuthorName(authorName);
book.setPublisherName(publisherName);
book.setFlag(flag);
return R.ok().put("book", book);
}
/**
* 保存
*/

View File

@@ -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();
// }

View File

@@ -2,11 +2,8 @@ package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.BookForumArticlesEntity;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.common.entity.UserAppAuthorEntity;
import java.util.List;
import java.util.Map;
@@ -23,25 +20,10 @@ public interface MyUserService extends IService<MyUserEntity> {
PageUtils queryPage(Map<String, Object> params);
void sendCodeForRegister(String phone, String code,Integer areaCode) throws Exception;
//电子书鉴权
boolean bookAuthenticate(Integer bookId,Integer userId);
//电子书针对听书鉴权
boolean bookAuthen(Integer bookId,Integer userId);
List<BookForumArticlesEntity> getForumsLimit(Integer book_id, Integer limit);
//会员开通 电话 开通 期限
boolean openMember(Integer customerId,Integer openMonth);
//充值花生币
boolean rechargeHSPoint(MyUserEntity userEntity,Integer HSPoint);
//电子书购买
String buyEbook(String userId, String bookId,String couponId);
//第三方微信登录
R getUserInfoByApp(UserAppAuthorEntity userAppAuthorEntity);
boolean checkUserBook(Integer userId,Integer bookId);

View File

@@ -19,6 +19,7 @@ import com.peanut.modules.book.vo.UserOrderVo;
import com.peanut.modules.book.vo.request.BuyOrderListRequestVo;
import com.peanut.modules.book.vo.response.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.UserVipService;
import com.peanut.modules.common.vo.CourseCatalogueVo;
import com.peanut.modules.oss.service.OssService;
import lombok.extern.slf4j.Slf4j;
@@ -27,7 +28,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
@@ -45,28 +45,20 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
private BuyOrderDetailService buyOrderDetailService;
@Autowired
private MyUserService myUserService;
@Autowired
private ExpressFeeService expressFeeService;
@Autowired
private ExpressOrderService expressOrderService;
@Autowired
CountyService countyService;
@Autowired
ShopProductService shopProductService;
@Autowired
private UserRecordDao userRecordDao;
@Autowired
private BuyOrderDao buyOrderDao;
@Autowired
private BuyOrderProductService buyOrderProductService;
@Autowired
private ProvinceService provinceService;
@Autowired
@@ -91,6 +83,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
private PayZfbOrderService payZfbOrderService;
@Autowired
private BookBuyConfigDao bookBuyConfigDao;
@Autowired
private UserVipService userVipService;
protected Logger logger = LoggerFactory.getLogger(BuyOrderServiceImpl.class);
@@ -386,7 +380,10 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
Page<BuyOrder> buyOrderPage = getBaseMapper().selectPage(new Page<BuyOrder>(requestVo.getPageIndex(), requestVo.getPageSize()), wrapper);
//丰富订单内容
for (BuyOrder b : buyOrderPage.getRecords()){
b.setUser(myUserService.getById(b.getUserId()));
MyUserEntity user = myUserService.getById(b.getUserId());
user.setUserVips(userVipService.list(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId,user.getId()).eq(UserVip::getState,0)));
b.setUser(user);
//添加商品信息
List<BuyOrderProduct> buyOrderProducts = buyOrderProductDao.selectList(new LambdaQueryWrapper<BuyOrderProduct>().eq(BuyOrderProduct::getOrderId, b.getOrderId()));
for (BuyOrderProduct b1:buyOrderProducts){
@@ -419,34 +416,6 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
}
}
b.setConsigneeVo(consigneeVo);
//添加快递包裹信息
// LambdaQueryWrapper<BuyOrderProduct> b_wrapper = new LambdaQueryWrapper<>();
// b_wrapper.eq(BuyOrderProduct::getOrderId,b.getOrderId());
// b_wrapper.gt(BuyOrderProduct::getExpressOrderId,0);
// List<Integer> collect = buyOrderProductService.getBaseMapper().selectList(b_wrapper).stream().map(BuyOrderProduct::getExpressOrderId).collect(Collectors.toList());
// if(collect.size()>0){
// List<ExpressOrder> expressOrders = expressOrderService.getBaseMapper().selectList(new LambdaQueryWrapper<ExpressOrder>().in(ExpressOrder::getId, collect));
// for (ExpressOrder e : expressOrders){
// MPJLambdaWrapper<BuyOrderProduct> buyOrderProductMPJLambdaWrapper = new MPJLambdaWrapper<>();
// buyOrderProductMPJLambdaWrapper.selectAll(ShopProduct.class);
// buyOrderProductMPJLambdaWrapper.select(BuyOrderProduct::getQuantity);
// buyOrderProductMPJLambdaWrapper.select(BuyOrder::getOrderSn);
// buyOrderProductMPJLambdaWrapper.leftJoin(ShopProduct.class,ShopProduct::getProductId,BuyOrderProduct::getProductId);
// buyOrderProductMPJLambdaWrapper.leftJoin(BuyOrder.class,BuyOrder::getOrderId,BuyOrderProduct::getOrderId);
// buyOrderProductMPJLambdaWrapper.eq(BuyOrderProduct::getExpressOrderId,e.getId());
// List<ShopProduct> shopProducts = buyOrderProductDao.selectJoinList(ShopProduct.class, buyOrderProductMPJLambdaWrapper);
// for(ShopProduct s : shopProducts){
// MPJLambdaWrapper<ShopProductBookEntity> shopProductBookEntityMPJLambdaWrapper = new MPJLambdaWrapper<>();
// shopProductBookEntityMPJLambdaWrapper.selectAll(BookEntity.class);
// shopProductBookEntityMPJLambdaWrapper.leftJoin(BookEntity.class,BookEntity::getId,ShopProductBookEntity::getBookId);
// shopProductBookEntityMPJLambdaWrapper.eq(ShopProductBookEntity::getProductId,s.getProductId());
// List<BookEntity> bookEntities = shopProductBookDao.selectJoinList(BookEntity.class, shopProductBookEntityMPJLambdaWrapper);
// s.setBooks(bookEntities);
// }
// e.setProducts(shopProducts);
// }
// b.setExpressList(expressOrders);
// }
}
return buyOrderPage;
}

View File

@@ -1,7 +1,5 @@
package com.peanut.modules.book.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.domain.Member;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody;
@@ -9,29 +7,19 @@ import com.aliyun.tea.TeaException;
import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.Maps;
import com.peanut.common.utils.*;
import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.app.config.SMSConfig;
import com.peanut.modules.app.config.Sample;
import com.peanut.modules.book.service.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.mq.service.RabbitMqService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.MyUserDao;
@Slf4j
@@ -42,18 +30,8 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
@Autowired
private SMSConfig smsConfig;
@Autowired
private BookService bookService;
@Autowired
private RabbitMqService rabbitMqService;
@Autowired
private TransactionDetailsService transactionDetailsService;
@Autowired
private UserEbookBuyService userEbookBuyService;
@Autowired
private AuthorService authorService;
@Autowired
private MyUserDao myUserDao;
@Autowired
private BookForumArticlesService bookForumArticlesService;
@Override
@@ -72,79 +50,6 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
sendCode(phone,scode,areaCode);
}
@Override
public boolean bookAuthenticate(Integer bookId, Integer userId) {
// //查询书籍 类型
// BookEntity book = bookService.getById(bookId);
// Integer isVip = book.getIsVip(); // 0 - 免费 1- 会免 2 - 付费
// Boolean canListen = book.getCanListen();
// if (isVip == 1) {
// // 查询 用户是否为 vip 0 - 普通 1- 会员
// MyUserEntity myUserEntity = this.getBaseMapper().selectById(userId);
// String vip = myUserEntity.getVip();
// if (!"1".equals(vip)){
//
// // 判断普通用 是否解锁书籍
// TransactionDetailsEntity transactionDetailsEntity = transactionDetailsService.getBaseMapper().selectOne(new QueryWrapper<TransactionDetailsEntity>().eq("user_id", userId)
// .eq("relation_id", bookId));
//
// if (transactionDetailsEntity == null) {
// return false;
// }
//
// }
// }
// if (isVip == 2) {
//
//
// // TODO 查询 购买表中是否有用户购买记录
// TransactionDetailsEntity transactionDetailsEntity = transactionDetailsService.getBaseMapper().selectOne(new QueryWrapper<TransactionDetailsEntity>().eq("user_id", userId)
// .eq("relation_id", bookId));
//
// if (transactionDetailsEntity == null) {
// return false;
// }
//
// }
// //vip等于3为听书付费
// if (isVip == 3){
// UserEbookBuyEntity userid = userEbookBuyService.getBaseMapper().selectOne(new QueryWrapper<UserEbookBuyEntity>()
// .eq("user_id", userId)
// .eq("book_id",bookId));
//
// if (userid == null) {
// return false;
// }
//
// }
//
// if (canListen == true){
// UserEbookBuyEntity userid = userEbookBuyService.getBaseMapper().selectOne(new QueryWrapper<UserEbookBuyEntity>()
// .eq("user_id", userId)
// .eq("book_id",bookId));
//
// if (userid == null) {
// return false;
// }
//
// }
return true;
}
@Override
public boolean bookAuthen(Integer bookId, Integer userId) {
UserEbookBuyEntity userid = userEbookBuyService.getBaseMapper().selectOne(new QueryWrapper<UserEbookBuyEntity>()
.eq("user_id", userId)
.eq("book_id", bookId));
if (userid == null) {
return false;
}
return true;
}
@Override
public List<BookForumArticlesEntity> getForumsLimit(Integer book_id, Integer limit) {
LambdaQueryWrapper<BookForumArticlesEntity> wrapper = new LambdaQueryWrapper<>();
@@ -160,89 +65,6 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
return bookForumArticlesEntities;
}
@Override
public boolean openMember(Integer customerId,Integer openMonth) {
MyUserEntity user = this.getById(customerId);
if (user == null) {
return false;
}
long ttl = 0;
Date validDate = new Date();
Date date = new Date();
if (user.getVip().equals("1")) {
//如果当前已经是会员进行续期操作
validDate = user.getVipValidtime();
Calendar calendar = new GregorianCalendar();
calendar.setTime(validDate);
if (openMonth == 1){
Integer openDays = 31;
// 把日期往后增加一天,整数 往后推,负数往前移动
calendar.add(Calendar.DAY_OF_YEAR, openDays);
// 这个时间就是日期往后推一天的结果
Date endDate = calendar.getTime();
user.setVipValidtime(endDate);
ttl = endDate.getTime() - date.getTime() ;
}else {
//月份
calendar.add(Calendar.MONTH, openMonth);
Date endDate = calendar.getTime();
user.setVipValidtime(endDate);
ttl = endDate.getTime() - date.getTime() ;
}
}else {
//获取系统当前日期
user.setVip("1");
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
if (openMonth == 1){
Integer openDays = 31;
// 把日期往后增加一天,整数 往后推,负数往前移动
calendar.add(Calendar.DAY_OF_YEAR, openDays);
// 这个时间就是日期往后推一天的结果
Date endDate = calendar.getTime();
user.setVipValidtime(endDate);
ttl = endDate.getTime() - date.getTime() ;
}else {
//月份
calendar.add(Calendar.MONTH, openMonth);
Date endDate = calendar.getTime();
user.setVipValidtime(endDate);
ttl = endDate.getTime() - date.getTime() ;
}
}
user.setVipStartTime(date);
this.updateById(user);
//mq
// 手动指定消息过期时间
Map<String, Object> msgMap = Maps.newHashMapWithExpectedSize(3);
msgMap.put("msg", customerId);
msgMap.put("time", LocalDateTime.now());
msgMap.put("ttl", ttl);
// 注意这里发送的交换机是 延时交换机
rabbitMqService.send(DelayQueueConfig.DELAY_EXCHANGE, DelayQueueConfig.DELAY_QUEUE_ROUTING_KEY, JSONObject.toJSONString(msgMap), ttl);
log.info("消息发送成功:{}", JSONObject.toJSONString(msgMap));
return true;
}
@Override
public boolean rechargeHSPoint(MyUserEntity user,Integer HSPoint) {
if (user == null) {
@@ -254,120 +76,6 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
this.updateById(user);
return true;
}
@Override
public String buyEbook(String userId, String bookId,String couponId) {
String authorName = "";
//避免重复购买
TransactionDetailsEntity entity = transactionDetailsService.getBaseMapper().selectOne(new QueryWrapper<TransactionDetailsEntity>().eq("user_id", userId)
.eq("relation_id", bookId));
if (entity != null) {
return "余额不足,请充值!";
}
BigDecimal salePrice = new BigDecimal(0);
// 查询书籍 价格
BookEntity book = bookService.getById(Integer.valueOf(bookId));
// 是否为秒杀
Integer isSale = book.getIsSale();
if (isSale == 1) {
salePrice = book.getSalePrice();
}else {
salePrice = book.getPrice();
}
//查询用户
MyUserEntity user = this.getById(Integer.valueOf(userId));
Double peanutCoin = user.getPeanutCoin().doubleValue() - salePrice.doubleValue();
if (peanutCoin < 0) {
return "当前书籍已购买,请勿重复购买!";
}
user.setPeanutCoin(new BigDecimal(peanutCoin));
this.updateById(user);
TransactionDetailsEntity detailsEntity = new TransactionDetailsEntity();
detailsEntity.setUserId(Integer.valueOf(userId));
detailsEntity.setChangeAmount(salePrice.negate());
detailsEntity.setUserBalance(user.getPeanutCoin());
detailsEntity.setRemark("购买:"+book.getName());
detailsEntity.setOrderType("购买电子书");
detailsEntity.setRelationId(Integer.valueOf(bookId));
detailsEntity.setUserName(user.getNickname());
detailsEntity.setTel(user.getTel());
transactionDetailsService.save(detailsEntity);
// 插入购买记录
UserEbookBuyEntity userEbookBuyEntity = new UserEbookBuyEntity();
userEbookBuyEntity.setUserId(Integer.valueOf(userId));
userEbookBuyEntity.setBookId(Integer.valueOf(bookId));
userEbookBuyEntity.setBookName(book.getName());
String authorId = book.getAuthorId();
String[] authorIds = authorId.split(",");
List<String> authorList = Arrays.asList(authorIds);
List<AuthorEntity> authorEntities = authorService.getBaseMapper().selectList(new QueryWrapper<AuthorEntity>().in("id", authorList));
for (AuthorEntity authorEntity : authorEntities) {
authorName += "," + authorEntity.getAuthorName();
}
authorName = authorName.startsWith(",") ? authorName.substring(1) : authorName;
userEbookBuyEntity.setAuthor(authorName);
userEbookBuyEntity.setImage(book.getImages());
userEbookBuyEntity.setPayStatus("支付成功");
userEbookBuyEntity.setPayType("point");
userEbookBuyEntity.setPayTime(new Date());
userEbookBuyService.save(userEbookBuyEntity);
return "购买成功!";
}
/**
* 微信授权登录
*
* @param userAppAuthorEntity
*/
@Override
public R getUserInfoByApp(UserAppAuthorEntity userAppAuthorEntity) {
// todo CommConfig WeiXinParam 表未建
try {
Member member = new Member();
BeanUtils.copyProperties(userAppAuthorEntity, member);
CommConfig commConfig = new CommConfig();
//调用微信授权
// WeixinLoginUtils appWeiXinUserInfo1 = weixinLoginUtils1.getAppWeiXinUserInfo(commConfig.);
WeixinLoginUtils weixinLoginUtils = new WeixinLoginUtils();
StringBuilder stringBuilder = weixinLoginUtils.getAccessTokenBycode(commConfig.getUserAppID(), commConfig.getUserAppSecret(), userAppAuthorEntity.getCode());
if (stringBuilder != null) {
if (stringBuilder.toString().trim().contains("errcode")) {
return R.error();
}
JSONObject object = JSONObject.parseObject(stringBuilder.toString().trim());
String accessToken = object.getString("access_token"); //接口调用凭证
String openID = object.getString("openid"); //授权用户唯一标识
//获取微信用户基本信息
WeiXinParam appWeiXinUserInfo = weixinLoginUtils.getAppWeiXinUserInfo(accessToken, openID, WeiXinParam.class);
// TODO 业务逻辑
return R.ok().put("member",member);
}
} catch (Exception e) {
e.printStackTrace();
}
return R.ok("sec");
}
@Override
public boolean checkUserBook(Integer userId, Integer bookId) {

View File

@@ -1,46 +1,13 @@
package com.peanut.modules.book.task;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.book.service.MyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Component
@EnableScheduling
//@Async
public class SysTask {
@Autowired
private MyUserService userService;
//
@Scheduled(cron = "0 0 2 ? * * ")
public void run() throws InterruptedException {
List<MyUserEntity> users = userService.getBaseMapper().selectList(new QueryWrapper<>());
for (MyUserEntity user : users) {
Date vipValidtime = user.getVipValidtime();
Date date = new Date();
long times = date.getTime() - vipValidtime.getTime();
if (times <= 0) {
String vip = user.getVip();
if (vip.equals("1")) {
user.setVip("0");
userService.save(user);
}
}
}
// System.out.println(Thread.currentThread().getName()+"=====>>>>>使用cron {}"+(System.currentTimeMillis()/1000));
}
}

View File

@@ -6,11 +6,9 @@ import com.peanut.common.utils.MD5Utils;
import com.peanut.common.utils.MailUtil;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.common.entity.ClassUser;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.common.entity.UserInviteRegister;
import com.peanut.modules.common.entity.UserVip;
import com.peanut.modules.common.service.ClassEntityService;
import com.peanut.modules.common.service.MyUserService;
import com.peanut.modules.common.service.UserInviteRegisterService;
import com.peanut.modules.common.service.UserVipService;
@@ -23,7 +21,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.Random;
@@ -117,13 +114,10 @@ public class UserController {
public R getUserInfo(){
int uid = ShiroUtils.getUId();
MyUserEntity userEntity = userService.getById(uid);
if(!userEntity.getVip().equals("0")){
List<UserVip> userVips = userVipService.getBaseMapper().selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId, uid).eq(UserVip::getState,0));
if (userVips.size()==1){
userEntity.setUserVip(userVips.get(0));
}
}
List<UserVip> userVips = userVipService.list(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId, uid)
.eq(UserVip::getState,0));
userEntity.setUserVips(userVips);
return R.ok().put("result",userEntity);
}

View File

@@ -2,18 +2,17 @@ package com.peanut.modules.common.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.config.Constants;
import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.book.service.TransactionDetailsService;
import com.peanut.modules.common.dao.MyUserDao;
import com.peanut.modules.common.dao.UserVipDao;
import com.peanut.modules.common.dao.VipBuyConfigDao;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.BuyOrderService;
import com.peanut.modules.common.service.JfTransactionDetailsService;
import com.peanut.modules.common.service.UserVipService;
import com.peanut.modules.common.service.*;
import com.peanut.modules.master.service.CourseCatalogueService;
import com.peanut.modules.master.service.CourseService;
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
import com.peanut.modules.pay.weChatPay.service.WxpayService;
import lombok.extern.slf4j.Slf4j;
@@ -25,11 +24,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.Period;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* 超V管理
@@ -50,13 +46,200 @@ public class UserVipController {
@Autowired
private MyUserDao myUserDao;
@Autowired
private VipBuyConfigDao vipBuyConfigDao;
@Autowired
private UserVipDao userVipDao;
private VipBuyConfigService vipBuyConfigService;
@Autowired
private TransactionDetailsService transactionDetailsService;
@Autowired
private JfTransactionDetailsService jfTransactionDetailsService;
@Autowired
private CourseService courseService;
@Autowired
private CourseCatalogueService courseCatalogueService;
//获取用户类型
@RequestMapping("/getUserVipType")
public R getUserVipType() {
List<Map<String,Object>> resList = new ArrayList();
List<UserVip> l4 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,4).orderByDesc(UserVip::getEndTime));
List<UserVip> l5 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,5).orderByDesc(UserVip::getEndTime));
List<UserVip> l6 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,6).orderByDesc(UserVip::getEndTime));
if (l4.size()>0&&l5.size()>0&&l6.size()>0&&l4.get(0).getState()==0&&l5.get(0).getState()==0&&l6.get(0).getState()==0){
Date t4 = l4.get(0).getEndTime();
Date t5 = l5.get(0).getEndTime();
Date t6 = l6.get(0).getEndTime();
Map map = new HashMap();
map.put("type",1);
map.put("endTime",t4.getTime()<t5.getTime()?(t4.getTime()<t6.getTime()?t4:(t5.getTime()<t6.getTime()?t5:t6)):(t5.getTime()<t6.getTime()?t5:t6));
resList.add(map);
}else {
if (l4.size()>0){
Map map = new HashMap();
map.put("type",4);
map.put("endTime",l4.get(0).getEndTime());
resList.add(map);
}
if (l5.size()>0){
Map map = new HashMap();
map.put("type",5);
map.put("endTime",l5.get(0).getEndTime());
resList.add(map);
}
if (l6.size()>0){
Map map = new HashMap();
map.put("type",6);
map.put("endTime",l6.get(0).getEndTime());
resList.add(map);
}
}
List<UserVip> l7 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,7).orderByDesc(UserVip::getEndTime));
List<UserVip> l8 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,8).orderByDesc(UserVip::getEndTime));
if (l7.size()>0&&l8.size()>0&&l7.get(0).getState()==0&&l8.get(0).getState()==0){
Date t7 = l7.get(0).getEndTime();
Date t8 = l8.get(0).getEndTime();
Map map = new HashMap();
map.put("type",2);
map.put("endTime",t7.getTime()<t8.getTime()?t7:t8);
resList.add(map);
}else {
if (l7.size()>0){
Map map = new HashMap();
map.put("type",7);
map.put("endTime",l7.get(0).getEndTime());
resList.add(map);
}
if (l8.size()>0){
Map map = new HashMap();
map.put("type",8);
map.put("endTime",l8.get(0).getEndTime());
resList.add(map);
}
}
resList = resList.stream().sorted((map1,map2)->{
return Long.compare(((Date)map2.get("endTime")).getTime(),((Date)map1.get("endTime")).getTime());
}).collect(Collectors.toList());
return R.ok().put("list", resList);
}
//vip商品列表
@RequestMapping("/getVipBuyConfigList")
public R getVipBuyConfigList() {
List<List> ll = new ArrayList<>();
ll.add(Arrays.asList(1));
ll.add(Arrays.asList(4,5,6));
ll.add(Arrays.asList(2));
ll.add(Arrays.asList(7,8));
List<Map<String,Object>> resList = new ArrayList<>();
for (List l : ll) {
LambdaQueryWrapper<VipBuyConfigEntity> wrapper = new LambdaQueryWrapper();
wrapper.select(VipBuyConfigEntity::getType,VipBuyConfigEntity::getTitle);
wrapper.and(r->r.eq(VipBuyConfigEntity::getDateType,0).or(f->f.eq(VipBuyConfigEntity::getDateType,1).lt(VipBuyConfigEntity::getStartTime,new Date()).gt(VipBuyConfigEntity::getEndTime,new Date())));
wrapper.in(VipBuyConfigEntity::getType,l);
wrapper.groupBy(VipBuyConfigEntity::getType);
List<Map<String,Object>> list = vipBuyConfigService.listMaps(wrapper);
for (Map<String,Object> map:list){
Map originalPriceAndCourseCount = getOriginalPriceAndCourseCount(map.get("type").toString());
map.put("originalPrice",originalPriceAndCourseCount.get("originalPrice"));//模块下课程一年原价
map.put("courseCount",originalPriceAndCourseCount.get("courseCount"));//模块下课程数量
map.put("tip",null);//提示到期
map.put("vcbList",null);//vip商品列表
map.put("yanqiList",null);//延期商品列表
map.put("state",null);//有效状态
boolean flag = false;
if ("1".equals(map.get("type").toString())){
List<UserVip> uv4 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,4).orderByDesc(UserVip::getEndTime));
List<UserVip> uv5 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,5).orderByDesc(UserVip::getEndTime));
List<UserVip> uv6 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,6).orderByDesc(UserVip::getEndTime));
if (uv4.size() > 0 && uv5.size() > 0 && uv6.size() > 0){//办理过
if (uv4.get(0).getState()==0&&uv5.get(0).getState()==0&&uv6.get(0).getState()==0){
long l4 = uv4.get(0).getEndTime().getTime();
long l5 = uv5.get(0).getEndTime().getTime();
long l6 = uv6.get(0).getEndTime().getTime();
if (l4<l5){
if (l4<l6){
map.put("tip",(l4-new Date().getTime())/60/60/24/1000);
}else {
map.put("tip",(l6-new Date().getTime())/60/60/24/1000);
}
}else {
if (l5<l6){
map.put("tip",(l5-new Date().getTime())/60/60/24/1000);
}else {
map.put("tip",(l6-new Date().getTime())/60/60/24/1000);
}
}
map.put("state",0);
}else {
map.put("state",1);
}
flag = true;
}
}else if ("2".equals(map.get("type").toString())){
List<UserVip> uv7 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,7).orderByDesc(UserVip::getEndTime));
List<UserVip> uv8 = userVipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,8).orderByDesc(UserVip::getEndTime));
if (uv7.size() > 0 && uv8.size() > 0){
if (uv7.get(0).getState()==0&&uv8.get(0).getState()==0){
if (uv7.get(0).getEndTime().getTime()<uv8.get(0).getEndTime().getTime()){
map.put("tip",(uv7.get(0).getEndTime().getTime()-new Date().getTime())/60/60/24/1000);
}else {
map.put("tip",(uv8.get(0).getEndTime().getTime()-new Date().getTime())/60/60/24/1000);
}
map.put("state",0);
}else {
map.put("state",1);
}
flag = true;
}
}else {
List<UserVip> userVips = userVipService.list(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId,ShiroUtils.getUId()).eq(UserVip::getType,map.get("type")).orderByDesc(UserVip::getEndTime));
if (userVips.size()>0){
if (userVips.get(0).getState()==0){
map.put("tip",(userVips.get(0).getEndTime().getTime()-new Date().getTime())/60/60/24/1000);
map.put("state",0);
}else {
map.put("state",1);
}
flag = true;
}
}
if (flag){
List<VipBuyConfigEntity> yanqiList = vipBuyConfigService.list(new LambdaQueryWrapper<VipBuyConfigEntity>()
.and(r->r.eq(VipBuyConfigEntity::getDateType,0).or(f->f.eq(VipBuyConfigEntity::getDateType,1).lt(VipBuyConfigEntity::getStartTime,new Date()).gt(VipBuyConfigEntity::getEndTime,new Date())))
.eq(VipBuyConfigEntity::getType,map.get("type")+"1"));
map.put("yanqiList",yanqiList);
}else {
List<VipBuyConfigEntity> vcbList = vipBuyConfigService.list(new LambdaQueryWrapper<VipBuyConfigEntity>()
.and(r->r.eq(VipBuyConfigEntity::getDateType,0).or(f->f.eq(VipBuyConfigEntity::getDateType,1).lt(VipBuyConfigEntity::getStartTime,new Date()).gt(VipBuyConfigEntity::getEndTime,new Date())))
.eq(VipBuyConfigEntity::getType,map.get("type")));
map.put("vcbList",vcbList);
}
}
list = list.stream().sorted((map1,map2)->{
return Long.compare((Long) (map1.get("tip")==null?0l:map1.get("tip")),(Long)(map2.get("tip")==null?0l:map2.get("tip")));
}).collect(Collectors.toList());
list = list.stream().sorted((map1,map2)->{
return (map1.get("vcbList")==null?0:(int)map1.get("type"))>(map2.get("vcbList")==null?0:(int)map2.get("type"))?
1:((map1.get("vcbList")==null?0:(int)map1.get("type"))==(map2.get("vcbList")==null?0:(int)map2.get("type"))?0:-1);
}).collect(Collectors.toList());
resList.addAll(list);
}
return R.ok().put("res", resList);
}
//是否是这门课的vip
@RequestMapping("/ownCourseCatalogueByVip")
public R ownCourseCatalogueByVip(@RequestBody Map<String,Object> params) {
UserVip userVip = userVipService.ownCourseCatalogueByVip(Integer.parseInt(params.get("courseId").toString()));
return R.ok().put("userVip", userVip);
}
//当前课程属于什么会员
@RequestMapping("/getCourseVipModule")
public R getCourseVipModule(@RequestBody Map<String,Object> params) {
return R.ok().put("list", userVipService.getCourseVipModule(Integer.parseInt(params.get("courseId").toString())));
}
@RequestMapping("/getMyVipHistory")
public R getMyVipHistory(String userId) {
@@ -70,9 +253,8 @@ public class UserVipController {
@RequestMapping("/placeVipOrder")
@Transactional
public R placeVipOrder(@RequestBody BuyOrder buyOrder) throws Exception {
public R placeVipOrder(@RequestBody BuyOrder buyOrder){
int uid = ShiroUtils.getUId();
buyOrder.setOrderStatus("0");
buyOrder.setOrderType("vip");
String timeId = IdWorker.getTimeId().substring(0, 32);
@@ -94,9 +276,15 @@ public class UserVipController {
if(buyOrder.getJfDeduction()!=null&&buyOrder.getJfDeduction().compareTo(BigDecimal.ZERO) > 0){
jfTransactionDetailsService.recordJfTransaction(buyOrder, user, buyOrder.getJfDeduction());
}
//开通用户vip,并且对已开通的课程做延期
openVipForUser(buyOrder);
//开通用户vip
userVipService.openVipForUser(buyOrder);
} else {
rabbitTemplate.convertAndSend(
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
buyOrder.getOrderId(),
messagePostProcessor()
);
return R.error(500, "余额不足!");
}
}
@@ -138,92 +326,6 @@ public class UserVipController {
return false;
}
private void openVipForUser(BuyOrder buyOrder) throws Exception {
VipBuyConfigEntity vipBuyConfigEntity = vipBuyConfigDao.selectById(buyOrder.getVipBuyConfigId());
MyUserEntity userEntity = myUserDao.selectById(buyOrder.getUserId());
String u_v_type = userEntity.getVip();
if(vipBuyConfigEntity.getType()==1){//超v
if(u_v_type.equals("0")){//初次办理
UserVip userVip = new UserVip();
userVip.setUserId(userEntity.getId());
userVip.setType(1);
userVip.setStartTime(new Date());
LocalDate today = LocalDate.now();
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
userVip.setEndTime(threeYearsDate);
userVipDao.insert(userVip);
userEntity.setVip("1");
myUserDao.updateById(userEntity);
}else if(u_v_type.equals("1")){//vip延期
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
throwExceptionMethod();
}
UserVip userVip = userVips.get(0);
Date endTime = userVip.getEndTime();
Calendar calendar = Calendar.getInstance();
calendar.setTime(endTime);
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
userVip.setEndTime(calendar.getTime());
userVipDao.updateById(userVip);
}else if (u_v_type.equals("2")||u_v_type.equals("3")){//医学vip或国学vip升级
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
throwExceptionMethod();
}
UserVip userVip1 = userVips.get(0);
userVip1.setEndTime(new Date());
userVip1.setState(1);
userVipDao.updateById(userVip1);
UserVip userVip = new UserVip();
userVip.setUserId(userEntity.getId());
userVip.setType(1);
userVip.setStartTime(new Date());
LocalDate today = LocalDate.now();
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
userVip.setEndTime(threeYearsDate);
userVipDao.insert(userVip);
userEntity.setVip("1");
myUserDao.updateById(userEntity);
}
}
if(vipBuyConfigEntity.getType()==2||vipBuyConfigEntity.getType()==3){//医学vip或国学vip
if(userEntity.getVip().equals("2")||userEntity.getVip().equals("3")){//续费
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
throwExceptionMethod();
}
UserVip userVip = userVips.get(0);
Date endTime = userVip.getEndTime();
Calendar calendar = Calendar.getInstance();
calendar.setTime(endTime);
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
userVip.setEndTime(calendar.getTime());
userVipDao.updateById(userVip);
}else{//新办理
UserVip userVip = new UserVip();
userVip.setUserId(userEntity.getId());
userVip.setType(vipBuyConfigEntity.getType());
userVip.setStartTime(new Date());
LocalDate today = LocalDate.now();
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
userVip.setEndTime(threeYearsDate);
userVipDao.insert(userVip);
userEntity.setVip(vipBuyConfigEntity.getType().toString());
myUserDao.updateById(userEntity);
}
}
}
private static void throwExceptionMethod() throws Exception {
throw new Exception("开通vip异常");
}
private boolean useJfCoin(MyUserEntity user,BigDecimal jf){
if(jf==null){
return true;
@@ -245,4 +347,64 @@ public class UserVipController {
};
}
public Map getOriginalPriceAndCourseCount(String type) {
Map map = new HashMap();
map.put("courseCount",0);
map.put("originalPrice",0);
if ("4".equals(type)||"5".equals(type)||"6".equals(type)){
List list = new ArrayList<>();
if ("4".equals(type)){
userVipService.bottomLabel(1,list);
}else if ("5".equals(type)){
userVipService.bottomLabel(2,list);
}else if ("6".equals(type)){
userVipService.bottomLabel(5,list);
}
MPJLambdaWrapper<CourseCatalogueEntity> wrapper = new MPJLambdaWrapper();
wrapper.inSql(CourseCatalogueEntity::getCourseId,
"select course_id from course_to_medicine where del_flag = 0 and medical_id in ("+String.join(",",list.toString().replace("[","").replace("]",""))+") group by course_id");
wrapper.select("count(1) as courseCount,sum(fee) as originalPrice");
map = courseCatalogueService.getMap(wrapper);
}else if ("7".equals(type)){
MPJLambdaWrapper<CourseCatalogueEntity> wrapper = new MPJLambdaWrapper();
wrapper.inSql(CourseCatalogueEntity::getCourseId,
"select course_id from course_to_sociology where del_flag = 0 group by course_id");
wrapper.select("count(1) as courseCount,sum(fee) as originalPrice");
map = courseCatalogueService.getMap(wrapper);
}else if ("8".equals(type)){
List list = new ArrayList<>();
userVipService.bottomLabel(4,list);
MPJLambdaWrapper<CourseCatalogueEntity> wrapper = new MPJLambdaWrapper();
wrapper.inSql(CourseCatalogueEntity::getCourseId,
"select course_id from course_to_medicine where del_flag = 0 and medical_id in ("+String.join(",",list.toString().replace("[","").replace("]",""))+") group by course_id");
wrapper.select("count(1) as courseCount,sum(fee) as originalPrice");
map = courseCatalogueService.getMap(wrapper);
if ("0".equals(map.get("courseCount").toString())){
MPJLambdaWrapper<CourseCatalogueEntity> pWrapper = new MPJLambdaWrapper();
pWrapper.inSql(CourseCatalogueEntity::getCourseId,
"select course_id from course_to_psyche where del_flag = 0 group by course_id");
pWrapper.select("count(1) as courseCount,sum(fee) as originalPrice");
map = courseCatalogueService.getMap(pWrapper);
}
}else if ("2".equals(type)){
MPJLambdaWrapper<CourseCatalogueEntity> wrapper = new MPJLambdaWrapper();
wrapper.inSql(CourseCatalogueEntity::getCourseId,
"select course_id from course_to_sociology where del_flag = 0 group by course_id\n" +
"union \n" +
"select course_id from course_to_psyche where del_flag = 0 group by course_id");
wrapper.select("count(1) as courseCount,sum(fee) as originalPrice");
map = courseCatalogueService.getMap(wrapper);
}else if ("1".equals(type)){
MPJLambdaWrapper<CourseCatalogueEntity> wrapper = new MPJLambdaWrapper();
wrapper.inSql(CourseCatalogueEntity::getCourseId,
"select course_id from course_to_medicine where del_flag = 0 group by course_id\n" +
"union \n" +
"select course_id from course_to_sociology where del_flag = 0 group by course_id\n" +
"union \n" +
"select course_id from course_to_psyche where del_flag = 0 group by course_id");
wrapper.select("count(1) as courseCount,sum(fee) as originalPrice");
map = courseCatalogueService.getMap(wrapper);
}
return map;
}
}

View File

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import lombok.Data;
/**
@@ -153,6 +155,6 @@ public class MyUserEntity implements Serializable {
private String remark;
@TableField(exist = false)
private UserVip userVip;
private List<UserVip> userVips;
}

View File

@@ -25,7 +25,7 @@ public class UserVip implements Serializable {
*/
private Integer userId;
/**
* 1超v2简易超v
* 4中医学5针灸学6肿瘤学7国学8心理学
*/
private Integer type;
/**

View File

@@ -16,7 +16,7 @@ public class VipBuyConfigEntity {
private Integer id;
/**
* 1超级vip2医学vip3国学vip
* 1医学超级 11延期医学超级 2国学心理学超级 21延期国心超级 4中医学41延期中医学 5、51针灸学 6、61肿瘤学 7、71国学 8、81心理学
*/
private Integer type;
@@ -28,6 +28,10 @@ public class VipBuyConfigEntity {
private BigDecimal rebateFee;
private String icon;
private String content;
private Integer dateType;
private Date startTime;

View File

@@ -1,7 +1,27 @@
package com.peanut.modules.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BuyOrder;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.common.entity.UserVip;
import java.util.List;
import java.util.Set;
public interface UserVipService extends IService<UserVip> {
boolean noMedicalVip();
boolean isMedicalVip();
boolean isAcupunctureVip();
boolean istumorVip();
boolean isSociologyVip();
boolean isPsycheVip();
//是否是这门课的vip
UserVip ownCourseCatalogueByVip(int courseId);
Set getCourseVipModule(int catalogueId);
UserVip ownCourseCatalogueByVip(MyUserEntity u, int catalogueId);
void bottomLabel(int labelId, List list);
void openVipForUser(BuyOrder buyOrder);
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.VipBuyConfigEntity;
public interface VipBuyConfigService extends IService<VipBuyConfigEntity> {
}

View File

@@ -3,7 +3,6 @@ package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
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.ExpressOrderUtil;
@@ -17,7 +16,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -49,7 +47,6 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
MyUserEntity userEntity = userDao.selectById(prepareOrderDto.getUid());
UserBaseVo userBaseVo = new UserBaseVo();
userBaseVo.setId(userEntity.getId());
userBaseVo.setVip(Integer.valueOf(userEntity.getVip()));
userBaseVo.setPeanutCoin(userEntity.getPeanutCoin());
userBaseVo.setJf(userEntity.getJf());
flag.put("user",userBaseVo);

View File

@@ -12,6 +12,7 @@ import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.ClassEntityService;
import com.peanut.modules.common.service.UserVipService;
import com.peanut.modules.sys.dao.SysUserDao;
import com.peanut.modules.sys.entity.SysUserEntity;
import lombok.extern.slf4j.Slf4j;
@@ -62,6 +63,8 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
private UserCertificateDao userCertificateDao;
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private UserVipService userVipService;
@Override
public Page getClassModelList(Map<String, Object> params) {
@@ -304,12 +307,13 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
if (userList.size() > 0) {
for (ClassUser classUser:userList){
MyUserEntity user = myUserDao.selectById(classUser.getUserId());
if ("0".equals(user.getVip())||"3".equals(user.getVip())){
//不是vip查询每门课是否购买
boolean flag = false;
List<ClassCourse> courses = classCourseDao.selectList(new LambdaQueryWrapper<ClassCourse>()
.eq(ClassCourse::getModelId,classEntity.getModelId()));
for (ClassCourse classCourse:courses){
boolean flag = false;
List<ClassCourse> courses = classCourseDao.selectList(new LambdaQueryWrapper<ClassCourse>()
.eq(ClassCourse::getModelId,classEntity.getModelId()));
for (ClassCourse classCourse:courses){
UserVip userVip = userVipService.ownCourseCatalogueByVip(user,classCourse.getCourseId());
if (userVip==null){
//不是vip查询每门课是否购买
List<CourseCatalogueEntity> catalogues = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>()
.eq(CourseCatalogueEntity::getCourseId,classCourse.getCourseId()));
for (CourseCatalogueEntity catalog:catalogues){
@@ -325,9 +329,9 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
}
}
}
if (flag) {
return R.error(sb.toString());
}
}
if (flag) {
return R.error(sb.toString());
}
}
}
@@ -576,11 +580,12 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
Map<String, Object> map = new HashMap<>();
map.put("student",user);
StringBuilder sb = new StringBuilder();
if ("1".equals(user.getVip())||"2".equals(user.getVip())){
sb.append("会员 ");
}else {
if (courses.size() > 0){
for (CourseEntity course : courses) {
if (courses.size() > 0){
for (CourseEntity course : courses) {
UserVip userVip = userVipService.ownCourseCatalogueByVip(user,course.getId());
if (userVip != null) {
sb.append("会员 ");
}else {
List<CourseCatalogueEntity> catalogues = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>()
.eq(CourseCatalogueEntity::getCourseId,course.getId()));
for (CourseCatalogueEntity catalog:catalogues){
@@ -700,11 +705,12 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
ClassEntity classEntity = this.baseMapper.selectById(params.get("classId").toString());
MyUserEntity user = ShiroUtils.getUser();
String msg = "";
if ("0".equals(user.getVip())||"3".equals(user.getVip())){
//不是vip查询每门课是否购买
List<ClassCourse> courses = classCourseDao.selectList(new LambdaQueryWrapper<ClassCourse>()
.eq(ClassCourse::getModelId,classEntity.getModelId()));
for (ClassCourse classCourse:courses){
List<ClassCourse> courses = classCourseDao.selectList(new LambdaQueryWrapper<ClassCourse>()
.eq(ClassCourse::getModelId,classEntity.getModelId()));
for (ClassCourse classCourse:courses){
UserVip userVip = userVipService.ownCourseCatalogueByVip(classCourse.getCourseId());
if (userVip == null) {
//不是vip查询每门课是否购买
List<CourseCatalogueEntity> catalogues = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>()
.eq(CourseCatalogueEntity::getCourseId,classCourse.getCourseId()));
for (CourseCatalogueEntity catalog:catalogues){

View File

@@ -1,13 +1,307 @@
package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.UserVipDao;
import com.peanut.modules.common.entity.UserVip;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.UserVipService;
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.*;
@Slf4j
@Service("commonUserVipService")
public class UserVipServiceImpl extends ServiceImpl<UserVipDao, UserVip> implements UserVipService {
@Autowired
private UserVipDao userVipDao;
@Autowired
private CourseMedicineDao courseMedicineDao;
@Autowired
private CourseToMedicineDao courseToMedicalDao;
@Autowired
private CourseToSociologyDao courseToSociologyDao;
@Autowired
private CourseToPsycheDao courseToPsycheDao;
@Autowired
private VipBuyConfigDao vipBuyConfigDao;
@Override
public boolean noMedicalVip() {
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId, ShiroUtils.getUId())
.eq(UserVip::getState,0)
.in(UserVip::getType,4,5,6));
if (userVipList.size() > 0) {
return false;
}else {
return true;
}
}
@Override
public boolean isMedicalVip() {
return isVip(4);
}
@Override
public boolean isAcupunctureVip() {
return isVip(5);
}
@Override
public boolean istumorVip() {
return isVip(6);
}
@Override
public boolean isSociologyVip() {
return isVip(7);
}
@Override
public boolean isPsycheVip() {
return isVip(8);
}
public boolean isVip(int type) {
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId, ShiroUtils.getUId())
.eq(UserVip::getState,0)
.eq(UserVip::getType,type));
if (userVipList.size() > 0) {
return true;
}else {
return false;
}
}
public UserVip ownCourseCatalogueByVip(MyUserEntity u,int courseId) {
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId, u==null?ShiroUtils.getUId():u.getId())
.eq(UserVip::getState,0));
for (UserVip userVip : userVipList) {
if (userVip.getType()==4||userVip.getType()==5||userVip.getType()==6) {
List<CourseToMedicine> list = courseToMedicalDao.selectList(new LambdaQueryWrapper<CourseToMedicine>()
.eq(CourseToMedicine::getCourseId,courseId));
for (CourseToMedicine ctm:list) {
CourseMedicine cm = topLabel(ctm.getMedicalId());
if (cm != null){
if ((cm.getId()==1&&userVip.getType()==4)||//中医学
(cm.getId()==2&&userVip.getType()==5)||//针灸学
(cm.getId()==5&&userVip.getType()==6)){//肿瘤学
return userVip;
}
}
}
}else if (userVip.getType()==7){//国学
List<CourseToSociologyEntity> list = courseToSociologyDao.selectList(new LambdaQueryWrapper<CourseToSociologyEntity>()
.eq(CourseToSociologyEntity::getCourseId,courseId));
if (list.size() > 0) {
return userVip;
}
}else if (userVip.getType()==8){//心理学
List<CourseToPsyche> list = courseToPsycheDao.selectList(new LambdaQueryWrapper<CourseToPsyche>()
.eq(CourseToPsyche::getCourseId,courseId));
if (list.size() > 0) {
return userVip;
}else {
List<CourseToMedicine> l2 = courseToMedicalDao.selectList(new LambdaQueryWrapper<CourseToMedicine>()
.eq(CourseToMedicine::getCourseId,courseId));
for (CourseToMedicine ctm:l2) {
CourseMedicine cm = topLabel(ctm.getMedicalId());
if (cm != null){
if ((cm.getId()==4&&userVip.getType()==8)){//心理学
return userVip;
}
}
}
}
}
}
return null;
}
@Override
public UserVip ownCourseCatalogueByVip(int courseId) {
return ownCourseCatalogueByVip(null,courseId);
}
@Override
public Set getCourseVipModule(int courseId) {
Set set = new HashSet();
List<CourseToMedicine> mlist = courseToMedicalDao.selectList(new LambdaQueryWrapper<CourseToMedicine>()
.eq(CourseToMedicine::getCourseId,courseId));
for (CourseToMedicine ctm:mlist) {
CourseMedicine cm = topLabel(ctm.getMedicalId());
if (cm.getId()==1){//中医学
set.add(4);
}else if (cm.getId() == 2) {//针灸学
set.add(5);
}else if (cm.getId() == 5) {//肿瘤学
set.add(6);
}else if (cm.getId() == 4) {//心身医学
set.add(8);
}
}
List<CourseToSociologyEntity> slist = courseToSociologyDao.selectList(new LambdaQueryWrapper<CourseToSociologyEntity>()
.eq(CourseToSociologyEntity::getCourseId,courseId));
if (slist.size()>0){
set.add(7);
}
List<CourseToPsyche> plist = courseToPsycheDao.selectList(new LambdaQueryWrapper<CourseToPsyche>()
.eq(CourseToPsyche::getCourseId,courseId));
if (plist.size()>0){
set.add(8);
}
return set;
}
public CourseMedicine topLabel(int labelId) {
CourseMedicine cm = courseMedicineDao.selectById(labelId);
if (cm != null) {
CourseMedicine pcm = courseMedicineDao.selectById(cm.getPid());
if (pcm != null) {
if (pcm.getPid()==0){
return pcm;
}else {
return topLabel(pcm.getId());
}
}
}
return null;
}
@Override
public void bottomLabel(int labelId,List list) {
CourseMedicine cm = courseMedicineDao.selectById(labelId);
if (cm != null) {
if (cm.getIsLast()==1){
list.add(cm.getId());
}else {
List<CourseMedicine> cms = courseMedicineDao.selectList(new LambdaQueryWrapper<CourseMedicine>()
.eq(CourseMedicine::getPid,cm.getId()));
for (CourseMedicine ccm:cms){
bottomLabel(ccm.getId(),list);
}
}
}
}
@Override
public void openVipForUser(BuyOrder buyOrder) {
VipBuyConfigEntity vipBuyConfigEntity = vipBuyConfigDao.selectById(buyOrder.getVipBuyConfigId());
if(vipBuyConfigEntity.getType()==1){//医学超级
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId,buyOrder.getUserId()).eq(UserVip::getState,0).in(UserVip::getType,4,5,6));
for (int i=4;i<=6;i++){
UserVip userVip = new UserVip();
userVip.setUserId(buyOrder.getUserId());
userVip.setType(i);
boolean flag = false;
for (UserVip uv:userVipList){
if (uv.getType()==i){
flag = true;
userVip = uv;
userVip.setEndTime(DateUtils.addYears(uv.getEndTime(),vipBuyConfigEntity.getYear()));
userVipDao.updateById(userVip);
break;
}
}
if (!flag) {
userVip.setStartTime(new Date());
userVip.setEndTime(DateUtils.addYears(userVip.getStartTime(),vipBuyConfigEntity.getYear()));
userVipDao.insert(userVip);
}
}
}else if(vipBuyConfigEntity.getType()==11){//延期医学超级
for (int i=4;i<7;i++){
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId,buyOrder.getUserId()).eq(UserVip::getType,i).orderByDesc(UserVip::getEndTime));
UserVip userVip = userVipList.get(0);
if (userVip.getState()==0) {
userVip.setEndTime(DateUtils.addYears(userVip.getEndTime(),vipBuyConfigEntity.getYear()));
userVipDao.updateById(userVip);
}else {
UserVip uv = new UserVip();
uv.setUserId(buyOrder.getUserId());
uv.setType(i);
uv.setStartTime(new Date());
uv.setEndTime(DateUtils.addYears(uv.getStartTime(),vipBuyConfigEntity.getYear()));
userVipDao.insert(uv);
}
}
}else if (vipBuyConfigEntity.getType()==2){//国心超级
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId,buyOrder.getUserId()).eq(UserVip::getState,0).in(UserVip::getType,7,8));
for (int i=7;i<=8;i++){
UserVip userVip = new UserVip();
userVip.setUserId(buyOrder.getUserId());
userVip.setType(i);
boolean flag = false;
for (UserVip uv:userVipList){
if (uv.getType()==i){
flag = true;
userVip = uv;
userVip.setEndTime(DateUtils.addYears(uv.getEndTime(),vipBuyConfigEntity.getYear()));
userVipDao.updateById(userVip);
break;
}
}
if (!flag) {
userVip.setStartTime(new Date());
userVip.setEndTime(DateUtils.addYears(userVip.getStartTime(),vipBuyConfigEntity.getYear()));
userVipDao.insert(userVip);
}
}
}else if(vipBuyConfigEntity.getType()==21){//延期国心超级
for (int i=7;i<9;i++){
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId,buyOrder.getUserId()).eq(UserVip::getType,i).orderByDesc(UserVip::getEndTime));
UserVip userVip = userVipList.get(0);
if (userVip.getState()==0) {
userVip.setEndTime(DateUtils.addYears(userVip.getEndTime(),vipBuyConfigEntity.getYear()));
userVipDao.updateById(userVip);
}else {
UserVip uv = new UserVip();
uv.setUserId(buyOrder.getUserId());
uv.setType(i);
uv.setStartTime(new Date());
uv.setEndTime(DateUtils.addYears(uv.getStartTime(),vipBuyConfigEntity.getYear()));
userVipDao.insert(uv);
}
}
}else if (vipBuyConfigEntity.getType()==4||vipBuyConfigEntity.getType()==5||vipBuyConfigEntity.getType()==6||
vipBuyConfigEntity.getType()==7||vipBuyConfigEntity.getType()==8){
UserVip userVip = new UserVip();
userVip.setUserId(buyOrder.getUserId());
userVip.setType(vipBuyConfigEntity.getType());
userVip.setStartTime(new Date());
userVip.setEndTime(DateUtils.addYears(userVip.getStartTime(),vipBuyConfigEntity.getYear()));
userVipDao.insert(userVip);
}else if (vipBuyConfigEntity.getType()==41||vipBuyConfigEntity.getType()==51||vipBuyConfigEntity.getType()==61||
vipBuyConfigEntity.getType()==71||vipBuyConfigEntity.getType()==81){
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId,buyOrder.getUserId())
.eq(UserVip::getType,vipBuyConfigEntity.getType().toString().substring(0,1))
.orderByDesc(UserVip::getEndTime));
UserVip userVip = userVipList.get(0);
if (userVip.getState()==0) {
userVip.setEndTime(DateUtils.addYears(userVip.getEndTime(),vipBuyConfigEntity.getYear()));
userVipDao.updateById(userVip);
}else {
UserVip uv = new UserVip();
uv.setUserId(buyOrder.getUserId());
uv.setType(userVip.getType());
uv.setStartTime(new Date());
uv.setEndTime(DateUtils.addYears(uv.getStartTime(),vipBuyConfigEntity.getYear()));
userVipDao.insert(uv);
}
}
}
}

View File

@@ -0,0 +1,16 @@
package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.VipBuyConfigDao;
import com.peanut.modules.common.entity.VipBuyConfigEntity;
import com.peanut.modules.common.service.VipBuyConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("commonVipBuyConfigService")
public class VipBuyConfigServiceImpl extends ServiceImpl<VipBuyConfigDao, VipBuyConfigEntity> implements VipBuyConfigService {
}

View File

@@ -11,7 +11,6 @@ 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 java.util.List;
import java.util.Map;
@@ -79,12 +78,6 @@ public class UserManageController {
return R.ok().put("result",page);
}
//获取vip历史开通记录
@RequestMapping("/activateVIP")
public R activateVIP(@RequestBody UserVipLog vipLog) {
return userService.activateVIP(vipLog);
}

View File

@@ -1,17 +1,13 @@
package com.peanut.modules.master.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.common.utils.ShiroUtils;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.common.entity.UserVip;
import com.peanut.modules.common.entity.VipBuyConfigEntity;
import com.peanut.modules.master.service.MyUserService;
import com.peanut.modules.master.service.UserVipService;
import com.peanut.modules.sociology.service.VipBuyConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,8 +17,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* 超V管理
@@ -36,76 +30,6 @@ public class UserVipController {
private UserVipService vipService;
@Autowired
private MyUserService userService;
@Autowired
private VipBuyConfigService vipBuyConfigService;
//获取vip商品
@RequestMapping("/getVipProductForUser")
public R getVipProductForUser(@RequestBody Map<String, Object> params){
int uid = Integer.parseInt(params.get("uid").toString());
MyUserEntity userEntity = userService.getById(uid);
Integer chaoCount = vipService.count(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, uid).eq(UserVip::getType, 1).gt(UserVip::getEndTime,new Date()).eq(UserVip::getState,0));
Integer medicalCount = vipService.count(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, uid).eq(UserVip::getType, 2).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
Integer sociologyCount = vipService.count(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, uid).eq(UserVip::getType, 3).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
//获取超v列表
LambdaQueryWrapper<VipBuyConfigEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.in(VipBuyConfigEntity::getType,userEntity.getVip().equals("1")||userEntity.getVip().equals("2")||userEntity.getVip().equals("3")? Collections.singletonList(1): Arrays.asList(1,2,3));
wrapper.and(r->r.eq(VipBuyConfigEntity::getDateType,0).or(f->f.eq(VipBuyConfigEntity::getDateType,1).lt(VipBuyConfigEntity::getStartTime,new Date()).gt(VipBuyConfigEntity::getEndTime,new Date())));
List<VipBuyConfigEntity> vipBuyConfigEntities = vipBuyConfigService.list(wrapper);
for (VipBuyConfigEntity v:vipBuyConfigEntities){
if(v.getType()==1){
if(userEntity.getVip().equals("0")){
v.setLastFee(chaoCount==0?v.getFee():v.getRebateFee());
} else {
if(userEntity.getVip().equals("2")){//医学转超v计算价格
List<UserVip> userVips = vipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, uid).eq(UserVip::getType, 2).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
return R.error("用户vip信息异常请联系管理员");
}
UserVip userVip = userVips.get(0);
Date nowDate = new Date(); // 第一个日期
Date endDate = userVip.getEndTime(); // 第二个日期
long differenceInMilliseconds = endDate.getTime() - nowDate.getTime();
int differenceInDays = (int) TimeUnit.MILLISECONDS.toDays(differenceInMilliseconds);
int i = (18000 / (3 * 365)) * differenceInDays;//默认按照打折价格抵扣
BigDecimal chaFee = BigDecimal.valueOf(i);
v.setLastFee(chaoCount>0?v.getRebateFee().subtract(chaFee):v.getFee().subtract(chaFee));
} else if (userEntity.getVip().equals("3")) {//国学vip转超v计算价格
List<UserVip> userVips = vipService.list(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, uid).eq(UserVip::getType, 3).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
return R.error("用户vip信息异常请联系管理员");
}
UserVip userVip = userVips.get(0);
Date nowDate = new Date(); // 第一个日期
Date endDate = userVip.getEndTime(); // 第二个日期
long differenceInMilliseconds = endDate.getTime() - nowDate.getTime();
int differenceInDays = (int)TimeUnit.MILLISECONDS.toDays(differenceInMilliseconds);
int i = (8888 / (3 * 365)) * differenceInDays;//默认按照打折价格抵扣
BigDecimal chaFee = BigDecimal.valueOf(i);
v.setLastFee(chaoCount>0?v.getRebateFee().subtract(chaFee):v.getFee().subtract(chaFee));
}else {
v.setLastFee(v.getRebateFee());
}
}
}else {
v.setLastFee(chaoCount>0||medicalCount>0||sociologyCount>0?v.getRebateFee():v.getFee());
}
}
Map<String, List<VipBuyConfigEntity>> flag = new HashMap<>();
List<VipBuyConfigEntity> collect = vipBuyConfigEntities.stream().filter(r -> r.getType() == 1 &&r.getDateType()==0).collect(Collectors.toList());
List<VipBuyConfigEntity> collect2 = vipBuyConfigEntities.stream().filter(r -> r.getType() == 1 && r.getDateType() == 1).collect(Collectors.toList());
List<VipBuyConfigEntity> collect4 = vipBuyConfigEntities.stream().filter(r -> r.getType() == 2 && r.getDateType()==0).collect(Collectors.toList());
List<VipBuyConfigEntity> collect5 = vipBuyConfigEntities.stream().filter(r -> r.getType() == 2 && r.getDateType() == 1).collect(Collectors.toList());
List<VipBuyConfigEntity> collect1 = vipBuyConfigEntities.stream().filter(r -> r.getType() == 3 && r.getDateType()==0).collect(Collectors.toList());
List<VipBuyConfigEntity> collect3 = vipBuyConfigEntities.stream().filter(r -> r.getType() == 3 && r.getDateType() == 1).collect(Collectors.toList());
flag.put("super",collect);
flag.put("super_hd",collect2);
flag.put("sociology",collect1);
flag.put("sociology_hd",collect3);
flag.put("medical",collect4);
flag.put("medical_hd",collect5);
return R.ok().put("list",flag);
}
@RequestMapping("/listByPage")
public R listByPage(@RequestBody Map<String, Object> params) {

View File

@@ -2,10 +2,8 @@ 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;
@@ -15,6 +13,4 @@ public interface MyUserService extends IService<MyUserEntity> {
Page<UserVip> getVipHistoryList(Map<String, Object> params);
R activateVIP(UserVipLog vipLog);
}

View File

@@ -12,17 +12,15 @@ import com.peanut.common.utils.ShiroUtils;
import com.peanut.common.utils.SpdbUtil;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.UserVipService;
import com.peanut.modules.common.to.ParamTo;
import com.peanut.modules.master.service.CourseCatalogueChapterVideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.xml.ws.soap.Addressing;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Slf4j
@Service("masterCourseCatalogueChapterVideoService")
@@ -40,9 +38,7 @@ public class CourseCatalogueChapterVideoServiceImpl extends ServiceImpl<CourseCa
@Autowired
private UserCourseBuyDao userCourseBuyDao;
@Autowired
private CourseToSociologyDao courseToSociologyDao;
@Autowired
private CourseToMedicineDao courseToMedicineDao;
private UserVipService userVipService;
@Autowired
private MyUserDao userDao;
@Autowired
@@ -186,21 +182,10 @@ public class CourseCatalogueChapterVideoServiceImpl extends ServiceImpl<CourseCa
}
private boolean courseCheckVip(MyUserEntity u,int courseId){
if(u.getVip().equals("1")){
UserVip userVip = userVipService.ownCourseCatalogueByVip(courseId);
if (userVip != null) {
return true;
}
if(u.getVip().equals("3")){
Integer integer = courseToSociologyDao.selectCount(new LambdaQueryWrapper<CourseToSociologyEntity>().eq(CourseToSociologyEntity::getCourseId, courseId));
if(integer>0){
return true;
}
}
if(u.getVip().equals("2")){
Integer integer = courseToMedicineDao.selectCount(new LambdaQueryWrapper<CourseToMedicine>().eq(CourseToMedicine::getCourseId, courseId));
if(integer>0){
return true;
}
}
return false;
}

View File

@@ -1,25 +1,17 @@
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.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
@@ -43,7 +35,7 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
wrapper.selectAs(UserVip::getEndTime,"endTime");
wrapper.leftJoin(UserVip.class,UserVip::getUserId,MyUserEntity::getId);
if (!"0".equals(params.get("type").toString())){
wrapper.eq(MyUserEntity::getVip,params.get("type"));
wrapper.eq(UserVip::getType,params.get("type"));
}
wrapper.eq(UserVip::getState,0);
if (StringUtils.isNotBlank(params.get("userWords").toString())){
@@ -71,48 +63,5 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
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(vipLog.getCreateTime());
newUserVip.setEndTime(DateUtils.addDays(newUserVip.getStartTime(),vipLog.getDays()));
userVipDao.insert(newUserVip);
return R.ok();
}
}

View File

@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.common.utils.SpdbUtil;
import com.peanut.modules.common.dao.CourseCatalogueDao;
@@ -14,12 +13,12 @@ import com.peanut.modules.common.dao.CourseMedicineDao;
import com.peanut.modules.common.dao.CourseToMedicineDao;
import com.peanut.modules.common.dao.UserCourseBuyDao;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.UserVipService;
import com.peanut.modules.common.to.ParamTo;
import com.peanut.modules.medical.service.CourseMedicalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@@ -28,7 +27,7 @@ import java.util.stream.Collectors;
public class CourseMedicalServiceImpl extends ServiceImpl<CourseMedicineDao, CourseMedicine> implements CourseMedicalService {
@Autowired
private CourseMedicineDao medicineDao;
private UserVipService userVipService;
@Autowired
private CourseToMedicineDao toMedicineDao;
@Autowired
@@ -105,7 +104,6 @@ public class CourseMedicalServiceImpl extends ServiceImpl<CourseMedicineDao, Cou
public Page<CourseEntity> getMedicalCoursePriceIsBuy(Map<String,Object> params) {
Integer limit = Integer.valueOf(params.get("limit").toString());
Integer page = Integer.valueOf(params.get("page").toString());
String vip = ShiroUtils.getUser().getVip();
MPJLambdaWrapper<CourseToMedicine> wrapper = new MPJLambdaWrapper<>();
wrapper.selectAll(CourseEntity.class);
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToMedicine::getCourseId);
@@ -116,16 +114,15 @@ public class CourseMedicalServiceImpl extends ServiceImpl<CourseMedicineDao, Cou
if(courseEntities.size()>0){
for (CourseEntity co:courseEntities){
List<CourseCatalogueEntity> courseCatalogueEntities = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>().eq(CourseCatalogueEntity::getCourseId, co.getId()).orderByAsc(CourseCatalogueEntity::getSort));
if (courseCatalogueEntities.size() > 0){
for (CourseCatalogueEntity cc:courseCatalogueEntities){
if ("0".equals(vip)||"3".equals(vip)){
Integer i = userCourseBuyDao.selectCount(new LambdaQueryWrapper<UserCourseBuyEntity>()
.eq(UserCourseBuyEntity::getCatalogueId, cc.getId())
.eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId()));
cc.setIsBuy(i>0?1:0);
}else {
cc.setIsBuy(1);
}
for (CourseCatalogueEntity cc:courseCatalogueEntities){
UserVip userVip = userVipService.ownCourseCatalogueByVip(cc.getCourseId());
if (userVip==null){
Integer i = userCourseBuyDao.selectCount(new LambdaQueryWrapper<UserCourseBuyEntity>()
.eq(UserCourseBuyEntity::getCatalogueId, cc.getId())
.eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId()));
cc.setIsBuy(i>0?1:0);
}else {
cc.setIsBuy(1);
}
}
co.setCourseCatalogueEntityList(courseCatalogueEntities);

View File

@@ -3,19 +3,18 @@ package com.peanut.modules.medical.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.UserVipService;
import com.peanut.modules.common.to.ParamTo;
import com.peanut.modules.medical.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@@ -23,6 +22,8 @@ import java.util.stream.Collectors;
@Service("medicalCourseService")
public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> implements CourseService {
@Autowired
private UserVipService userVipService;
@Autowired
UserCourseStudyingDao studyingDao;
@Autowired
@@ -119,7 +120,6 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
@Override
public List getUserCourseStudying(Map<String, Object> param) {
MyUserEntity user = ShiroUtils.getUser();
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,CourseEntity::getId);
wrapper.leftJoin(UserCourseStudying.class,UserCourseStudying::getCourseId,CourseEntity::getId);
@@ -133,17 +133,15 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
if (courseCatalogueEntities.size() > 0) {
//查询目录添加,购买的课程目录详细信息
for (CourseCatalogueEntity courseCatalogueEntity : courseCatalogueEntities) {
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, user.getId()));
List<UserCourseBuyEntity> userCourseBuyList = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId()).eq(UserCourseBuyEntity::getCatalogueId, courseCatalogueEntity.getId()));
//是否购买,生效时间
if ("1".equals(user.getVip())||"2".equals(user.getVip())){
//是超级会员或者医学会员
if (userVipList.size() > 0) {
courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userVipList.get(0).getEndTime());
}
UserVip userVip = userVipService.ownCourseCatalogueByVip(courseCatalogueEntity.getCourseId());
if (userVip!=null){
//会员
courseCatalogueEntity.setStartTime(userVip.getStartTime());
courseCatalogueEntity.setEndTime(userVip.getEndTime());
courseCatalogueEntity.setIsBuy(1);
}else if ("0".equals(user.getVip())){
}else {
//普通用户
if (userCourseBuyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
@@ -152,24 +150,6 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
}else {
courseCatalogueEntity.setIsBuy(0);
}
}else if ("3".equals(user.getVip())){
//国学会员
//买的医学课程
if (userCourseBuyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userCourseBuyList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userCourseBuyList.get(0).getEndTime());
}else {
//国学课程会员免费
List<CourseToSociologyEntity> courseToSociologyList = courseToSociologyDao.selectList(new LambdaQueryWrapper<CourseToSociologyEntity>().eq(CourseToSociologyEntity::getCourseId, courseCatalogueEntity.getCourseId()));
if (courseToSociologyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userVipList.get(0).getEndTime());
}else {
courseCatalogueEntity.setIsBuy(0);
}
}
}
}
}
@@ -181,25 +161,24 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
@Override
public Page<CourseEntity> getUserCourseBuy(Map<String, Object> param) {
MyUserEntity user =ShiroUtils.getUser();
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,CourseEntity::getId);
//0-普通 1超级vip 2医学vip 3国学vip
if ("0".equals(user.getVip())||"3".equals(user.getVip())){
if (userVipService.noMedicalVip()){
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
wrapper.leftJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
wrapper.eq(UserCourseBuyEntity::getUserId,user.getId());
if ("3".equals(user.getVip())){
MPJLambdaWrapper<CourseEntity> vipWrapper = new MPJLambdaWrapper<>(CourseEntity.class);
vipWrapper.leftJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,CourseEntity::getId);
vipWrapper.exists("select * from course_to_sociology where del_flag = 0 and course_id = t.id");
vipWrapper.selectAll(CourseEntity.class);
vipWrapper.first("(");
vipWrapper.last(")");
wrapper.first("(");
wrapper.last(")");
wrapper.union(vipWrapper);
wrapper.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId());
}else {
List list = new ArrayList<>();//通过顶级标签获取最下层标签
if (userVipService.isMedicalVip()){
userVipService.bottomLabel(1,list);
}
if (userVipService.isAcupunctureVip()){
userVipService.bottomLabel(2,list);
}
if (userVipService.istumorVip()){
userVipService.bottomLabel(5,list);
}
wrapper.in(CourseToMedicine::getMedicalId,list);
}
if (StringUtils.isNotEmpty(param.get("medicalId").toString())){
wrapper.eq(CourseToMedicine::getMedicalId,param.get("medicalId"));
@@ -212,87 +191,67 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
wrapper.orderByAsc(CourseEntity::getSort);
Page<CourseEntity> courseEntityPage = this.getBaseMapper().selectJoinPage(new Page<>(Long.parseLong(param.get("page").toString()), Long.parseLong(param.get("limit").toString())), CourseEntity.class, wrapper);
List<CourseEntity> courseEntities = courseEntityPage.getRecords();
if(courseEntities!=null&&courseEntities.size()>0){
for (CourseEntity co:courseEntities){
int i = studyingDao.selectCount(new LambdaQueryWrapper<UserCourseStudying>().eq(UserCourseStudying::getCourseId,co.getId()).eq(UserCourseStudying::getUserId,user.getId()));
co.setIsStudying(i>0?1:0);
MPJLambdaWrapper<CourseCatalogueEntity> catalogueWrapper = new MPJLambdaWrapper();
catalogueWrapper.eq(CourseCatalogueEntity::getCourseId, co.getId());
catalogueWrapper.orderByAsc(CourseCatalogueEntity::getSort);
List<CourseCatalogueEntity> courseCatalogueEntities = courseCatalogueDao.selectList(catalogueWrapper);
if (courseCatalogueEntities.size() > 0) {
//查询目录添加,购买的课程目录详细信息
for (CourseCatalogueEntity courseCatalogueEntity : courseCatalogueEntities) {
List<UserCourseBuyEntity> userCourseBuyList = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getUserId, user.getId()).eq(UserCourseBuyEntity::getCatalogueId, courseCatalogueEntity.getId()));
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, user.getId()));
//完成度、上次学习时间
// catalogueCompletion(courseCatalogueEntity);
//是否购买,生效时间
if ("1".equals(user.getVip())||"2".equals(user.getVip())){
//是超级会员或者医学学会员
if (userVipList.size() > 0) {
courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userVipList.get(0).getEndTime());
}
for (CourseEntity co:courseEntities){
int i = studyingDao.selectCount(new LambdaQueryWrapper<UserCourseStudying>()
.eq(UserCourseStudying::getCourseId,co.getId())
.eq(UserCourseStudying::getUserId,ShiroUtils.getUId()));
co.setIsStudying(i>0?1:0);
MPJLambdaWrapper<CourseCatalogueEntity> catalogueWrapper = new MPJLambdaWrapper();
catalogueWrapper.eq(CourseCatalogueEntity::getCourseId, co.getId());
catalogueWrapper.orderByAsc(CourseCatalogueEntity::getSort);
List<CourseCatalogueEntity> courseCatalogueEntities = courseCatalogueDao.selectList(catalogueWrapper);
if (courseCatalogueEntities.size() > 0) {
//查询目录添加,购买的课程目录详细信息
for (CourseCatalogueEntity courseCatalogueEntity : courseCatalogueEntities) {
//是否购买,生效时间
UserVip userVip = userVipService.ownCourseCatalogueByVip(courseCatalogueEntity.getCourseId());
if (userVip!=null){
//会员
courseCatalogueEntity.setStartTime(userVip.getStartTime());
courseCatalogueEntity.setEndTime(userVip.getEndTime());
courseCatalogueEntity.setIsBuy(1);
}else {
//普通用户
List<UserCourseBuyEntity> userCourseBuyList = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>()
.eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId())
.eq(UserCourseBuyEntity::getCatalogueId, courseCatalogueEntity.getId()));
if (userCourseBuyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
}else if ("0".equals(user.getVip())){
//普通用户
if (userCourseBuyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userCourseBuyList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userCourseBuyList.get(0).getEndTime());
}else {
courseCatalogueEntity.setIsBuy(0);
}
}else if ("3".equals(user.getVip())){
//国学会员
//买的医学课程
if (userCourseBuyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userCourseBuyList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userCourseBuyList.get(0).getEndTime());
}else {
//国学课程会员免费
List<CourseToSociologyEntity> courseToSociologyList = courseToSociologyDao.selectList(new LambdaQueryWrapper<CourseToSociologyEntity>().eq(CourseToSociologyEntity::getCourseId, courseCatalogueEntity.getCourseId()));
if (courseToSociologyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userVipList.get(0).getEndTime());
}else {
courseCatalogueEntity.setIsBuy(0);
}
}
courseCatalogueEntity.setStartTime(userCourseBuyList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userCourseBuyList.get(0).getEndTime());
}else {
courseCatalogueEntity.setIsBuy(0);
}
}
}
co.setCourseCatalogueEntityList(courseCatalogueEntities);
}
co.setCourseCatalogueEntityList(courseCatalogueEntities);
}
return courseEntityPage;
}
@Override
public List getCourseExpire(Map<String, Object> param) {
String vip = ShiroUtils.getUser().getVip();
if ("0".equals(vip)||"3".equals(vip)){
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.distinct();
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
wrapper.rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
wrapper.rightJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,CourseEntity::getId);
//关掉本次查询del_flg = 0的条件查询过期课程
wrapper.disableSubLogicDel();
wrapper.eq(UserCourseBuyEntity::getUserId,param.get("userId"));
wrapper.eq(UserCourseBuyEntity::getDelFlag,-1);
wrapper.selectAll(CourseEntity.class);
wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId");
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle");
wrapper.orderByAsc(CourseEntity::getSort);
wrapper.orderByAsc(CourseCatalogueEntity::getSort);
List<Map<String,Object>> courseEntities = this.getBaseMapper().selectMaps(wrapper);
List<Map<String,Object>> res = new ArrayList<>();
//如果过期又开通,去除
for (Map<String,Object> c : courseEntities) {
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.distinct();
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
wrapper.rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
wrapper.rightJoin(CourseToMedicine.class,CourseToMedicine::getCourseId,CourseEntity::getId);
//关掉本次查询del_flg = 0的条件查询过期课程
wrapper.disableSubLogicDel();
wrapper.eq(UserCourseBuyEntity::getUserId,param.get("userId"));
wrapper.eq(UserCourseBuyEntity::getDelFlag,-1);
wrapper.selectAll(CourseEntity.class);
wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId");
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle");
wrapper.orderByAsc(CourseEntity::getSort);
wrapper.orderByAsc(CourseCatalogueEntity::getSort);
List<Map<String,Object>> courseEntities = this.getBaseMapper().selectMaps(wrapper);
List<Map<String,Object>> res = new ArrayList<>();
//如果过期又开通,去除
for (Map<String,Object> c : courseEntities) {
UserVip userVip = userVipService.ownCourseCatalogueByVip((int)c.get("id"));
if (userVip == null) {
int ucb = userCourseBuyDao.selectCount(new LambdaQueryWrapper<UserCourseBuyEntity>()
.eq(UserCourseBuyEntity::getUserId,param.get("userId"))
.eq(UserCourseBuyEntity::getCatalogueId,c.get("catalogueId")));
@@ -300,10 +259,8 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
res.add(c);
}
}
return res;
}else {
return null;
}
return res;
}
@@ -322,22 +279,11 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
.orderByAsc(ShopProduct::getSort));
flag.put("shopProductList",shopProductList);
}
//获取用户身份和此课程的关系
MyUserEntity userEntity = myUserDao.selectById(uId);
HashMap<String, String> userVip = new HashMap<>();
userVip.put("vip",userEntity.getVip());
if (userEntity.getVip().equals("3")){
Integer integer = courseToSociologyDao.selectCount(new LambdaQueryWrapper<CourseToSociologyEntity>().eq(CourseToSociologyEntity::getCourseId, id));
userVip.put("vipCan",integer>0?"1":"0");
}
flag.put("vip",userVip);
//目录信息
List<CourseCatalogueEntity> courseCatalogueEntities = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>().eq(CourseCatalogueEntity::getCourseId, id).orderByAsc(CourseCatalogueEntity::getSort));
for (CourseCatalogueEntity c :courseCatalogueEntities){
List<UserCourseBuyEntity> userCourseBuyList = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getUserId, uId).eq(UserCourseBuyEntity::getCatalogueId, c.getId()));
//完成度、上次学习时间
// catalogueCompletion(c);
catalogueCompletion(c);//完成度、上次学习时间
if (userCourseBuyList.size() > 0) {
c.setIsBuy(1);
c.setStartTime(userCourseBuyList.get(0).getStartTime());
@@ -373,28 +319,26 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
}
private void catalogueCompletion(CourseCatalogueEntity c){
List<CourseCatalogueChapterEntity> courseCatalogueChapterEntities = courseCatalogueChapterDao.selectList(new LambdaQueryWrapper<CourseCatalogueChapterEntity>().eq(CourseCatalogueChapterEntity::getCatalogueId, c.getId()));
Integer act = 0;
Date date = null;
for (CourseCatalogueChapterEntity cc : courseCatalogueChapterEntities){
List<CourseCatalogueChapterVideoEntity> courseCatalogueChapterVideoEntities = courseCatalogueChapterVideoDao.selectList(new LambdaQueryWrapper<CourseCatalogueChapterVideoEntity>().eq(CourseCatalogueChapterVideoEntity::getChapterId, cc.getId()));
List<Integer> collect = courseCatalogueChapterVideoEntities.stream().map(CourseCatalogueChapterVideoEntity::getId).collect(Collectors.toList());
if(collect.size()==0){
continue;
}
List<UserCourseVideoPositionEntity> videoPositionList = userCourseVideoPositionDao.selectList(new LambdaQueryWrapper<UserCourseVideoPositionEntity>().eq(UserCourseVideoPositionEntity::getUserId, ShiroUtils.getUId()).in(UserCourseVideoPositionEntity::getVideoId, collect).orderByDesc(UserCourseVideoPositionEntity::getCreateTime));
if (videoPositionList.size()>0){
act++;
if (date!=null){
date = date.getTime()>videoPositionList.get(0).getUpdateTime().getTime()?date:videoPositionList.get(0).getUpdateTime();
}else {
date = videoPositionList.get(0).getUpdateTime();
List<CourseCatalogueChapterEntity> chapterList = courseCatalogueChapterDao.selectList(new LambdaQueryWrapper<CourseCatalogueChapterEntity>().eq(CourseCatalogueChapterEntity::getCatalogueId, c.getId()));
if (chapterList.size() > 0){
List<Integer> collect = chapterList.stream().map(CourseCatalogueChapterEntity::getId).collect(Collectors.toList());
List<CourseCatalogueChapterVideoEntity> videoList = courseCatalogueChapterVideoDao
.selectList(new LambdaQueryWrapper<CourseCatalogueChapterVideoEntity>()
.in(CourseCatalogueChapterVideoEntity::getChapterId, collect));
if (videoList.size() > 0) {
List<Integer> videoCollect = videoList.stream().map(CourseCatalogueChapterVideoEntity::getId).collect(Collectors.toList());
List<UserCourseVideoPositionEntity> videoPositionList = userCourseVideoPositionDao
.selectList(new LambdaQueryWrapper<UserCourseVideoPositionEntity>()
.eq(UserCourseVideoPositionEntity::getUserId, ShiroUtils.getUId())
.in(UserCourseVideoPositionEntity::getVideoId, videoCollect)
.orderByDesc(UserCourseVideoPositionEntity::getCreateTime));
if (videoPositionList.size()>0){
int completion = videoPositionList.size() * 100 / videoList.size();
c.setCompletion(completion);
c.setLastStudyTime(videoPositionList.get(0).getCreateTime());
}
}
}
int completion = courseCatalogueChapterEntities.size()==0?0:act * 100 / courseCatalogueChapterEntities.size();
c.setCompletion(completion);
c.setLastStudyTime(date);
}

View File

@@ -1,20 +1,17 @@
package com.peanut.modules.mq.Consumer;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.peanut.common.utils.DateUtils;
import com.peanut.common.utils.R;
import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.ClassEntityService;
import com.peanut.modules.common.service.ClassExamService;
import com.peanut.modules.common.service.CouponHistoryService;
import com.peanut.modules.common.service.UserVipService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -42,6 +39,8 @@ public class CommonConsumer {
private CouponHistoryService couponHistoryService;
@Autowired
private CourseCatalogueDao courseCatalogueDao;
@Autowired
private UserVipService userVipService;
@RabbitListener(queues = DelayQueueConfig.COMMON_QUEUE)
public void commonConsumer(String typeAndParam) {
@@ -71,11 +70,12 @@ public class CommonConsumer {
if (classEntity!=null&&"0".equals(classEntity.getState())){
MyUserEntity user = myUserDao.selectById(typeAndParams[2]);
if (user!=null){
if ("0".equals(user.getVip())||"3".equals(user.getVip())){
//不是vip查询每门课是否购买
List<ClassCourse> courses = classCourseDao.selectList(new LambdaQueryWrapper<ClassCourse>()
.eq(ClassCourse::getModelId,classEntity.getModelId()));
for (ClassCourse classCourse:courses){
List<ClassCourse> courses = classCourseDao.selectList(new LambdaQueryWrapper<ClassCourse>()
.eq(ClassCourse::getModelId,classEntity.getModelId()));
for (ClassCourse classCourse:courses){
UserVip userVip = userVipService.ownCourseCatalogueByVip(user,classCourse.getCourseId());
if (userVip == null) {
//不是vip查询每门课是否购买
List<CourseCatalogueEntity> catalogues = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>()
.eq(CourseCatalogueEntity::getCourseId,classCourse.getCourseId()));
for (CourseCatalogueEntity catalog:catalogues){

View File

@@ -1,23 +1,9 @@
package com.peanut.modules.mq.Consumer;
import com.alibaba.fastjson.JSONObject;
import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.book.service.MyUserService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
* 延时队列消息消费者
@@ -28,38 +14,6 @@ import java.util.Date;
@Slf4j
public class DelayMsgConsumer {
@Autowired
private MyUserService userService;
// 会员开通 时间到期 进入死信队列
@RabbitListener(bindings = @QueueBinding(
value = @Queue(DelayQueueConfig.DEAD_LETTER_QUEUE),
exchange = @Exchange(DelayQueueConfig.DEAD_LETTER_EXCHANGE)))
public void queueAConsumer(Message message) {
Msg msg = JSONObject.parseObject(new String(message.getBody()), Msg.class);
LocalDateTime now = LocalDateTime.now();
Duration duration = Duration.between(msg.getTime(), now);
String id = msg.getMsg();
System.out.println("--------------------------->"+id);
MyUserEntity user = userService.getById(id);
Date vipValidtime = user.getVipValidtime();
Date date = new Date();
long times = date.getTime() - vipValidtime.getTime();
if (times >= 0) {
user.setVip("0");
}
userService.updateById(user);
log.info("DelayMsgConsumer死信队列消费---->Msg:{}, 发送时间:{}, 当前时间:{}, 相差时间:{}秒消息设置的ttl:{}",
JSONObject.toJSONString(msg),
localDateTimeToString(msg.getTime()),
localDateTimeToString(now),
duration.getSeconds(),
msg.getTtl());
}
@Data
public static class Msg {
private String ttl;
@@ -67,8 +21,4 @@ public class DelayMsgConsumer {
private LocalDateTime time;
}
private String localDateTimeToString(LocalDateTime localDateTime){
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return dateTimeFormatter.format(localDateTime);
}
}

View File

@@ -2,9 +2,7 @@ package com.peanut.modules.pay.IOSPay.model.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.models.auth.In;
import lombok.Data;
import javax.persistence.Column;
import java.io.Serializable;
@@ -29,6 +27,7 @@ public class IapRequestDTO implements Serializable {
@Column(name = "receiptData")
String receiptData;
@JsonProperty("isSandBox")
boolean isSandBox;
String relevanceoid;

View File

@@ -16,6 +16,7 @@ import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.CouponHistoryService;
import com.peanut.modules.common.service.CouponService;
import com.peanut.modules.common.service.OfflineActivityToUserService;
import com.peanut.modules.common.service.UserVipService;
import com.peanut.modules.master.service.UserCourseBuyService;
import com.peanut.modules.pay.alipay.config.AliPayConfig;
import com.peanut.modules.pay.alipay.config.AliPayUtil;
@@ -30,8 +31,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.Period;
import java.util.*;
import java.util.stream.Collectors;
@@ -71,11 +70,7 @@ public class AliPayServiceImpl implements AliPayService {
@Autowired
private JfTransactionDetailsDao jfTransactionDetailsDao;
@Autowired
private MyUserDao myUserDao;
@Autowired
private VipBuyConfigDao vipBuyConfigDao;
@Autowired
private UserVipDao userVipDao;
private UserVipService userVipService;
@Autowired
private CouponService couponService;
@Autowired
@@ -200,13 +195,7 @@ public class AliPayServiceImpl implements AliPayService {
userCoinJf(order);
}
//开通vip
openVipForUser(order);
//获取会员开通 日期
// BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(Integer.valueOf(body));
// String month = bookBuyConfigEntity.getMonth();
// userService.openMember(Integer.valueOf(customerid),Integer.valueOf(month));
// // 插入 开通记录
// buyOrderService.updateOrderStatus(Integer.valueOf(customerid),oldPayZfbOrderEntity.getRelevanceoid(),"2");
userVipService.openVipForUser(order);
}
if("point".equals(subject)){
@@ -342,91 +331,6 @@ public class AliPayServiceImpl implements AliPayService {
}
}
private void openVipForUser(BuyOrder buyOrder) throws Exception {
VipBuyConfigEntity vipBuyConfigEntity = vipBuyConfigDao.selectById(buyOrder.getVipBuyConfigId());
MyUserEntity userEntity = myUserDao.selectById(buyOrder.getUserId());
String u_v_type = userEntity.getVip();
if(vipBuyConfigEntity.getType()==1){//超v
if(u_v_type.equals("0")){//初次办理
UserVip userVip = new UserVip();
userVip.setUserId(userEntity.getId());
userVip.setType(1);
userVip.setStartTime(new Date());
LocalDate today = LocalDate.now();
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
userVip.setEndTime(threeYearsDate);
userVipDao.insert(userVip);
userEntity.setVip("1");
myUserDao.updateById(userEntity);
} else if(u_v_type.equals("1")){//vip延期
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
throwExceptionMethod();
}
UserVip userVip = userVips.get(0);
Date endTime = userVip.getEndTime();
Calendar calendar = Calendar.getInstance();
calendar.setTime(endTime);
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
userVip.setEndTime(calendar.getTime());
userVipDao.updateById(userVip);
}else if (u_v_type.equals("2")||u_v_type.equals("3")){//医学vip或国学vip升级
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
throwExceptionMethod();
}
UserVip userVip1 = userVips.get(0);
userVip1.setEndTime(new Date());
userVip1.setState(1);
userVipDao.updateById(userVip1);
UserVip userVip = new UserVip();
userVip.setUserId(userEntity.getId());
userVip.setType(1);
userVip.setStartTime(new Date());
LocalDate today = LocalDate.now();
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
userVip.setEndTime(threeYearsDate);
userVipDao.insert(userVip);
userEntity.setVip("1");
myUserDao.updateById(userEntity);
}
}
if(vipBuyConfigEntity.getType()==2||vipBuyConfigEntity.getType()==3){//医学vip或国学vip
if(userEntity.getVip().equals("2")||userEntity.getVip().equals("3")){//续费
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
throwExceptionMethod();
}
UserVip userVip = userVips.get(0);
Date endTime = userVip.getEndTime();
Calendar calendar = Calendar.getInstance();
calendar.setTime(endTime);
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
userVip.setEndTime(calendar.getTime());
userVipDao.updateById(userVip);
}else{//新办理
UserVip userVip = new UserVip();
userVip.setUserId(userEntity.getId());
userVip.setType(vipBuyConfigEntity.getType());
userVip.setStartTime(new Date());
LocalDate today = LocalDate.now();
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
userVip.setEndTime(threeYearsDate);
userVipDao.insert(userVip);
userEntity.setVip(vipBuyConfigEntity.getType().toString());
myUserDao.updateById(userEntity);
}
}
}
private static void throwExceptionMethod() throws Exception {
throw new Exception("开通vip异常");
}
@Override
@Transactional
public String refund(Map<String,Object> params) {

View File

@@ -42,8 +42,8 @@ public class ApplePayController {
// return Result.failed(ResultCode.APPLE_NULL);
} else {
//
return applePayService.getAppPay(verifyResult, TransactionID);
// return applePayService.getAppPay(verifyResult, TransactionID);
return R.ok();
// return applePayService.doIosRequest(TransactionID,receipt,userId);
}

View File

@@ -1,6 +1,5 @@
package com.peanut.modules.pay.applePay.service;
import com.peanut.common.utils.R;
import com.peanut.modules.pay.IOSPay.Result;
import org.springframework.stereotype.Service;
@@ -30,7 +29,7 @@ public interface ApplePayService {
R getAppPay(String verifyResult, String transactionID);
// R getAppPay(String verifyResult, String transactionID);
}

View File

@@ -1,10 +1,7 @@
package com.peanut.modules.pay.applePay.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.DateUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.book.service.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.pay.IOSPay.Result;
import com.peanut.modules.pay.applePay.service.ApplePayService;
import com.peanut.modules.pay.applePay.utils.*;
@@ -15,8 +12,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
@@ -122,63 +117,38 @@ public class ApplePayServiceImpl implements ApplePayService {
}
@Override
@Transactional
public R getAppPay(String verifyResult, String transactionID) {
log.info("##########################苹果支付验证!########################");
JSONObject jsonObject = JSONObject.parseObject(verifyResult);
String status = jsonObject.getString("status");
//判断是否验证成功
if ("0".equals(status)) {
//app端所提供的收据是有效的,验证成功
String receipt = jsonObject.getString("receipt");
JSONObject returnJson = JSONObject.parseObject(receipt);
String in_app = returnJson.getString("in_app");
JSONObject in_appJson = JSONObject.parseObject(in_app.substring(1, in_app.length() - 1));
String transactionId = in_appJson.getString("transaction_id");
String in_app_ownership_type = in_appJson.getString("in_app_ownership_type");
//如果验证后的订单号与app端传来的订单号一致并且状态为已支付状态则处理自己的业务
if (transactionID.equals(transactionId) && "PURCHASED".equals(in_app_ownership_type)) {
//===================处理自己的业务 ============================
BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", transactionId ));
PayWechatOrderEntity wechat = new PayWechatOrderEntity();
// @Override
// @Transactional
// public R getAppPay(String verifyResult, String transactionID) {
// log.info("##########################苹果支付验证!########################");
// JSONObject jsonObject = JSONObject.parseObject(verifyResult);
// String status = jsonObject.getString("status");
// //判断是否验证成功
// if ("0".equals(status)) {
// //app端所提供的收据是有效的,验证成功
// String receipt = jsonObject.getString("receipt");
// JSONObject returnJson = JSONObject.parseObject(receipt);
// String in_app = returnJson.getString("in_app");
// JSONObject in_appJson = JSONObject.parseObject(in_app.substring(1, in_app.length() - 1));
// String transactionId = in_appJson.getString("transaction_id");
// String in_app_ownership_type = in_appJson.getString("in_app_ownership_type");
// //如果验证后的订单号与app端传来的订单号一致并且状态为已支付状态则处理自己的业务
// if (transactionID.equals(transactionId) && "PURCHASED".equals(in_app_ownership_type)) {
// //===================处理自己的业务 ============================
// BuyOrder order = this.buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("order_sn", transactionId ));
// PayWechatOrderEntity wechat = new PayWechatOrderEntity();
//
//
// }
// return R.ok();
// }
// return R.error("苹果内购验证失败");
// }
if ("vip".equals(order.getOrderType())) {
//会员记录
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(wechat.getBuyOrderId());
String month = bookBuyConfigEntity.getMonth();
userService.openMember(Integer.valueOf(transactionId),Integer.valueOf(month));
buyOrderService.updateOrderStatus(Integer.valueOf(transactionId),order.getOrderSn(),"2");
}
if ("order".equals(order.getOrderType())) {
BuyOrder orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper<BuyOrder>().eq("order_sn", wechat.getOrderId()));
BigDecimal realMoney = orderEntity.getRealMoney();
//更新 订单 记录
}
if ("point".equals(order.getOrderType())) {
BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(wechat.getBuyOrderId());
MyUserEntity userEntity = userService.getById(Integer.valueOf(order.getUserId()));
String realMoney = bookBuyConfigEntity.getRealMoney();
userService.rechargeHSPoint(userEntity,Integer.valueOf(realMoney));
//插入虚拟币消费记录
transactionDetailsService.rechargeRecord(userEntity,realMoney,wechat.getId().intValue(),"苹果支付",order.getOrderSn());
//插入花生币充值记录
payPaymentOrderService.insertDetail(userEntity,bookBuyConfigEntity,wechat.getId().toString());
buyOrderService.updateOrderStatus(Integer.valueOf(order.getUserId()),order.getOrderSn(),"2");
}
}
return R.ok();
}
return R.error("苹果内购验证失败");
}}
}

View File

@@ -14,6 +14,7 @@ import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.CouponHistoryService;
import com.peanut.modules.common.service.CouponService;
import com.peanut.modules.common.service.OfflineActivityToUserService;
import com.peanut.modules.common.service.UserVipService;
import com.peanut.modules.master.service.UserCourseBuyService;
import com.peanut.modules.pay.refund.entity.PayRefundOrder;
import com.peanut.modules.pay.refund.service.PayRefundOrderService;
@@ -27,11 +28,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.Period;
import java.util.*;
import java.util.stream.Collectors;
@@ -79,11 +77,7 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
@Autowired
private JfTransactionDetailsDao jfTransactionDetailsDao;
@Autowired
private MyUserDao myUserDao;
@Autowired
private VipBuyConfigDao vipBuyConfigDao;
@Autowired
private UserVipDao userVipDao;
private UserVipService userVipService;
@Autowired
private CouponService couponService;
@Autowired
@@ -183,7 +177,7 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
userCoinJf(order);
}
//开通vip
openVipForUser(order);
userVipService.openVipForUser(order);
}
// 1.根据订单id获取订单信息
@@ -307,92 +301,6 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
}
}
private void openVipForUser(BuyOrder buyOrder) throws Exception {
VipBuyConfigEntity vipBuyConfigEntity = vipBuyConfigDao.selectById(buyOrder.getVipBuyConfigId());
MyUserEntity userEntity = myUserDao.selectById(buyOrder.getUserId());
String u_v_type = userEntity.getVip();
if(vipBuyConfigEntity.getType()==1){//超v
if(u_v_type.equals("0")){//初次办理
UserVip userVip = new UserVip();
userVip.setUserId(userEntity.getId());
userVip.setType(1);
userVip.setStartTime(new Date());
LocalDate today = LocalDate.now();
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
userVip.setEndTime(threeYearsDate);
userVipDao.insert(userVip);
userEntity.setVip("1");
myUserDao.updateById(userEntity);
}else if(u_v_type.equals("1")){//vip延期
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
throwExceptionMethod();
}
UserVip userVip = userVips.get(0);
Date endTime = userVip.getEndTime();
Calendar calendar = Calendar.getInstance();
calendar.setTime(endTime);
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
userVip.setEndTime(calendar.getTime());
userVipDao.updateById(userVip);
}else if (u_v_type.equals("2")||u_v_type.equals("3")){//医学vip或国学vip升级
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
throwExceptionMethod();
}
UserVip userVip1 = userVips.get(0);
userVip1.setEndTime(new Date());
userVip1.setState(1);
userVipDao.updateById(userVip1);
UserVip userVip = new UserVip();
userVip.setUserId(userEntity.getId());
userVip.setType(1);
userVip.setStartTime(new Date());
LocalDate today = LocalDate.now();
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
userVip.setEndTime(threeYearsDate);
userVipDao.insert(userVip);
userEntity.setVip("1");
myUserDao.updateById(userEntity);
}
}
if(vipBuyConfigEntity.getType()==2||vipBuyConfigEntity.getType()==3){//医学vip或国学vip
if(userEntity.getVip().equals("2")||userEntity.getVip().equals("3")){//续费
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, userEntity.getId()).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
throwExceptionMethod();
}
UserVip userVip = userVips.get(0);
Date endTime = userVip.getEndTime();
Calendar calendar = Calendar.getInstance();
calendar.setTime(endTime);
calendar.add(Calendar.YEAR,vipBuyConfigEntity.getYear());
userVip.setEndTime(calendar.getTime());
userVipDao.updateById(userVip);
}else{//新办理
UserVip userVip = new UserVip();
userVip.setUserId(userEntity.getId());
userVip.setType(vipBuyConfigEntity.getType());
userVip.setStartTime(new Date());
LocalDate today = LocalDate.now();
LocalDate threeYearsLater = today.plus(Period.ofYears(vipBuyConfigEntity.getYear()));
Date threeYearsDate = Date.from(threeYearsLater.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant());
userVip.setEndTime(threeYearsDate);
userVipDao.insert(userVip);
userEntity.setVip(vipBuyConfigEntity.getType().toString());
myUserDao.updateById(userEntity);
}
}
}
private static void throwExceptionMethod() throws Exception {
throw new Exception("开通vip异常");
}
@Override
public String refund(Map<String,Object> map){
LambdaQueryWrapper<PayWechatOrderEntity> wrapper = new LambdaQueryWrapper();

View File

@@ -15,8 +15,6 @@ 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 java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -27,10 +25,10 @@ public class PsycheCourseController {
@Autowired
private CourseService courseService;
@Autowired
private CourseCatalogueService coursecatalogueService;
@Autowired
private UserVipService userVipService;
@Autowired
private CourseCatalogueService coursecatalogueService;
@Autowired
private UserCourseBuyService userCoursebuyService;
@Autowired
private UserCourseStudyingService userCourseStudyingService;
@@ -55,24 +53,26 @@ public class PsycheCourseController {
//我的课程-过期课程
@RequestMapping("/getCourseExpire")
public R getCourseExpire(@RequestBody Map<String,Object> param){
String vip = ShiroUtils.getUser().getVip();
public R getCourseExpire(){
List courseEntities = null;
if (!"1".equals(vip)){
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.distinct();
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
//关掉本次查询del_flg = 0的条件查询过期课程
wrapper.disableSubLogicDel().rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
wrapper.rightJoin(CourseToPsyche.class,CourseToPsyche::getCourseId,CourseEntity::getId);
wrapper.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId());
wrapper.eq(UserCourseBuyEntity::getDelFlag,-1);
wrapper.selectAll(CourseEntity.class);
wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId");
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle");
wrapper.orderByAsc(CourseEntity::getSort);
wrapper.orderByAsc(CourseCatalogueEntity::getSort);
courseEntities = courseService.listMaps(wrapper);
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.distinct();
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
//关掉本次查询del_flg = 0的条件查询过期课程
wrapper.disableSubLogicDel().rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
wrapper.rightJoin(CourseToPsyche.class,CourseToPsyche::getCourseId,CourseEntity::getId);
wrapper.eq(UserCourseBuyEntity::getUserId,ShiroUtils.getUId());
wrapper.eq(UserCourseBuyEntity::getDelFlag,-1);
wrapper.selectAll(CourseEntity.class);
wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId");
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle");
wrapper.orderByAsc(CourseEntity::getSort);
wrapper.orderByAsc(CourseCatalogueEntity::getSort);
List<Map<String,Object>> list = courseService.listMaps(wrapper);
for (Map<String,Object> courseEntity : list) {
if (!userVipService.isPsycheVip()){
courseEntities.add(courseEntity);
}
}
return R.ok().put("courseList",courseEntities);
}
@@ -95,17 +95,13 @@ public class PsycheCourseController {
if (courseCatalogueEntities.size() > 0) {
//查询目录添加,购买的课程目录详细信息
for (CourseCatalogueEntity courseCatalogueEntity : courseCatalogueEntities) {
List<UserVip> userVipList = userVipService.list(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId, user.getId()));
List<UserCourseBuyEntity> userCourseBuyList = userCoursebuyService.list(new LambdaQueryWrapper<UserCourseBuyEntity>()
.eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId()).eq(UserCourseBuyEntity::getCatalogueId, courseCatalogueEntity.getId()));
//是否购买,生效时间
if ("1".equals(user.getVip())){
//是超级会员或者国学会员
if (userVipList.size() > 0) {
courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userVipList.get(0).getEndTime());
}
UserVip userVip = userVipService.ownCourseCatalogueByVip(courseCatalogueEntity.getCourseId());
if (userVip!=null){
courseCatalogueEntity.setStartTime(userVip.getStartTime());
courseCatalogueEntity.setEndTime(userVip.getEndTime());
courseCatalogueEntity.setIsBuy(1);
}else{
//普通用户

View File

@@ -1,24 +1,11 @@
package com.peanut.modules.sociology.controller;
import com.peanut.common.utils.R;
import com.peanut.modules.sociology.service.VipBuyConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
@Slf4j
@RestController("sociologyUser")
@RequestMapping("sociology/user")
public class UserController {
@Autowired
private VipBuyConfigService vipBuyConfigService;
@RequestMapping("/getVipProductForUser")
public R getVipProductForUser() throws ParseException {
return vipBuyConfigService.getVipProductForUser();
}
}

View File

@@ -1,11 +1,7 @@
package com.peanut.modules.sociology.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.VipBuyConfigEntity;
import java.text.ParseException;
public interface VipBuyConfigService extends IService<VipBuyConfigEntity> {
R getVipProductForUser() throws ParseException;
}

View File

@@ -9,6 +9,7 @@ import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.MyUserService;
import com.peanut.modules.common.service.UserVipService;
import com.peanut.modules.common.to.ParamTo;
import com.peanut.modules.sociology.service.CourseService;
import lombok.extern.slf4j.Slf4j;
@@ -24,6 +25,8 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
@Autowired
private MyUserService userService;
@Autowired
private UserVipService userVipService;
@Autowired
private CourseToSociologyDao courseToSociologyDao;
@Autowired
private CourseToMedicineDao courseToMedicineDao;
@@ -62,7 +65,6 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
@Override
public Page getSociologyCourseList(ParamTo param) {
Integer uId = ShiroUtils.getUId();
MyUserEntity user = userDao.selectOne(new LambdaQueryWrapper<MyUserEntity>().eq(MyUserEntity::getId,uId));
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.selectAll(CourseEntity.class);
wrapper.leftJoin(CourseToSociologyEntity.class,CourseToSociologyEntity::getCourseId,CourseEntity::getId);
@@ -75,11 +77,12 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
List<CourseCatalogueEntity> courseCatalogueEntities = courseCatalogueDao.selectList(new LambdaQueryWrapper<CourseCatalogueEntity>().eq(CourseCatalogueEntity::getCourseId, c.getId()));
if (courseCatalogueEntities != null && courseCatalogueEntities.size() > 0){
for (CourseCatalogueEntity cc : courseCatalogueEntities) {
if ("0".equals(user.getVip())||"2".equals(user.getVip())){
UserVip userVip = userVipService.ownCourseCatalogueByVip(cc.getCourseId());
if (userVip!=null){
cc.setIsBuy(1);
}else {
Integer cou = userCourseBuyDao.selectCount(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getCatalogueId, cc.getId()).eq(UserCourseBuyEntity::getUserId,uId).and(i -> i.apply("end_time IS NULL OR end_time > {0}", new Date())));
cc.setIsBuy(cou>0?1:0);
}else {
cc.setIsBuy(1);
}
}
}
@@ -123,6 +126,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
if (StringUtils.isNotEmpty(course.getRelationProductIds())){
String[] ids = course.getRelationProductIds().split(",");
List<ShopProduct> shopProductList = shopProductDao.selectList(new LambdaQueryWrapper<ShopProduct>()
.select(ShopProduct::getProductId,ShopProduct::getProductImages,ShopProduct::getProductName,ShopProduct::getActivityPrice,ShopProduct::getPrice)
.in(ShopProduct::getProductId, ids)
.orderByAsc(ShopProduct::getSort));
flag.put("shopProductList",shopProductList);
@@ -132,8 +136,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
Integer uId = ShiroUtils.getUId();
for (CourseCatalogueEntity c :courseCatalogueEntities){
List<UserCourseBuyEntity> userCourseBuyList = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getUserId, uId).eq(UserCourseBuyEntity::getCatalogueId, c.getId()));
//完成度、上次学习时间
catalogueCompletion(c);
catalogueCompletion(c);//完成度、上次学习时间
if (userCourseBuyList.size() > 0) {
c.setIsBuy(1);
c.setStartTime(userCourseBuyList.get(0).getStartTime());
@@ -152,27 +155,32 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
//获取所有国学标签
List<CourseSociologyEntity> courseSociologyEntities = courseSociologyDao.selectList(null);
MyUserEntity userEntity = userService.getById(uId);
List<Integer> collect = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getUserId, userEntity.getId())).stream().map(UserCourseBuyEntity::getCourseId).collect(Collectors.toList());
if(userEntity.getVip().equals("0")&&collect.size()==0){
return new ArrayList<>();
boolean flag = true;
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId, ShiroUtils.getUId())
.eq(UserVip::getState,0)
.eq(UserVip::getType,6));
if (userVipList.size()>0){
flag = false;
}
ArrayList<Map> flag = new ArrayList<>();
List<Integer> collect = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getUserId, userEntity.getId())).stream().map(UserCourseBuyEntity::getCourseId).collect(Collectors.toList());
ArrayList<Map> resList = new ArrayList<>();
for (CourseSociologyEntity c : courseSociologyEntities){
HashMap<String, Object> stringObjectHashMap = new HashMap<>();
MPJLambdaWrapper<CourseToSociologyEntity> courseToSociologyEntityMPJLambdaWrapper = new MPJLambdaWrapper<>();
courseToSociologyEntityMPJLambdaWrapper.selectAll(CourseEntity.class);
courseToSociologyEntityMPJLambdaWrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToSociologyEntity::getCourseId);
courseToSociologyEntityMPJLambdaWrapper.eq(CourseToSociologyEntity::getSociologyId,c.getId());
courseToSociologyEntityMPJLambdaWrapper.in(userEntity.getVip().equals("0"),CourseToSociologyEntity::getCourseId,collect);
courseToSociologyEntityMPJLambdaWrapper.in(flag,CourseToSociologyEntity::getCourseId,collect);
List<CourseEntity> courseEntities = courseToSociologyDao.selectJoinList(CourseEntity.class, courseToSociologyEntityMPJLambdaWrapper);
if(courseEntities.size()==0){
continue;
}
stringObjectHashMap.put("sociology",c);
stringObjectHashMap.put("courseList",courseEntities);
flag.add(stringObjectHashMap);
resList.add(stringObjectHashMap);
}
return flag;
return resList;
}
@Override
@@ -232,28 +240,26 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
}
private void catalogueCompletion(CourseCatalogueEntity c){
List<CourseCatalogueChapterEntity> courseCatalogueChapterEntities = courseCatalogueChapterDao.selectList(new LambdaQueryWrapper<CourseCatalogueChapterEntity>().eq(CourseCatalogueChapterEntity::getCatalogueId, c.getId()));
Integer act = 0;
Date date = null;
for (CourseCatalogueChapterEntity cc : courseCatalogueChapterEntities){
List<CourseCatalogueChapterVideoEntity> courseCatalogueChapterVideoEntities = courseCatalogueChapterVideoDao.selectList(new LambdaQueryWrapper<CourseCatalogueChapterVideoEntity>().eq(CourseCatalogueChapterVideoEntity::getChapterId, cc.getId()));
List<Integer> collect = courseCatalogueChapterVideoEntities.stream().map(CourseCatalogueChapterVideoEntity::getId).collect(Collectors.toList());
if(collect.size()==0){
continue;
}
List<UserCourseVideoPositionEntity> videoPositionList = userCourseVideoPositionDao.selectList(new LambdaQueryWrapper<UserCourseVideoPositionEntity>().eq(UserCourseVideoPositionEntity::getUserId, ShiroUtils.getUId()).in(UserCourseVideoPositionEntity::getVideoId, collect).orderByDesc(UserCourseVideoPositionEntity::getCreateTime));
if (videoPositionList.size()>0){
act++;
if (date!=null){
date = date.getTime()>videoPositionList.get(0).getCreateTime().getTime()?date:videoPositionList.get(0).getCreateTime();
}else {
date = videoPositionList.get(0).getCreateTime();
List<CourseCatalogueChapterEntity> chapterList = courseCatalogueChapterDao.selectList(new LambdaQueryWrapper<CourseCatalogueChapterEntity>().eq(CourseCatalogueChapterEntity::getCatalogueId, c.getId()));
if (chapterList.size() > 0){
List<Integer> collect = chapterList.stream().map(CourseCatalogueChapterEntity::getId).collect(Collectors.toList());
List<CourseCatalogueChapterVideoEntity> videoList = courseCatalogueChapterVideoDao
.selectList(new LambdaQueryWrapper<CourseCatalogueChapterVideoEntity>()
.in(CourseCatalogueChapterVideoEntity::getChapterId, collect));
if (videoList.size() > 0) {
List<Integer> videoCollect = videoList.stream().map(CourseCatalogueChapterVideoEntity::getId).collect(Collectors.toList());
List<UserCourseVideoPositionEntity> videoPositionList = userCourseVideoPositionDao
.selectList(new LambdaQueryWrapper<UserCourseVideoPositionEntity>()
.eq(UserCourseVideoPositionEntity::getUserId, ShiroUtils.getUId())
.in(UserCourseVideoPositionEntity::getVideoId, videoCollect)
.orderByDesc(UserCourseVideoPositionEntity::getCreateTime));
if (videoPositionList.size()>0){
int completion = videoPositionList.size() * 100 / videoList.size();
c.setCompletion(completion);
c.setLastStudyTime(videoPositionList.get(0).getCreateTime());
}
}
}
int completion = courseCatalogueChapterEntities.size()==0?0:act * 100 / courseCatalogueChapterEntities.size();
c.setCompletion(completion);
c.setLastStudyTime(date);
}
@Override
@@ -276,7 +282,6 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
@Override
public List getUserCourseStudying() {
MyUserEntity user = ShiroUtils.getUser();
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(CourseToSociologyEntity.class,CourseToSociologyEntity::getCourseId,CourseEntity::getId);
wrapper.leftJoin(UserCourseStudying.class,UserCourseStudying::getCourseId,CourseEntity::getId);
@@ -290,19 +295,17 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
if (courseCatalogueEntities.size() > 0) {
//查询目录添加,购买的课程目录详细信息
for (CourseCatalogueEntity courseCatalogueEntity : courseCatalogueEntities) {
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, user.getId()));
List<UserCourseBuyEntity> userCourseBuyList = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getUserId, ShiroUtils.getUId()).eq(UserCourseBuyEntity::getCatalogueId, courseCatalogueEntity.getId()));
//完成度、上次学习时间
// catalogueCompletion(courseCatalogueEntity);
catalogueCompletion(courseCatalogueEntity);
//是否购买,生效时间
if ("1".equals(user.getVip())||"3".equals(user.getVip())){
//是超级会员或者国学会员
if (userVipList.size() > 0) {
courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userVipList.get(0).getEndTime());
}
UserVip userVip = userVipService.ownCourseCatalogueByVip(courseCatalogueEntity.getCourseId());
if (userVip!=null){
//是会员
courseCatalogueEntity.setStartTime(userVip.getStartTime());
courseCatalogueEntity.setEndTime(userVip.getEndTime());
courseCatalogueEntity.setIsBuy(1);
}else if ("0".equals(user.getVip())){
}else {
//普通用户
if (userCourseBuyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
@@ -311,24 +314,6 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
}else {
courseCatalogueEntity.setIsBuy(0);
}
}else if ("2".equals(user.getVip())){
//医学会员
//买的国学课程
if (userCourseBuyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userCourseBuyList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userCourseBuyList.get(0).getEndTime());
}else {
//医学课程会员免费
List<CourseToMedicine> courseToMedicineList = courseToMedicineDao.selectList(new LambdaQueryWrapper<CourseToMedicine>().eq(CourseToMedicine::getCourseId, courseCatalogueEntity.getCourseId()));
if (courseToMedicineList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userVipList.get(0).getEndTime());
}else {
courseCatalogueEntity.setIsBuy(0);
}
}
}
}
}
@@ -353,26 +338,27 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
@Override
public List getCourseExpire(Map<String, Object> param) {
String vip = ShiroUtils.getUser().getVip();
if ("0".equals(vip)||"2".equals(vip)){
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.distinct();
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
//关掉本次查询del_flg = 0的条件查询过期课程
wrapper.disableSubLogicDel().rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
wrapper.rightJoin(CourseToSociologyEntity.class,CourseToSociologyEntity::getCourseId,CourseEntity::getId);
wrapper.eq(UserCourseBuyEntity::getUserId,param.get("userId"));
wrapper.eq(UserCourseBuyEntity::getDelFlag,-1);
wrapper.selectAll(CourseEntity.class);
wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId");
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle");
wrapper.orderByAsc(CourseEntity::getSort);
wrapper.orderByAsc(CourseCatalogueEntity::getSort);
List courseEntities = this.getBaseMapper().selectMaps(wrapper);
return courseEntities;
}else {
return null;
List<Map<String,Object>> courseEntities = null;
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.distinct();
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getCourseId,CourseEntity::getId);
//关掉本次查询del_flg = 0的条件查询过期课程
wrapper.disableSubLogicDel().rightJoin(UserCourseBuyEntity.class,UserCourseBuyEntity::getCatalogueId,CourseCatalogueEntity::getId);
wrapper.rightJoin(CourseToSociologyEntity.class,CourseToSociologyEntity::getCourseId,CourseEntity::getId);
wrapper.eq(UserCourseBuyEntity::getUserId,param.get("userId"));
wrapper.eq(UserCourseBuyEntity::getDelFlag,-1);
wrapper.selectAll(CourseEntity.class);
wrapper.selectAs(CourseCatalogueEntity::getId,"catalogueId");
wrapper.selectAs(CourseCatalogueEntity::getTitle,"catalogueTitle");
wrapper.orderByAsc(CourseEntity::getSort);
wrapper.orderByAsc(CourseCatalogueEntity::getSort);
List<Map<String,Object>> courseList = this.getBaseMapper().selectMaps(wrapper);
for (Map<String,Object> map:courseList){
if (!userVipService.isSociologyVip()){
courseEntities.add(map);
}
}
return courseEntities;
}
@@ -383,15 +369,14 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
}
}
List<CourseEntity> courseEntities = null;
//0-普通 1超级vip 2医学vip 3国学vip
if ("1".equals(user.getVip())||"3".equals(user.getVip())){
if (userVipService.isSociologyVip()){
MPJLambdaWrapper<CourseToSociologyEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToSociologyEntity::getCourseId);
wrapper.selectAll(CourseEntity.class);
wrapper.eq(CourseToSociologyEntity::getSociologyId,c.getId());
wrapper.orderByAsc(CourseEntity::getSort);
courseEntities = courseToSociologyDao.selectJoinList(CourseEntity.class, wrapper);
}else if ("0".equals(user.getVip())){
}else {
MPJLambdaWrapper<UserCourseBuyEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getId,UserCourseBuyEntity::getCatalogueId);
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseCatalogueEntity::getCourseId);
@@ -401,23 +386,6 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
wrapper.eq(CourseToSociologyEntity::getSociologyId,c.getId());
wrapper.orderByAsc(CourseEntity::getSort);
courseEntities = userCourseBuyDao.selectJoinList(CourseEntity.class, wrapper);
}else if ("2".equals(user.getVip())){
MPJLambdaWrapper<UserCourseBuyEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getId,UserCourseBuyEntity::getCatalogueId);
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseCatalogueEntity::getCourseId);
wrapper.leftJoin(CourseToSociologyEntity.class,CourseToSociologyEntity::getCourseId,UserCourseBuyEntity::getCourseId);
wrapper.selectAll(CourseEntity.class);
wrapper.eq(UserCourseBuyEntity::getUserId,user.getId());
wrapper.eq(CourseToSociologyEntity::getSociologyId,c.getId());
wrapper.orderByAsc(CourseEntity::getSort);
courseEntities = userCourseBuyDao.selectJoinList(CourseEntity.class, wrapper);
//添加 国学医学都有的课程
MPJLambdaWrapper<CourseEntity> vipWrapper = new MPJLambdaWrapper<>();
vipWrapper.leftJoin(CourseToSociologyEntity.class,CourseToSociologyEntity::getCourseId,CourseEntity::getId);
vipWrapper.exists("select * from course_to_medicine where del_flag = 0 and course_id = t.id");
vipWrapper.eq(CourseToSociologyEntity::getSociologyId,c.getId());
vipWrapper.selectAll(CourseEntity.class);
courseEntities.addAll(this.getBaseMapper().selectList(vipWrapper));
}
if(courseEntities!=null&&courseEntities.size()>0){
for (CourseEntity co:courseEntities){
@@ -428,20 +396,15 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
if (courseCatalogueEntities.size() > 0) {
//查询目录添加,购买的课程目录详细信息
for (CourseCatalogueEntity courseCatalogueEntity : courseCatalogueEntities) {
List<UserCourseBuyEntity> userCourseBuyList = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getUserId, user.getId()).eq(UserCourseBuyEntity::getCatalogueId, courseCatalogueEntity.getId()));
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, user.getId()));
//完成度、上次学习时间
// catalogueCompletion(courseCatalogueEntity);
//是否购买,生效时间
if ("1".equals(user.getVip())||"3".equals(user.getVip())){
//是超级会员或者国学会员
if (userVipList.size() > 0) {
courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userVipList.get(0).getEndTime());
}
UserVip userVip = userVipService.ownCourseCatalogueByVip(user,courseCatalogueEntity.getCourseId());
if (userVip!=null){
courseCatalogueEntity.setStartTime(userVip.getStartTime());
courseCatalogueEntity.setEndTime(userVip.getEndTime());
courseCatalogueEntity.setIsBuy(1);
}else if ("0".equals(user.getVip())){
}else {
//普通用户
List<UserCourseBuyEntity> userCourseBuyList = userCourseBuyDao.selectList(new LambdaQueryWrapper<UserCourseBuyEntity>().eq(UserCourseBuyEntity::getUserId, user.getId()).eq(UserCourseBuyEntity::getCatalogueId, courseCatalogueEntity.getId()));
if (userCourseBuyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userCourseBuyList.get(0).getStartTime());
@@ -449,24 +412,6 @@ public class CourseServiceImpl extends ServiceImpl<CourseDao, CourseEntity> impl
}else {
courseCatalogueEntity.setIsBuy(0);
}
}else if ("2".equals(user.getVip())){
//医学会员
//买的国学课程
if (userCourseBuyList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userCourseBuyList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userCourseBuyList.get(0).getEndTime());
}else {
//医学课程会员免费
List<CourseToMedicine> courseToMedicineList = courseToMedicineDao.selectList(new LambdaQueryWrapper<CourseToMedicine>().eq(CourseToMedicine::getCourseId, courseCatalogueEntity.getCourseId()));
if (courseToMedicineList.size() > 0) {
courseCatalogueEntity.setIsBuy(1);
courseCatalogueEntity.setStartTime(userVipList.get(0).getStartTime());
courseCatalogueEntity.setEndTime(userVipList.get(0).getEndTime());
}else {
courseCatalogueEntity.setIsBuy(0);
}
}
}
}
}

View File

@@ -1,97 +1,16 @@
package com.peanut.modules.sociology.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.common.dao.MyUserDao;
import com.peanut.modules.common.dao.UserVipDao;
import com.peanut.modules.common.dao.VipBuyConfigDao;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.common.entity.UserVip;
import com.peanut.modules.common.entity.VipBuyConfigEntity;
import com.peanut.modules.sociology.service.VipBuyConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Slf4j
@Service("sociologyUserService")
public class VipBuyConfigServiceImpl extends ServiceImpl<VipBuyConfigDao, VipBuyConfigEntity> implements VipBuyConfigService {
@Autowired
private MyUserDao myUserDao;
@Autowired
private UserVipDao userVipDao;
/**
* 获取国学vip商品
* @return
*/
@Override
public R getVipProductForUser() throws ParseException {
int uid = ShiroUtils.getUId();
MyUserEntity userEntity = myUserDao.selectById(uid);
Integer chaoCount = userVipDao.selectCount(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, uid).eq(UserVip::getType, 1).gt(UserVip::getEndTime,new Date()).eq(UserVip::getState,0));
Integer sociologyCount = userVipDao.selectCount(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, uid).eq(UserVip::getType, 3).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
//获取超v列表
LambdaQueryWrapper<VipBuyConfigEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.in(VipBuyConfigEntity::getType,userEntity.getVip().equals("1")||userEntity.getVip().equals("2")? Collections.singletonList(1):Arrays.asList(1,3));
wrapper.and(r->r.eq(VipBuyConfigEntity::getDateType,0).or(f->f.eq(VipBuyConfigEntity::getDateType,1).lt(VipBuyConfigEntity::getStartTime,new Date()).gt(VipBuyConfigEntity::getEndTime,new Date())));
List<VipBuyConfigEntity> vipBuyConfigEntities = this.getBaseMapper().selectList(wrapper);
for (VipBuyConfigEntity v:vipBuyConfigEntities){
if(v.getType()==1){
if(userEntity.getVip().equals("0")){
v.setLastFee(chaoCount==0?v.getFee():v.getRebateFee());
} else {
if(userEntity.getVip().equals("2")){//医学转超v计算价格
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, uid).eq(UserVip::getType, 2).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
return R.error("用户vip信息异常请联系管理员");
}
UserVip userVip = userVips.get(0);
Date nowDate = new Date(); // 第一个日期
Date endDate = userVip.getEndTime(); // 第二个日期
long differenceInMilliseconds = endDate.getTime() - nowDate.getTime();
int differenceInDays = (int)TimeUnit.MILLISECONDS.toDays(differenceInMilliseconds);
int i = (18000 / (3 * 365)) * differenceInDays;
BigDecimal chaFee = BigDecimal.valueOf(i);
v.setLastFee(v.getFee().subtract(chaFee));
} else if (userEntity.getVip().equals("3")) {//国学vip转超v计算价格
List<UserVip> userVips = userVipDao.selectList(new LambdaQueryWrapper<UserVip>().eq(UserVip::getUserId, uid).eq(UserVip::getType, 3).gt(UserVip::getEndTime, new Date()).eq(UserVip::getState, 0));
if(userVips.size()!=1){
return R.error("用户vip信息异常请联系管理员");
}
UserVip userVip = userVips.get(0);
Date nowDate = new Date(); // 第一个日期
Date endDate = userVip.getEndTime(); // 第二个日期
long differenceInMilliseconds = endDate.getTime() - nowDate.getTime();
int differenceInDays = (int)TimeUnit.MILLISECONDS.toDays(differenceInMilliseconds);
int i = (8888 / (3 * 365)) * differenceInDays;
BigDecimal chaFee = BigDecimal.valueOf(i);
v.setLastFee(v.getFee().subtract(chaFee));
}else {
v.setLastFee(v.getRebateFee());
}
}
}else {
v.setLastFee(chaoCount>0||sociologyCount>0?v.getRebateFee():v.getFee());
}
}
Map<String, List<VipBuyConfigEntity>> flag = new HashMap<>();
List<VipBuyConfigEntity> collect = vipBuyConfigEntities.stream().filter(r -> r.getType() == 1).collect(Collectors.toList());
List<VipBuyConfigEntity> collect1 = vipBuyConfigEntities.stream().filter(r -> r.getType() == 3).collect(Collectors.toList());
List<VipBuyConfigEntity> collect2 = new ArrayList<>();//vipBuyConfigEntities.stream().filter(r -> r.getType() == 1 && r.getDateType() == 1).collect(Collectors.toList());
List<VipBuyConfigEntity> collect3 = new ArrayList<>();//vipBuyConfigEntities.stream().filter(r -> r.getType() == 3 && r.getDateType() == 1).collect(Collectors.toList());
flag.put("super",collect);
flag.put("sociology",collect1);
flag.put("super_hd",collect2);
flag.put("sociology_hd",collect3);
return R.ok().put("list",flag);
}
}