Browse Source

fix:章节列表限免;

Wang Chen 4 years ago
parent
commit
66781bf519

+ 17 - 2
app/Http/Controllers/QuickApp/Book/ChapterController.php

@@ -56,6 +56,9 @@ class ChapterController extends BaseController
 
     private function getChapterCatalog(int $bid, $chapters, $book_info)
     {
+        // 查询书籍是否限免
+        $isFree = BookConfigService::judgeBookIsFree($bid);
+
         switch ($book_info->charge_type) {
             case 'BOOK':
                 $price          = $this->getPrice($book_info);
@@ -63,12 +66,24 @@ class ChapterController extends BaseController
                 foreach ($chapters as $v) {
                     $v->is_need_charge = $v->is_vip ? $is_need_charge : false;
                     $v->price          = $price;
+
+                    // 限免判断
+                    if ($isFree) {
+                        $v->is_need_charge = false;
+                        $v->price          = 0;
+                    }
                 }
                 break;
             default:
                 foreach ($chapters as $v) {
-                    $v->price          = $v->is_vip ? $this->getPrice($book_info, $v->size) : 0;
-                    $v->is_need_charge = $v->is_vip ? $this->isChapterNeedCharge($bid, $v->id, $v->price) : false;
+                    // 限免判断
+                    if ($isFree) {
+                        $v->is_need_charge = false;
+                        $v->price          = 0;
+                    } else {
+                        $v->price          = $v->is_vip ? $this->getPrice($book_info, $v->size) : 0;
+                        $v->is_need_charge = $v->is_vip ? $this->isChapterNeedCharge($bid, $v->id, $v->price) : false;
+                    }
                 }
                 break;
         }

+ 10 - 10
app/Http/Controllers/QuickApp/Book/Transformers/ChapterListTransformer.php

@@ -10,16 +10,16 @@ class ChapterListTransformer
     public function transform($chapter)
     {
         return [
-            'bid'       =>  Hashids::encode($chapter->bid),
-            'chapter_id'       =>  $chapter->id,
-            'chapter_name'   =>  $chapter->name,
-            'chapter_sequence'   =>  $chapter->sequence,
-            'chapter_is_vip'   =>  $chapter->is_vip,
-            'chapter_size'   =>  $chapter->size,
-            'prev_cid'   =>  $chapter->prev_cid,
-            'next_cid'   =>  $chapter->next_cid,
-            'recent_update_at'   =>  $chapter->recent_update_at,
-            'is_need_charge' => $chapter->is_need_charge ? 1 : 0,
+            'bid'              => Hashids::encode($chapter->bid),
+            'chapter_id'       => $chapter->id,
+            'chapter_name'     => $chapter->name,
+            'chapter_sequence' => $chapter->sequence,
+            'chapter_is_vip'   => $chapter->is_vip,
+            'chapter_size'     => $chapter->size,
+            'prev_cid'         => $chapter->prev_cid,
+            'next_cid'         => $chapter->next_cid,
+            'recent_update_at' => $chapter->recent_update_at,
+            'is_need_charge'   => $chapter->is_need_charge ? 1 : 0,
         ];
     }
 }