1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Modules\Book\Services;
- use App\Http\Controllers\QuickApp\Book\Transformers\BookTransformer;
- class BookAuditService
- {
- /**
- * 审核数据
- * @param $sex
- * @param $package
- * @return array[]
- */
- public static function getHomeBooksData($sex, $package): array
- {
- // 基本配置数据
- $home = config('home.default');
- if ($package === 'com.app.kyy.jdqyy') {
- $home = config('home.new');
- }
- // 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())
- ],
- ];
- }
- }
|