BookAuditService.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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,$is_auth): array
  13. {
  14. // 基本配置数据
  15. $home = config('home.default');
  16. if ($package === 'com.app.kyy.jdqyy') {
  17. $home = config('home.new');
  18. }
  19. if (!$is_auth){
  20. $home = config('home.ycsd');
  21. }
  22. // banner
  23. $banner = $home['reco_banner'];
  24. $bannerBooks = $banner[$sex];
  25. // 模块
  26. [$hot, $live, $recom, $new] = [$home['hot'], $home['zhibo'], $home['recom'], $home['new_recom']];
  27. [$hotBids, $liveBids, $recomBids, $newBids] = [$hot[$sex], $live[$sex], $recom[$sex], $new[$sex]];
  28. // 一次性获取书籍列表
  29. $bids = array_merge($hotBids, $liveBids, $recomBids, $newBids);
  30. $books = BookConfigService::getBooksByIds($bids);
  31. return [
  32. [
  33. 'type' => 'reco_banner',
  34. 'lable' => $banner['label'],
  35. 'books' => $bannerBooks
  36. ],
  37. [
  38. 'type' => 'hot',
  39. 'lable' => $hot['label'],
  40. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all())
  41. ],
  42. [
  43. 'type' => 'zhibo',
  44. 'lable' => $live['label'],
  45. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all())
  46. ],
  47. [
  48. 'type' => 'recom',
  49. 'lable' => $recom['label'],
  50. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
  51. ],
  52. [
  53. 'type' => 'new_recom',
  54. 'lable' => $new['label'],
  55. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
  56. ],
  57. ];
  58. }
  59. }