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));
}
}