|
@@ -308,12 +308,12 @@ public class BookServiceImpl implements BookService {
|
|
|
}
|
|
|
if (bookContentVO.getContentId() > freeChapterNum) { //收费
|
|
|
//是否已购买
|
|
|
- long count = consumeMapper.countByExample(ConsumeExample.newAndCreateCriteria()
|
|
|
+ Consume consume = consumeMapper.selectOneByExample(ConsumeExample.newAndCreateCriteria()
|
|
|
.andBookIdEqualTo(bookContentVO.getBookId())
|
|
|
.andUserIdEqualTo(bookContentVO.getUserId())
|
|
|
.example()
|
|
|
);
|
|
|
- if (count == 0) { // 没有购买记录
|
|
|
+ if (consume == null) { // 没有购买记录
|
|
|
User user = userMapper.selectByPrimaryKey(bookContentVO.getUserId());
|
|
|
//查询免费看点
|
|
|
RechargeExample example = RechargeExample.newAndCreateCriteria()
|
|
@@ -343,7 +343,8 @@ public class BookServiceImpl implements BookService {
|
|
|
// 记录到消费表
|
|
|
addConsumer(bookContentVO, book, left, 0);
|
|
|
// 更新免费看点到 user
|
|
|
- userMapper.updateUserKandian(user, user.getKandian(), freeCount - book.getPrice(), DateUtils.getNow());
|
|
|
+ int i = userMapper.updateUserKandian(user, user.getKandian(), freeCount - book.getPrice(), DateUtils.getNow());
|
|
|
+ checkUpdate(i);
|
|
|
|
|
|
} else if (user.getKandian() + freeCount > book.getPrice()) { //免费+充值足够
|
|
|
Integer left = user.getKandian() + freeCount;
|
|
@@ -358,8 +359,10 @@ public class BookServiceImpl implements BookService {
|
|
|
|
|
|
// 记录到消费表
|
|
|
addConsumer(bookContentVO, book, freeCount, book.getPrice() - freeCount);
|
|
|
+
|
|
|
// 更新到 user
|
|
|
- userMapper.updateUserKandian(user, kandian, 0, DateUtils.getNow());
|
|
|
+ int i = userMapper.updateUserKandian(user, kandian, 0, DateUtils.getNow());
|
|
|
+ checkUpdate(i);
|
|
|
|
|
|
} else {
|
|
|
return Result.failure(ResultCode.NOMONEY);
|
|
@@ -381,31 +384,39 @@ public class BookServiceImpl implements BookService {
|
|
|
.andBookIdEqualTo(bookContentVO.getBookId())
|
|
|
.example());
|
|
|
if (userRecentlyRead == null) {
|
|
|
- userRecentlyReadMapper.insert(UserRecentlyRead.builder()
|
|
|
+ int i = userRecentlyReadMapper.insert(UserRecentlyRead.builder()
|
|
|
.userId(bookContentVO.getUserId())
|
|
|
.bookId(book.getId())
|
|
|
.chapterId(Long.valueOf(bookContentVO.getContentId()))
|
|
|
.chapterName(bookContentVO.getContentName())
|
|
|
.createtime(DateUtils.getNow())
|
|
|
.updatetime(DateUtils.getNow())
|
|
|
- .bookShelfAdd((byte)0)
|
|
|
- .bookShelfFlag((byte)0)
|
|
|
+ .bookShelfAdd((byte) 0)
|
|
|
+ .bookShelfFlag((byte) 0)
|
|
|
.build());
|
|
|
+ //checkUpdate(i);
|
|
|
} else {
|
|
|
userRecentlyRead.setChapterId(Long.valueOf(bookContentVO.getContentId()));
|
|
|
userRecentlyRead.setChapterName(bookContentVO.getContentName());
|
|
|
userRecentlyRead.setUpdatetime(DateUtils.getNow());
|
|
|
- userRecentlyReadMapper.updateByPrimaryKeySelective(userRecentlyRead,
|
|
|
+ int i = userRecentlyReadMapper.updateByPrimaryKeySelective(userRecentlyRead,
|
|
|
UserRecentlyRead.Column.chapterId,
|
|
|
UserRecentlyRead.Column.chapterName,
|
|
|
UserRecentlyRead.Column.updatetime
|
|
|
);
|
|
|
+ //checkUpdate(i);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return Result.byObject(content);
|
|
|
}
|
|
|
|
|
|
+ private void checkUpdate(int i) {
|
|
|
+ if (i <= 0) {
|
|
|
+ throw new RuntimeException("请稍后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 消费记录
|
|
|
*
|
|
@@ -416,7 +427,7 @@ public class BookServiceImpl implements BookService {
|
|
|
*/
|
|
|
@Transactional
|
|
|
void addConsumer(BookContentVO bookContentVO, Book book, int freeKandian, int kandian) {
|
|
|
- consumeMapper.insert(Consume.builder()
|
|
|
+ int i = consumeMapper.insert(Consume.builder()
|
|
|
.userId(bookContentVO.getUserId())
|
|
|
.type("1") // 订购章节
|
|
|
.bookId(book.getId())
|
|
@@ -429,6 +440,7 @@ public class BookServiceImpl implements BookService {
|
|
|
.updatetime(DateUtils.getNow())
|
|
|
.businessLine((byte) 0)
|
|
|
.build());
|
|
|
+ checkUpdate(i);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -437,15 +449,16 @@ public class BookServiceImpl implements BookService {
|
|
|
* @param reduceNum 消费多少免费看点
|
|
|
* @param recharge
|
|
|
*/
|
|
|
- @Transactional
|
|
|
+ @Transactional()
|
|
|
void subtractFreeRecharge(int reduceNum, Recharge recharge) {
|
|
|
- rechargeMapper.updateByExampleSelective(
|
|
|
+ int i = rechargeMapper.updateByExampleSelective(
|
|
|
Recharge.builder().remainFreeKandian(recharge.getRemainFreeKandian() - reduceNum).build(),
|
|
|
RechargeExample.newAndCreateCriteria()
|
|
|
.andIdEqualTo(recharge.getId())
|
|
|
.andRemainFreeKandianEqualTo(recharge.getRemainFreeKandian()).example(),
|
|
|
Recharge.Column.remainFreeKandian
|
|
|
);
|
|
|
+ checkUpdate(i);
|
|
|
}
|
|
|
|
|
|
/**
|