BookAuditService.php 8.6 KB

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