wangzq 2 年之前
父節點
當前提交
1afe9ef39c

+ 26 - 34
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -263,10 +263,10 @@ class BookController extends BaseController
     private function getCheckBids($channel,$books,$package_id,$package)
     {
         $isAuthor = check_qapp_auth($package_id,1);
-        $hotBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel,$package,$isAuthor);
-        $liveBids  = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel,$package,$isAuthor);
-        $recomBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel,$package,$isAuthor);
-        $newBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel,$package,$isAuthor);
+        $hotBids   = BookConfigService::getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel,$package,$isAuthor);
+        $liveBids  = BookConfigService::getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel,$package,$isAuthor);
+        $recomBids = BookConfigService::getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel,$package,$isAuthor);
+        $newBids   = BookConfigService::getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel,$package,$isAuthor);
 
 
         return array_filter([
@@ -305,27 +305,26 @@ class BookController extends BaseController
                 ['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',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;
-        // }
+        //获取当前有效书本数量
+        $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',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;
-        // }
+        $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')
@@ -335,14 +334,8 @@ class BookController extends BaseController
             ->whereNotIn('book_configs.cp_source',$hidden_cp)
             ->where('book_categories.pid',$channel)
             ->pluck('book_configs.bid')->all();
-        // $bid_list = array_intersect($bid_list,$bids);
-        $book_count = count($bids);
-        if ($book_count === $count){
-            return  $bid_list;
-        }
-        $log = ['bid_list',$bid_list,'bids' => $bids];
-        $bid_list = $bids;
-        $supplement_count = $count - $book_count;
+        $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')
@@ -355,8 +348,7 @@ class BookController extends BaseController
             ->inRandomOrder()
             ->limit($supplement_count)
             ->get()->pluck('bid')->toArray();
-            $log['result'] = array_merge($bid_list,$rand_bid);
-            myLog('Qapp_index_bid')->info($log);
+
         return array_filter(array_merge($bid_list,$rand_bid));
     }
 

+ 6 - 1
app/Modules/Book/Services/BookAuditService.php

@@ -30,10 +30,15 @@ class BookAuditService
         // banner
         $banner      = $home['reco_banner'];
         $bannerBooks = $banner[$sex];
+        if ($sex == 'male') {
+            $channel          = 1;
+        } else {
+            $channel          = 2;
+        }
 
         // 模块
         [$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]];
+        [$hotBids, $liveBids, $recomBids, $newBids] = [BookConfigService::getCheckBooks($hot[$sex],$channel,$package,$is_auth),BookConfigService::getCheckBooks($live[$sex],$channel,$package,$is_auth) , BookConfigService::getCheckBooks($recom[$sex],$channel,$package,$is_auth),  BookConfigService::getCheckBooks($new[$sex],$channel,$package,$is_auth)];
 
         // 一次性获取书籍列表
         $bids  = array_merge($hotBids, $liveBids, $recomBids, $newBids);

+ 56 - 0
app/Modules/Book/Services/BookConfigService.php

@@ -271,4 +271,60 @@ class BookConfigService
         return $res->pluck("bid")->toArray();
     }
 
+    /***
+     *  推荐位书籍检测和补齐
+     * name: getCheckBooks
+     * @param $bid_list
+     * @param $channel
+     * @param $package
+     * @param $is_author
+     * @return mixed
+     * date 2022/10/26 10:11
+     */
+    public  static  function getCheckBooks($bid_list,$channel,$package,$is_author)
+    {
+        $hidden_cp = getHiddenCp();
+        if(!is_public_package($package)){
+            $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'],
+            ];
+        }
+
+        //获取书籍交集bid,过滤掉不符合要求的书
+        $bid_list = 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',2)
+            ->where($where)
+            ->whereNotIn('book_configs.cp_source',$hidden_cp)
+            ->where('book_categories.pid',$channel)
+            ->pluck('book_configs.bid')->all();
+
+        $book_count = count($bid_list);
+        if ($book_count === $count){
+            return  $bid_list;
+        }
+        $supplement_count = $count - $book_count;
+        //获取随机的有效的书籍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($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));
+    }
 }