123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace App\Service;
- use App\Models\Album;
- use App\Models\Episode;
- use App\Models\Material;
- use App\Models\UserCollect;
- class AlbumService
- {
- public static function albumList($appId, $openId, $keyword, $page, $pageSize) {
- # 查询短剧列表
- list($data, $count) = Album::getList([
- 'app_id' => $appId, 'keyword' => $keyword, 'online_status' => 1
- ], $page, $pageSize);
- # 查询客户收藏状态
- // 提取短剧id
- $albumIdList = array_column($data->toArray(), 'album_id');
- list($collectList, $collectCount) = UserCollect::getUserCollectList($appId, $openId, $albumIdList);
- # 数据格式化
- foreach($data as $info) {
- # 封面图处理
- $coverList = explode(',', $info->cover_list);
- # 根据封面id获取封面url
- $picInfo = Material::getPicList($appId, $coverList);
- $coverInfo = $picInfo->first();
- $info->cover_url = $coverInfo->oss_url ?? '';
- # 追剧状态处理
- $collectInfo = $collectList->where('album_id', $info->album_id)->where('type', 2)->first();
- if(!empty($collectInfo)) {
- $info->collect_status = 1;
- } else {
- $info->collect_status = 0;
- }
- # 播放信息查询
- $playInfo = $collectList->where('album_id', $info->album_id)->where('type', 1)->first();
- $info->seq = $playInfo->seq ?? 1;
- $info->video_url = null;
- $episodeInfo = Episode::getInfo($appId, $info->album_id, $info->seq);
- $openVideoId = $episodeInfo->open_video_id ?? null;
- $info->episode_id = $episodeInfo->episode_id ?? null;
- if(!empty($openVideoId)) {
- $videoInfoList = Material::getVideoList($appId, [$openVideoId]);
- $videoInfo = $videoInfoList->where('open_video_id', $openVideoId)->first();
- $info->video_url = $videoInfo->oss_url ?? null;
- }
- }
- return [$data, $count];
- }
- public static function albumDetail($appId, $openId, $albumId, $page, $pageSize) {
- # 查询短剧基础信息
- $albumInfo = Album::getInfo($appId, $albumId);
- $albumInfo->cover_url = '';
- if(!empty($albumInfo->cover_list)) {
- # 处理短剧封面信息
- $coverList = explode(',', $albumInfo->cover_list);
- # 根据封面id获取封面url
- $picInfo = Material::getPicList($appId, $coverList);
- $coverInfo = $picInfo->first();
- $albumInfo->cover_url = $coverInfo->oss_url ?? '';
- }
- # 查询剧集列表
- list($list, $count) = Episode::getList($appId, $albumId, $page, $pageSize);
- # 批量查询剧集对应的视频播放链接
- $openVideoIdList = array_column($list->toArray(), 'open_video_id');
- $videoList = Material::getVideoList($appId, $openVideoIdList);
- # 查询客户收藏状态
- $albumIdList = [$albumId];
- list($collectList, $collectCount) = UserCollect::getUserCollectList($appId, $openId, $albumIdList);
- # 追剧状态处理
- $collectInfo = $collectList->where('album_id', $albumId)->where('type', 2)->first();
- if(!empty($collectInfo)) {
- $albumInfo->collect_status = 1;
- } else {
- $albumInfo->collect_status = 0;
- }
- # 数据格式化
- foreach($list as $info) {
- # 视频播放链接
- $videoInfo = $videoList->where('open_video_id', $info->open_video_id)->first();
- $info->video_url = $videoInfo->oss_url ?? '';
- # 广告标识
- $info->ad_status = 0;
- $info->ad_type = 2;
- if(!empty($albumInfo->charge_num) && $info->seq >= $albumInfo->charge_num){
- $info->ad_status = 1;
- }
- }
- return [['album_info' => $albumInfo, 'episode_list' => $list], $count];
- }
- }
|