fly 5 jaren geleden
bovenliggende
commit
e34e153e96

+ 7 - 0
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -14,6 +14,7 @@ use App\Modules\Book\Services\UserShelfBooksService;
 use App\Modules\Book\Services\ChapterService;
 use App\Modules\Subscribe\Services\BookOrderService;
 use App\Modules\Subscribe\Services\ChapterOrderService;
+use App\Modules\User\Services\ReadRecordService;
 use Hashids;
 use Log;
 
@@ -114,6 +115,12 @@ class BookController extends BaseController
         $last_chapter = ChapterService::getChapterNameById($book_info['last_cid'], $bid);
         $book_info['last_chapter_is_vip'] = $last_chapter['is_vip'];
         $book_info['is_need_charge'] = $this->isNeedCharge($bid, $last_chapter, $book_info);
+        $record = ReadRecordService::getBookReadRecordStatic($this->uid, $bid);
+        if($record)
+        {
+            $book_info['record_chapter_id'] = $record['record_chapter_id'];
+            $book_info['record_chapter_name'] = $record['record_chapter_name'];
+        }
         return response()->item(new BookTransformer(), $book_info);
     }
 

+ 2 - 0
app/Http/Controllers/QuickApp/Book/Transformers/BookTransformer.php

@@ -44,6 +44,8 @@ class BookTransformer
             'is_on_user_shelf' => $book->is_on_user_shelf,
             'last_chapter_is_vip' => $book->last_chapter_is_vip,
             'is_need_charge' => $book->is_need_charge ? 1 : 0,
+            'record_chapter_id' => $book->record_chapter_id,
+            'record_chapter_name' => $book->record_chapter_name,
         ];
     }
 }

+ 30 - 26
app/Modules/User/Services/ReadRecordService.php

@@ -19,11 +19,24 @@ use DB;
 
 /**
  * @method static delReadRecordStatic(int $uid, array $bids) 删除最近阅读记录
+ * @method static getBookReadRecordStatic(int $uid, int $bid) 获取单本书籍的最近阅读记录
  */
 class ReadRecordService
 {
     #region 以后按照这种方式写静态方法
     use BaseService;
+
+    public function getBookReadRecord(int $uid, int $bid)
+    {
+        $record = Redis::hGet('book_read:' . $uid, $bid);
+        if ($record) {
+            $cid = explode('_', $record)[1];
+            $name = self::cid2ChapterName($cid);
+            return ['record_chapter_id' => $cid, 'record_chapter_name' => $name];
+        }
+        return false;
+    }
+
     /**
      * 删除最近阅读记录
      * @param int $uid
@@ -165,7 +178,7 @@ class ReadRecordService
 
     /**
      * 添加阅读记录升级版
-     * @param $param
+     * @param array $param
      */
     public static function addReadRecord($param)
     {
@@ -228,7 +241,6 @@ class ReadRecordService
     public static function getFirstReadRecord($uid)
     {
         self::delBookBase($uid);
-        //Redis::hget('book_base:' . $uid, 'last_read', "{$bid}_{$cid}_{$book_name}_{$chapter_name}_" . time());
         $record = Redis::hget('book_read:' . $uid, 'last_read');
         if ($record) {
             $record_arr = explode('_', $record);
@@ -295,20 +307,16 @@ class ReadRecordService
      */
     public static function bid2BookName($bid)
     {
-        $book_name = null;
-        if (is_null($book_name)) {
-            $book_key = 'wap:string:book:' . $bid;
-            $book_name = Redis::get($book_key);
-            Redis::EXPIRE($book_key, 3600);
-            if (!$book_name) {
-                $book_name = '';
-                $book_info = BookConfigService::getBookById($bid);
-                if ($book_info && isset($book_info->book_name)) {
-                    $book_name = $book_info->book_name;
-                }
+        $book_key = 'wap:string:book:' . $bid;
+        $book_name = Redis::get($book_key);
+        Redis::EXPIRE($book_key, 3600);
+        if (!$book_name) {
+            $book_name = '';
+            $book_info = BookConfigService::getBookById($bid);
+            if ($book_info && isset($book_info->book_name)) {
+                $book_name = $book_info->book_name;
             }
         }
-        return $book_name;
     }
 
     /**
@@ -318,17 +326,14 @@ class ReadRecordService
      */
     public static function cid2ChapterName($cid)
     {
-        $chapter_name = null;
-        if (is_null($chapter_name)) {
-            $chapter_key = 'wap:string:chapter:' . $cid;
-            $chapter_name = Redis::get($chapter_key);
-            Redis::EXPIRE($chapter_key, 3600);
-            if (!$chapter_name) {
-                $chapter_name = '';
-                $chapter_info = Chapter::getChapterNameById($cid);
-                if ($chapter_info && isset($chapter_info->name)) {
-                    $chapter_name = $chapter_info->name;
-                }
+        $chapter_key = 'wap:string:chapter:' . $cid;
+        $chapter_name = Redis::get($chapter_key);
+        Redis::EXPIRE($chapter_key, 3600);
+        if (!$chapter_name) {
+            $chapter_name = '';
+            $chapter_info = Chapter::getChapterNameById($cid);
+            if ($chapter_info && isset($chapter_info->name)) {
+                $chapter_name = $chapter_info->name;
             }
         }
         return $chapter_name;
@@ -341,7 +346,6 @@ class ReadRecordService
      */
     public static function delBookNameAndChapter($uid)
     {
-        //Redis::hset('book_base:' . $uid, 'last_read', "{$bid}_{$cid}_{$book_name}_{$chapter_name}_" . time()) ;
         $base_record = Redis::hget('book_base:' . $uid, 'last_read');
         if ($base_record) {
             $record_arr = explode('_', $base_record);