Bladeren bron

'补充男女频筛选'

zhuchengjie 3 jaren geleden
bovenliggende
commit
c36328adc3
1 gewijzigde bestanden met toevoegingen van 21 en 8 verwijderingen
  1. 21 8
      app/Http/Controllers/QuickApp/Book/BookController.php

+ 21 - 8
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -236,10 +236,10 @@ class BookController extends BaseController
      */
     private function getCheckBids($channel,$books,$package_id)
     {
-        $hotBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id));
-        $liveBids  = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id));
-        $recomBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id));
-        $newBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id));
+        $hotBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel);
+        $liveBids  = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel);
+        $recomBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel);
+        $newBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel);
 
         return array_filter([
             ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
@@ -252,16 +252,22 @@ class BookController extends BaseController
     }
 
     /**
-     * 补充不满足条件的书籍id
+     * 检测并补充不满足条件的书籍id
      * @param $bid_list
+     * @param $channel : 频道
      * @return array
      */
-    private function getCheckBooks($bid_list)
+    private function getCheckBooks($bid_list,$channel)
     {
         //获取书本数量
         $count = count($bid_list);
         //获取当前有效书本数量
-        $book_count = BookConfig::whereIn('bid',$bid_list)->whereNotIn('cp_source',getHiddenCp())->count();
+        $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)
+            ->whereNotIn('book_configs.cp_source',getHiddenCp())
+            ->where('book_categories.pid',$channel)
+            ->count();
         if($count == $book_count){
             return $bid_list;
         }
@@ -269,7 +275,14 @@ class BookController extends BaseController
         $supplement_count = (($count - $book_count) > 0) ? $count - $book_count : 0;
 
         //获取随机的有效的书籍bid
-        $rand_bid = BookConfig::where('is_on_shelf',1)->whereNotIn('cp_source',getHiddenCp())->inRandomOrder()->limit($supplement_count)->get()->pluck('bid')->toArray();
+        $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',1)
+            ->whereNotIn('book_configs.cp_source',getHiddenCp())
+            ->inRandomOrder()
+            ->limit($supplement_count)
+            ->where('book_categories.pid',$channel)
+            ->get()->pluck('book_configs.bid')->toArray();
 
         return array_merge($bid_list,$rand_bid);
     }