BookAuditService.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace App\Modules\Book\Services;
  3. use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
  4. use App\Modules\Book\Models\BookConfig;
  5. use App\Modules\RecommendBook\Services\QappRecommendService;
  6. class BookAuditService
  7. {
  8. /**
  9. * 审核数据
  10. * @param $sex
  11. * @param $package
  12. * @return array[]
  13. */
  14. public static function getHomeBooksData($sex, $package,$is_auth): array
  15. {
  16. // 基本配置数据
  17. $home = config('home.default');
  18. if ($package === 'com.app.kyy.jdqyy') {
  19. $home = config('home.new');
  20. }
  21. if (!$is_auth){
  22. $home = config('home.ycsd');
  23. }
  24. // banner
  25. $banner = $home['reco_banner'];
  26. $bannerBooks = $banner[$sex];
  27. if ($sex == 'male') {
  28. $channel = 1;
  29. } else {
  30. $channel = 2;
  31. }
  32. // 模块
  33. [$hot, $live, $recom, $new] = [$home['hot'], $home['zhibo'], $home['recom'], $home['new_recom']];
  34. [$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)];
  35. // 一次性获取书籍列表
  36. $bids = array_merge($hotBids, $liveBids, $recomBids, $newBids);
  37. $channel_id = is_public_package($package) ? get_default_public_channel_id() : 0;
  38. $books = BookConfigService::getBookLists(compact('bids','channel_id'));
  39. return [
  40. [
  41. 'type' => 'reco_banner',
  42. 'lable' => $banner['label'],
  43. 'books' => $bannerBooks
  44. ],
  45. [
  46. 'type' => 'hot',
  47. 'lable' => $hot['label'],
  48. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all())
  49. ],
  50. [
  51. 'type' => 'zhibo',
  52. 'lable' => $live['label'],
  53. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all())
  54. ],
  55. [
  56. 'type' => 'recom',
  57. 'lable' => $recom['label'],
  58. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
  59. ],
  60. [
  61. 'type' => 'new_recom',
  62. 'lable' => $new['label'],
  63. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
  64. ],
  65. ];
  66. }
  67. public static function getYueaiHomeBooksData($sex, $package,$is_auth,$channel): array
  68. {
  69. $home = config('home.yueai');
  70. if (!$is_auth){
  71. $home = config('home.ycsd');
  72. }
  73. $banner = $home['reco_banner'];
  74. $bannerBooks = $banner[$sex];
  75. // 模块
  76. [$hot, $live, $recom, $new] = [$home['hot'], $home['zhibo'], $home['recom'], $home['new_recom']];
  77. [$hotBids, $liveBids, $recomBids, $newBids] = [$hot[$sex], $live[$sex], $recom[$sex], $new[$sex]];
  78. return [
  79. [
  80. 'type' => 'reco_banner',
  81. 'lable' => $banner['label'],
  82. 'books' => $bannerBooks
  83. ],
  84. [
  85. 'type' => 'hot',
  86. 'lable' => $hot['label'],
  87. 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($hotBids,$channel,$package,$is_auth),[],false)),
  88. ],
  89. [
  90. 'type' => 'zhibo',
  91. 'lable' => $live['label'],
  92. 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($liveBids,$channel,$package,$is_auth),[],false)),
  93. ],
  94. [
  95. 'type' => 'recom',
  96. 'lable' => $recom['label'],
  97. // 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
  98. 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($recomBids,$channel,$package,$is_auth),[],false)),
  99. ],
  100. [
  101. 'type' => 'new_recom',
  102. 'lable' => $new['label'],
  103. // 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
  104. 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($newBids,$channel,$package,$is_auth),[],false)),
  105. ],
  106. ];
  107. }
  108. private static function getCheckBooks($bid_list,$channel,$package,$is_author)
  109. {
  110. $hidden_cp = getHiddenCp($package);
  111. // if(!is_public_package($package)){
  112. // $hidden_cp = array_merge($hidden_cp,['lianshang']);
  113. // }
  114. //获取书本数量
  115. $count = count($bid_list);
  116. $where = [
  117. ['book_configs.charge_type','!=','BOOK'],
  118. ];
  119. //获取当前有效书本数量
  120. $book_count = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  121. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  122. ->whereIn('book_configs.bid',$bid_list)
  123. ->whereIn('book_configs.is_on_shelf',[1,2])
  124. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  125. ->where($where)
  126. ->where('book_categories.pid',$channel)
  127. ->count();
  128. if($count == $book_count){
  129. return $bid_list;
  130. }
  131. //获取需要补充的书籍数量
  132. $supplement_count = (($count - $book_count) > 0) ? $count - $book_count : 0;
  133. if($supplement_count <= 0){
  134. return $bid_list;
  135. }
  136. //获取书籍交集bid,过滤掉不符合要求的书
  137. $bids = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  138. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  139. ->whereIn('book_configs.bid',$bid_list)
  140. ->whereIn('book_configs.is_on_shelf',[1,2])
  141. ->where($where)
  142. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  143. ->where('book_categories.pid',$channel)
  144. ->pluck('book_configs.bid')->all();
  145. $bid_list = array_intersect($bid_list,$bids);
  146. //获取随机的有效的书籍bid
  147. $rand_bid = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  148. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  149. ->where('book_configs.is_on_shelf',2)
  150. // ->where('book_configs.charge_type','!=','BOOK')
  151. ->where($where)
  152. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  153. ->where('book_categories.pid',$channel)
  154. ->orderBy('book_configs.recommend_index', 'desc')
  155. ->limit($supplement_count)
  156. ->get()->pluck('bid')->toArray();
  157. return array_filter(array_merge($bid_list,$rand_bid));
  158. }
  159. public static function getHuPoHomeBooksData($channel,$books,$package_id,$package): array
  160. {
  161. $isAuthor = check_qapp_auth($package_id,1);
  162. $hotBids = [65741,65743,65742,65744,66474,66475];
  163. $liveBids = [66476,66477,66479,66480,66631,61596];
  164. $recomBids = BookConfigService::getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel,$package,$isAuthor);
  165. $newBids = BookConfigService::getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel,$package,$isAuthor);
  166. return array_filter([
  167. ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
  168. ['type' => 'hot', 'lable' => '热门书单', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($hotBids,$channel,$package,$isAuthor),[],false))],
  169. ['type' => 'zhibo', 'lable' => '神书直播', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($liveBids,$channel,$package,$isAuthor),[],false))],
  170. ['type' => 'recom', 'lable' => '小编精选', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($recomBids))],
  171. ['type' => 'new_recom', 'lable' => '人气新书', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($newBids))]
  172. ]);
  173. }
  174. }