BookAuditService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. $books = BookConfigService::getBooksByIds($bids);
  28. return [
  29. [
  30. 'type' => 'reco_banner',
  31. 'lable' => $banner['label'],
  32. 'books' => $bannerBooks
  33. ],
  34. [
  35. 'type' => 'hot',
  36. 'lable' => $hot['label'],
  37. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all())
  38. ],
  39. [
  40. 'type' => 'zhibo',
  41. 'lable' => $live['label'],
  42. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all())
  43. ],
  44. [
  45. 'type' => 'recom',
  46. 'lable' => $recom['label'],
  47. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
  48. ],
  49. [
  50. 'type' => 'new_recom',
  51. 'lable' => $new['label'],
  52. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
  53. ],
  54. ];
  55. }
  56. }