123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Modules\Channel\Services;
- use App\Modules\Book\Services\BookConfigService;
- use App\Modules\Channel\Models\ChannelRecommendBooks;
- class ChannelRecommendBooksService
- {
- static function getChannelBid($channel_id)
- {
- return ChannelRecommendBooks::leftjoin('book_configs','book_configs.bid','channel_recommend_books.bid')
- ->where('channel_recommend_books.channel_id',$channel_id)
- ->whereNotIn('book_configs.cp_source',getHiddenCp())
- ->whereIn('book_configs.is_on_shelf',[1,2])
- ->orderBy('channel_recommend_books.priority','DESC')
- ->orderBy('channel_recommend_books.created_at','DESC')
- ->pluck('channel_recommend_books.bid')->all();
- }
- static function getMergerBids($channel_id,$bid)
- {
- $bids = self::getChannelBid($channel_id);
- if(isset($bid) && $bid != 0){
- $key = array_keys($bids,$bid);
- if(!empty($key)){
- $value = 1;
- if(isset($bids[$key[0]+1])){
- $bidArr[] = $bids[$key[0]+1];
- }else{
- $bidArr[] = $bids[$value];
- $value += 1;
- }
- if(isset($bids[$key[0]+2])){
- $bidArr[] = $bids[$key[0]+2];
- }else{
- $bidArr[] = $bids[$value-1];
- $value += 1;
- }
- if(isset($bids[$key[0]+3])){
- $bidArr[] = $bids[$key[0]+3];
- }else{
- $bidArr[] = $bids[$value-1];
- }
- }else{
- $bidArr = [$bids[0],$bids[1],$bids[2]];
- }
- }else{
- $bidArr = [$bids[0],$bids[1],$bids[2]];
- }
- return $bidArr;
- }
- static function getRecommendBooks($channel_id,$bid = 0)
- {
- $bids = self::getMergerBids($channel_id,$bid);
- if(!isset($channel_id)) return [];
- return BookConfigService::getBooksByIds($bids,[],false);
- // $query = ChannelRecommendBooks::leftjoin('book_configs','book_configs.bid','channel_recommend_books.bid')
- // ->leftjoin('books','books.id','channel_recommend_books.bid')
- // ->select('books.intro','books.category_name','book_configs.book_name','book_configs.cover','book_configs.bid','channel_recommend_books.priority')
- // ->orderBy('channel_recommend_books.priority','DESC')->orderBy('channel_recommend_books.created_at','DESC');
- //
- // $query->where('channel_recommend_books.channel_id',$channel_id)
- // ->whereIn('channel_recommend_books.bid',$bids);
- //
- //
- // return $query->get()->toArray();
- }
- static function incrRecommendNum($channel_id,$bids)
- {
- return ChannelRecommendBooks::where('channel_id',$channel_id)->whereIn('bid',$bids)->increment('recommend_num');
- }
- }
|