'reco_banner', 'lable' => $banner['label'], 'books' => $bannerBooks ], [ 'type' => 'hot', 'lable' => $hot['label'], 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all()) ], [ 'type' => 'zhibo', 'lable' => $live['label'], 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all()) ], [ 'type' => 'recom', 'lable' => $recom['label'], 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all()) ], [ 'type' => 'new_recom', 'lable' => $new['label'], 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all()) ], ]; } public static function getYueaiHomeBooksData($sex, $package,$is_auth,$channel): array { $home = config('home.yueai'); if (!$is_auth){ $home = config('home.ycsd'); } $banner = $home['reco_banner']; $bannerBooks = $banner[$sex]; // 模块 [$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]]; return [ [ 'type' => 'reco_banner', 'lable' => $banner['label'], 'books' => $bannerBooks ], [ 'type' => 'hot', 'lable' => $hot['label'], 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($hotBids,$channel,$package,$is_auth),[],false)), ], [ 'type' => 'zhibo', 'lable' => $live['label'], '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, 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, BookConfigService::getBooksByIds(self::getCheckBooks($newBids,$channel,$package,$is_auth),[],false)), ], ]; } private static function getCheckBooks($bid_list,$channel,$package,$is_author) { $hidden_cp = getHiddenCp($package); // if(!is_public_package($package)){ // $hidden_cp = array_merge($hidden_cp,['lianshang']); // } //获取书本数量 $count = count($bid_list); $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) ->whereIn('book_configs.is_on_shelf',[1,2]) ->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) ->whereIn('book_configs.is_on_shelf',[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) ->orderBy('book_configs.recommend_index', 'desc') ->limit($supplement_count) ->get()->pluck('bid')->toArray(); return array_filter(array_merge($bid_list,$rand_bid)); } }