lishiyeaaron 5 yıl önce
ebeveyn
işleme
d4a73c0f2a

+ 2 - 0
app/Http/Controllers/QuickApp/User/Transformers/UserShelfBooksTransformer.php

@@ -19,6 +19,8 @@ class UserShelfBooksTransformer
             'updated_at' => strtotime($userShelfBook->updated_at),
             'first_cid' => $userShelfBook->first_cid,
             'last_cid' => $userShelfBook->last_cid,
+            'last_chapter' => $userShelfBook->last_chapter,
+            'recent_reading_chapter' => $userShelfBook->recent_reading_chapter,
         ];
     }
 }

+ 28 - 5
app/Http/Controllers/QuickApp/User/UserShelfBooksController.php

@@ -6,6 +6,7 @@ use Illuminate\Http\Request;
 use App\Http\Controllers\QuickApp\BaseController;
 use Redis;
 use App\Modules\Book\Services\UserShelfBooksService;
+use App\Modules\Book\Services\ChapterService;
 use App\Http\Controllers\QuickApp\User\Transformers\UserShelfBooksTransformer;
 use App\Modules\User\Services\ReadRecordService;
 use Hashids;
@@ -36,7 +37,9 @@ class UserShelfBooksController extends BaseController
      * @apiSuccess {Int}         data.bid   bid
      * @apiSuccess {Int}         data.book_name   书名
      * @apiSuccess {Int}         data.cover   封面
-     * @apiSuccess {Int}         data.last_cid   章节id
+     * @apiSuccess {Int}         data.last_cid   最后章节id
+     * @apiSuccess {String}      data.last_chapter  最新章节
+     * @apiSuccess {String}      data.last_chapter  最近阅读章节
      * @apiSuccessExample {json} Success-Response:
      *     HTTP/1.1 200 OK
      *     {
@@ -52,7 +55,10 @@ class UserShelfBooksController extends BaseController
      *                   book_name: "京华烟云",
      *                   cover: "https://leyue-bucket.oss-cn-hangzhou.aliyuncs.com/ycsd_cover/covermiddle/0/1.jpg",
      *                   updated_at: 1511783068,
-     *                   last_cid: 4
+     *                   last_cid: 4,
+     *                   last_chapter:"最新 第122章 大事不妙",
+     *                   recent_reading_chapter:"最近阅读:第5章 又来?"
+     *
      *               },
      *               {
      *                   id: 7,
@@ -62,7 +68,9 @@ class UserShelfBooksController extends BaseController
      *                   book_name: "我来好好爱你",
      *                   cover: "https://leyue-bucket.oss-cn-hangzhou.aliyuncs.com/ycsd_cover/covermiddle/0/11.jpg",
      *                   updated_at: 1511783068,
-     *                   last_cid: 4
+     *                   last_cid: 4,
+     *                   last_chapter:"最新 第2556章 又来了个张老三",
+     *                   recent_reading_chapter:"最近阅读:第2551章 又来了个猪八戒"
      *               }
      *           ]
      *       }
@@ -73,12 +81,27 @@ class UserShelfBooksController extends BaseController
             return response()->success();
         }
         $record = ReadRecordService::getReadRecord($this->uid);
+//        $record=array([
+//            'bid'=>1,
+//            'time'=>3,
+//            'cid'=>4,
+//        ],[
+//            'bid'=>2,
+//            'time'=>3,
+//            'cid'=>4,
+//        ]);
         foreach ($res as &$v){
-            $v['last_cid'] = $v['first_cid'];
+            $bid=$v['bid'];
+            $last_cid = $v['last_cid'];
+            $last_chapter = ChapterService::getChapterNameById($last_cid,$bid);
+            $v['last_chapter']="最后章节:第{$last_cid}章 {$last_chapter['name']}";
             foreach ($record as $val){
                 if($v['bid'] == $val['bid']){
                     $v['updated_at'] = $val['time'];
-                    $v['last_cid'] = $val['cid'];
+                    $recent_reading_cid = $val['cid'];
+//                    dd($recent_reading_cid);
+                    $recent_reading_chapter = ChapterService::getChapterNameById($recent_reading_cid,$bid);
+                    $v['recent_reading_chapter'] = "最近阅读:第{$recent_reading_cid}章 {$recent_reading_chapter['name']}";
                     break;
                 }
             }

+ 1 - 1
app/Modules/Book/Models/UserShelfBooks.php

@@ -30,7 +30,7 @@ class UserShelfBooks extends Model
             ->join('books','user_shelf_books.bid','=','books.id')
             ->select('book_configs.cover','book_configs.book_name','user_shelf_books.bid',
                 'user_shelf_books.distribution_channel_id','user_shelf_books.bid','user_shelf_books.id',
-                'user_shelf_books.uid','user_shelf_books.updated_at','books.first_cid'
+                'user_shelf_books.uid','user_shelf_books.updated_at','books.first_cid','books.last_cid as last_cid'
             )->orderBy('user_shelf_books.id','desc');
 
         if($is_all)