12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Modules\Book\Services;
- use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
- class BookAuditService
- {
- /**
- * 审核数据
- * @param $sex
- * @return array
- */
- public static function getHomeBooksData($sex): array
- {
- // 基本配置数据
- $home = config('home');
- // banner
- $banner = $home['reco_banner'];
- $bannerBooks = $banner[$sex];
- // 模块
- [$hot, $live, $recom, $new] = [$home['hot'], $home['zhibo'], $home['recom'], $home['new_recom']];
- [$hotBids, $liveBids, $recomBids, $newBids] = [$hot[$sex], $live[$sex], $recom[$sex], $new[$sex]];
- // 一次性获取书籍列表
- $bids = array_merge($hotBids, $liveBids, $recomBids, $newBids);
- $books = BookConfigService::getBooksByIds($bids);
- return [
- [
- 'type' => 'reco_banner',
- 'lable' => $banner['label'],
- 'books' => $bannerBooks
- ],
- [
- 'type' => 'hot',
- 'lable' => $hot['label'],
- 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $hotBids)->all())
- ],
- [
- 'type' => 'zhibo',
- 'lable' => $live['label'],
- 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $liveBids)->all())
- ],
- [
- 'type' => 'recom',
- 'lable' => $recom['label'],
- 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $recomBids)->all())
- ],
- [
- 'type' => 'new_recom',
- 'lable' => $new['label'],
- 'books' => collectionTransform(new BookTransformer, collect($books)->whereIn('bid', $newBids)->all())
- ],
- ];
- }
- }
|