Procházet zdrojové kódy

阅读接口更新
还没完成,等待消息

tianyunperfect před 3 roky
rodič
revize
7c85d9a8ba

+ 1 - 0
book-server/src/main/java/com/book/server/common/entity/ResultCode.java

@@ -6,6 +6,7 @@ public enum ResultCode {
     FAIL(-1, "fail"),
     UNKNOWN(-2, "unknown"),
 
+    NOMONEY(10000, "金币不足"),
     ;
 
     private Integer code;

+ 26 - 2
book-server/src/main/java/com/book/server/common/util/DateUtils.java

@@ -18,7 +18,7 @@ import java.time.temporal.TemporalAdjusters;
 public class DateUtils {
 
     /**
-     * 当前秒
+     * 当前
      *
      * @return {@link Long}
      */
@@ -31,10 +31,30 @@ public class DateUtils {
      *
      * @return {@link Long}
      */
-    public static Long getEpochSecond() {
+    public static Long getNowSecond() {
         return Instant.now().getEpochSecond();
     }
 
+    public static Long day3Second = (long) (-3 * 24 * 60 * 60);
+
+    /**
+     * 获取三天前的时间戳(秒)
+     *
+     * @return
+     */
+    public static Integer get3DayAgo() {
+        return (int) Instant.now().plusSeconds(day3Second).getEpochSecond();
+    }
+
+    /**
+     * 获取当前秒
+     *
+     * @return
+     */
+    public static Integer getNow() {
+        return (int) LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
+    }
+
     /**
      * 将Long类型的时间戳转换成String 类型的时间格式,时间格式为:yyyy-MM-dd HH:mm:ss
      */
@@ -93,4 +113,8 @@ public class DateUtils {
         return LocalDateTime.of(lastDayOfThisMonth(), LocalTime.MAX);
     }
 
+    public static void main(String[] args) {
+        System.out.println(DateUtils.getNowSecond());
+        System.out.println(DateUtils.get3DayAgo());
+    }
 }

+ 54 - 6
book-server/src/main/java/com/book/server/service/impl/BookServiceImpl.java

@@ -2,14 +2,18 @@ package com.book.server.service.impl;
 
 
 import com.book.dao.cps.mapper.*;
-import com.book.dao.cps.pojo.Book;
-import com.book.dao.cps.pojo.BookCategory;
-import com.book.dao.cps.pojo.ManageBlock;
-import com.book.dao.cps.pojo.SearchKeyword;
+import com.book.dao.cps.pojo.*;
+import com.book.dao.cpsshard.entity.Recharge;
 import com.book.dao.cpsshard.entity.UserRecentlyRead;
+import com.book.dao.cpsshard.mapper.ConsumeMapper;
+import com.book.dao.cpsshard.mapper.RechargeMapper;
 import com.book.dao.cpsshard.mapper.UserRecentlyReadMapper;
+import com.book.dao.cpsshard.pojo.example.ConsumeExample;
+import com.book.dao.cpsshard.pojo.example.RechargeExample;
 import com.book.dao.cpsshard.pojo.example.UserRecentlyReadExample;
 import com.book.server.common.entity.Result;
+import com.book.server.common.entity.ResultCode;
+import com.book.server.common.util.DateUtils;
 import com.book.server.common.util.JsonUtils;
 import com.book.dao.cps.pojo.example.*;
 import com.book.dao.VO.*;
@@ -25,6 +29,8 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -279,13 +285,55 @@ public class BookServiceImpl implements BookService {
     }
 
 
+    @Autowired
+    private ConfigMapper configMapper;
+
+    @Autowired
+    private ConsumeMapper consumeMapper;
+    @Autowired
+    private UserMapper userMapper;
+
+    @Autowired
+    private RechargeMapper rechargeMapper;
+
     @Override
     public Result<BookContent> getContentByContentId(BookContentVO bookContentVO) {
+        BookContent content = null;
         Book book = bookMapper.selectByPrimaryKey(bookContentVO.getBookId());
-        if (book.getFreeChapterNum() == null) {
+        //是否是付费章节
+        Integer freeChapterNum = book.getFreeChapterNum();
+        if (freeChapterNum == null) { //查看默认配置
+            freeChapterNum = Integer.valueOf(configMapper.selectByName("book_free_chapter_num").getValue());
+        }
+        if (bookContentVO.getContentId() > freeChapterNum) { //收费
+            //是否已购买
+            long count = consumeMapper.countByExample(ConsumeExample.newAndCreateCriteria()
+                    .andBookIdEqualTo(bookContentVO.getBookId())
+                    .andUserIdEqualTo(bookContentVO.getUserId())
+                    .example()
+            );
+            if (count == 0) { // 没有购买记录
+                User user = userMapper.selectByPrimaryKey(bookContentVO.getUserId());
+                //查询免费看点
+                List<Recharge> recharges = rechargeMapper.selectByExample(
+                        RechargeExample.newAndCreateCriteria()
+                                .andUserIdEqualTo(bookContentVO.getUserId())
+                                .andTypeEqualTo("5") // 免费类型
+                                .andCreatetimeGreaterThan(DateUtils.get3DayAgo())
+                                .example()
+                );
+                Integer freeCount = 0;
+                if (recharges != null) {
+                    freeCount = recharges.stream().mapToInt(x -> x.getFreeKandian()).sum();
+                }
+                //免费是否足够
+                //if (freeCount > )
+                //免费+充值是否足够
+
+            }
 
         }
-        BookContent content = null;
+        //获取章节内容
         if (bookContentVO.getBookId() > 110_0000 && bookContentVO.getBookId() < 110_9999) {
             // 自定义的书籍 TODO
         } else {