فهرست منبع

阅爱小说男频派单用户增加书籍补全

wangzq 2 سال پیش
والد
کامیت
43578e11ec
2فایلهای تغییر یافته به همراه74 افزوده شده و 10 حذف شده
  1. 1 1
      app/Http/Controllers/QuickApp/Book/BookController.php
  2. 73 9
      app/Modules/Book/Services/BookAuditService.php

+ 1 - 1
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -179,7 +179,7 @@ class BookController extends BaseController
             return response()->success($result);
         }
         if($send_order_id >  0 && $package == "com.beidao.kuaiying.yueai" && $sex == "male"){
-            $result  = BookAuditService::getYueaiHomeBooksData($sex, $package,$isAuth);
+            $result  = BookAuditService::getYueaiHomeBooksData($sex, $package,$isAuth,$channel);
             return  response()->success($result);
         }
         if ($sex == 'male') {

+ 73 - 9
app/Modules/Book/Services/BookAuditService.php

@@ -5,6 +5,7 @@ namespace App\Modules\Book\Services;
 
 
 use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
+use App\Modules\Book\Models\BookConfig;
 
 class BookAuditService
 {
@@ -68,7 +69,7 @@ class BookAuditService
         ];
     }
 
-    public static function getYueaiHomeBooksData($sex, $package,$is_auth): array
+    public static function getYueaiHomeBooksData($sex, $package,$is_auth,$channel): array
     {
         $home = config('home.yueai');
         if (!$is_auth){
@@ -81,10 +82,6 @@ class BookAuditService
         [$hot, $live, $recom, $new] = [$home['hot'], $home['zhibo'], $home['recom'], $home['new_recom']];
         [$hotBids, $liveBids, $recomBids, $newBids] = [$hot[$sex], $live[$sex], $recom[$sex], $new[$sex]];
 
-        // 一次性获取书籍列表
-        $bids  = array_merge($hotBids, $liveBids, $recomBids, $newBids);
-        $channel_id = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
-        $books = BookConfigService::getBookLists(compact('bids','channel_id'),[],false);
         return [
             [
                 'type'  => 'reco_banner',
@@ -94,23 +91,90 @@ class BookAuditService
             [
                 'type'  => 'hot',
                 'lable' => $hot['label'],
-                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all())
+                'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($hotBids,$channel,$package,$is_auth),[],false)),
             ],
             [
                 'type'  => 'zhibo',
                 'lable' => $live['label'],
-                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all())
+                'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($liveBids,$channel,$package,$is_auth),[],false)),
             ],
             [
                 'type'  => 'recom',
                 'lable' => $recom['label'],
-                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
+                // 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
+                 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($recomBids,$channel,$package,$is_auth),[],false)),
+
             ],
             [
                 'type'  => 'new_recom',
                 'lable' => $new['label'],
-                'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
+                // 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
+                'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($newBids,$channel,$package,$is_auth),[],false)),
             ],
         ];
     }
+
+    private function getCheckBooks($bid_list,$channel,$package,$is_author)
+    {
+        $hidden_cp = getHiddenCp();
+        if($package !== 'com.beidao.kuaiying.zsy'){
+            $hidden_cp = array_merge($hidden_cp,['lianshang']);
+        }
+        //获取书本数量
+        $count = count($bid_list);
+        if (!$is_author){
+            $where = [
+                ['book_configs.charge_type','!=','BOOK'],
+                ['book_configs.cp_source','=','ycsd'],
+            ];
+        }else{
+            $where = [
+                ['book_configs.charge_type','!=','BOOK'],
+            ];
+        }
+        //获取当前有效书本数量
+        $book_count = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
+            ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
+            ->whereIn('book_configs.bid',$bid_list)
+            ->where('book_configs.is_on_shelf','in',[1,2])
+            ->where('book_configs.charge_type','!=','BOOK')
+            ->whereNotIn('book_configs.cp_source',$hidden_cp)
+            ->where($where)
+            ->where('book_categories.pid',$channel)
+            ->count();
+
+        if($count == $book_count){
+            return $bid_list;
+        }
+        //获取需要补充的书籍数量
+        $supplement_count = (($count - $book_count) > 0) ? $count - $book_count : 0;
+        if($supplement_count <= 0){
+            return $bid_list;
+        }
+        //获取书籍交集bid,过滤掉不符合要求的书
+        $bids = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
+            ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
+            ->whereIn('book_configs.bid',$bid_list)
+            ->where('book_configs.is_on_shelf','in',[1,2])
+            ->where($where)
+            ->whereNotIn('book_configs.cp_source',$hidden_cp)
+            ->where('book_categories.pid',$channel)
+            ->pluck('book_configs.bid')->all();
+        $bid_list = array_intersect($bid_list,$bids);
+
+        //获取随机的有效的书籍bid
+        $rand_bid = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
+            ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
+            ->where('book_configs.is_on_shelf',2)
+            // ->where('book_configs.charge_type','!=','BOOK')
+            ->where($where)
+            ->whereNotIn('book_configs.cp_source',$hidden_cp)
+
+            ->where('book_categories.pid',$channel)
+            ->inRandomOrder()
+            ->limit($supplement_count)
+            ->get()->pluck('bid')->toArray();
+
+        return array_filter(array_merge($bid_list,$rand_bid));
+    }
 }