BookAuditService.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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,$package_id): 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::HomePageRecomBookCheck($hot, $live, $recom, $new,$package_id, $package,$channel);
  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,$package_id): 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] = BookConfigService::HomePageRecomBookCheck($hot, $live, $recom, $new,$package_id, $package,$channel,false);
  78. return array_filter([
  79. ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $bannerBooks],
  80. ['type' => 'hot', 'lable' => '热门书单', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($hotBids,['recommend_index','desc'],false))],
  81. ['type' => 'zhibo', 'lable' => '神书直播', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($liveBids,['recommend_index','desc'],false))],
  82. ['type' => 'recom', 'lable' => '小编精选', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($recomBids,['recommend_index','desc'],false))],
  83. ['type' => 'new_recom', 'lable' => '人气新书', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($newBids,['recommend_index','desc'],false))],
  84. ]);
  85. }
  86. private static function getCheckBooks($bid_list,$channel,$package,$is_author)
  87. {
  88. $hidden_cp = getHiddenCp($package);
  89. // if(!is_public_package($package)){
  90. // $hidden_cp = array_merge($hidden_cp,['lianshang']);
  91. // }
  92. //获取书本数量
  93. $count = count($bid_list);
  94. $where = [
  95. ['book_configs.charge_type','!=','BOOK'],
  96. ];
  97. //获取当前有效书本数量
  98. $book_count = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  99. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  100. ->whereIn('book_configs.bid',$bid_list)
  101. ->whereIn('book_configs.is_on_shelf',[1,2])
  102. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  103. ->where($where)
  104. ->where('book_categories.pid',$channel)
  105. ->count();
  106. if($count == $book_count){
  107. return $bid_list;
  108. }
  109. //获取需要补充的书籍数量
  110. $supplement_count = (($count - $book_count) > 0) ? $count - $book_count : 0;
  111. if($supplement_count <= 0){
  112. return $bid_list;
  113. }
  114. //获取书籍交集bid,过滤掉不符合要求的书
  115. $bids = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  116. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  117. ->whereIn('book_configs.bid',$bid_list)
  118. ->whereIn('book_configs.is_on_shelf',[1,2])
  119. ->where($where)
  120. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  121. ->where('book_categories.pid',$channel)
  122. ->pluck('book_configs.bid')->all();
  123. $bid_list = array_intersect($bid_list,$bids);
  124. //获取随机的有效的书籍bid
  125. $rand_bid = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
  126. ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
  127. ->where('book_configs.is_on_shelf',2)
  128. // ->where('book_configs.charge_type','!=','BOOK')
  129. ->where($where)
  130. ->whereNotIn('book_configs.cp_source',$hidden_cp)
  131. ->where('book_categories.pid',$channel)
  132. ->orderBy('book_configs.recommend_index', 'desc')
  133. ->limit($supplement_count)
  134. ->get()->pluck('bid')->toArray();
  135. return array_filter(array_merge($bid_list,$rand_bid));
  136. }
  137. public static function getHuPoHomeBooksData($channel,$books,$package_id,$package): array
  138. {
  139. $isAuthor = check_qapp_auth($package_id,1);
  140. $hotBids = [65741,65743,65742,65744,66474,66475];
  141. $liveBids = [66476,66477,66479,66480,66631,61596];
  142. $recomBids = QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id);
  143. $newBids = QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id);
  144. [$hotBids, $liveBids, $recomBids, $newBids] = BookConfigService::HomePageRecomBookCheck($hotBids, $liveBids, $recomBids, $newBids,$package_id, $package,$channel,false);
  145. return array_filter([
  146. ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
  147. ['type' => 'hot', 'lable' => '热门书单', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($hotBids,$channel,$package,$isAuthor),[],false))],
  148. ['type' => 'zhibo', 'lable' => '神书直播', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds(self::getCheckBooks($liveBids,$channel,$package,$isAuthor),[],false))],
  149. ['type' => 'recom', 'lable' => '小编精选', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($recomBids))],
  150. ['type' => 'new_recom', 'lable' => '人气新书', 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($newBids))]
  151. ]);
  152. }
  153. public static function getRecommendBooksNew($package_id, $package, $channel, $is_auth, $is_audit)
  154. {
  155. $config = config("home.audit")[$package];
  156. if($config){
  157. if ($channel == 1){
  158. $bids = $config['male'];
  159. }else {
  160. $bids = $config['female'];
  161. }
  162. [$hotBids, $liveBids, $recomBids, $newBids] = array_chunk($bids, 6);
  163. }else{
  164. if ($channel == 1){
  165. return self::getHomeBooksData('male',$package,$is_auth,$package_id);
  166. }else {
  167. return self::getHomeBooksData('female',$package,$is_auth,$package_id);
  168. }
  169. }
  170. [$hotBids, $liveBids, $recomBids, $newBids] = BookConfigService::HomePageRecomBookCheck($hotBids, $liveBids, $recomBids, $newBids,$package_id, $package,$channel);
  171. $list = [];
  172. foreach ($config['labels'] as $key => $v){
  173. $list[] = ['type' => 'rec_'.$key, 'lable' => $v, 'books' => collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($newBids))];
  174. }
  175. return array_filter($list);
  176. }
  177. }