BookAuditService.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Modules\Book\Services;
  3. use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
  4. class BookAuditService
  5. {
  6. /**
  7. * 审核数据
  8. * @param $sex
  9. * @param $package
  10. * @return array[]
  11. */
  12. public static function getHomeBooksData($sex, $package): array
  13. {
  14. // 基本配置数据
  15. $home = config('home.default');
  16. if ($package === 'com.app.kyy.jdqyy') {
  17. $home = config('home.new');
  18. }
  19. // banner
  20. $banner = $home['reco_banner'];
  21. $bannerBooks = $banner[$sex];
  22. // 模块
  23. [$hot, $live, $recom, $new] = [$home['hot'], $home['zhibo'], $home['recom'], $home['new_recom']];
  24. [$hotBids, $liveBids, $recomBids, $newBids] = [$hot[$sex], $live[$sex], $recom[$sex], $new[$sex]];
  25. // 一次性获取书籍列表
  26. $bids = array_merge($hotBids, $liveBids, $recomBids, $newBids);
  27. $channel_id = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
  28. $books = BookConfigService::getBookLists(compact('bids','channel_id'));
  29. return [
  30. [
  31. 'type' => 'reco_banner',
  32. 'lable' => $banner['label'],
  33. 'books' => $bannerBooks
  34. ],
  35. [
  36. 'type' => 'hot',
  37. 'lable' => $hot['label'],
  38. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all())
  39. ],
  40. [
  41. 'type' => 'zhibo',
  42. 'lable' => $live['label'],
  43. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all())
  44. ],
  45. [
  46. 'type' => 'recom',
  47. 'lable' => $recom['label'],
  48. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
  49. ],
  50. [
  51. 'type' => 'new_recom',
  52. 'lable' => $new['label'],
  53. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
  54. ],
  55. ];
  56. }
  57. }