BookAuditService.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. * @return array
  10. */
  11. public static function getHomeBooksData($sex): array
  12. {
  13. // 基本配置数据
  14. $home = config('home');
  15. // banner
  16. $banner = $home['reco_banner'];
  17. $bannerBooks = $banner[$sex];
  18. // 模块
  19. [$hot, $live, $recom, $new] = [$home['hot'], $home['zhibo'], $home['recom'], $home['new_recom']];
  20. [$hotBids, $liveBids, $recomBids, $newBids] = [$hot[$sex], $live[$sex], $recom[$sex], $new[$sex]];
  21. // 一次性获取书籍列表
  22. $bids = array_merge($hotBids, $liveBids, $recomBids, $newBids);
  23. $books = BookConfigService::getBooksByIds($bids);
  24. return [
  25. [
  26. 'type' => 'reco_banner',
  27. 'lable' => $banner['label'],
  28. 'books' => $bannerBooks
  29. ],
  30. [
  31. 'type' => 'hot',
  32. 'lable' => $hot['label'],
  33. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all())
  34. ],
  35. [
  36. 'type' => 'zhibo',
  37. 'lable' => $live['label'],
  38. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all())
  39. ],
  40. [
  41. 'type' => 'recom',
  42. 'lable' => $recom['label'],
  43. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
  44. ],
  45. [
  46. 'type' => 'new_recom',
  47. 'lable' => $new['label'],
  48. 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
  49. ],
  50. ];
  51. }
  52. }