抖音小程序

AlbumService.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Service;
  3. use App\Models\Album;
  4. use App\Models\Episode;
  5. use App\Models\Material;
  6. use App\Models\UserCollect;
  7. class AlbumService
  8. {
  9. public static function albumList($appId, $openId, $keyword, $page, $pageSize) {
  10. # 查询短剧列表
  11. list($data, $count) = Album::getList([
  12. 'app_id' => $appId, 'keyword' => $keyword, 'online_status' => 1
  13. ], $page, $pageSize);
  14. # 查询客户收藏状态
  15. // 提取短剧id
  16. $albumIdList = array_column($data->toArray(), 'album_id');
  17. list($collectList, $collectCount) = UserCollect::getUserCollectList($appId, $openId, $albumIdList);
  18. # 数据格式化
  19. foreach($data as $info) {
  20. # 封面图处理
  21. $coverList = explode(',', $info->cover_list);
  22. # 根据封面id获取封面url
  23. $picInfo = Material::getPicList($appId, $coverList);
  24. $coverInfo = $picInfo->first();
  25. $info->cover_url = $coverInfo->oss_url ?? '';
  26. # 追剧状态处理
  27. $collectInfo = $collectList->where('album_id', $info->album_id)->where('type', 2)->first();
  28. if(!empty($collectInfo)) {
  29. $info->collect_status = 1;
  30. } else {
  31. $info->collect_status = 0;
  32. }
  33. # 播放信息查询
  34. $playInfo = $collectList->where('album_id', $info->album_id)->where('type', 1)->first();
  35. $info->seq = $playInfo->seq ?? 1;
  36. $info->video_url = null;
  37. $episodeInfo = Episode::getInfo($appId, $info->album_id, $info->seq);
  38. $openVideoId = $episodeInfo->open_video_id ?? null;
  39. $info->episode_id = $episodeInfo->episode_id ?? null;
  40. if(!empty($openVideoId)) {
  41. $videoInfoList = Material::getVideoList($appId, [$openVideoId]);
  42. $videoInfo = $videoInfoList->where('open_video_id', $openVideoId)->first();
  43. $info->video_url = $videoInfo->oss_url ?? null;
  44. }
  45. }
  46. return [$data, $count];
  47. }
  48. public static function albumDetail($appId, $openId, $albumId, $page, $pageSize) {
  49. # 查询短剧基础信息
  50. $albumInfo = Album::getInfo($appId, $albumId);
  51. $albumInfo->cover_url = '';
  52. if(!empty($albumInfo->cover_list)) {
  53. # 处理短剧封面信息
  54. $coverList = explode(',', $albumInfo->cover_list);
  55. # 根据封面id获取封面url
  56. $picInfo = Material::getPicList($appId, $coverList);
  57. $coverInfo = $picInfo->first();
  58. $albumInfo->cover_url = $coverInfo->oss_url ?? '';
  59. }
  60. # 查询剧集列表
  61. list($list, $count) = Episode::getList($appId, $albumId, $page, $pageSize);
  62. # 批量查询剧集对应的视频播放链接
  63. $openVideoIdList = array_column($list->toArray(), 'open_video_id');
  64. $videoList = Material::getVideoList($appId, $openVideoIdList);
  65. # 查询客户收藏状态
  66. $albumIdList = [$albumId];
  67. list($collectList, $collectCount) = UserCollect::getUserCollectList($appId, $openId, $albumIdList);
  68. # 追剧状态处理
  69. $collectInfo = $collectList->where('album_id', $albumId)->where('type', 2)->first();
  70. if(!empty($collectInfo)) {
  71. $albumInfo->collect_status = 1;
  72. } else {
  73. $albumInfo->collect_status = 0;
  74. }
  75. # 数据格式化
  76. foreach($list as $info) {
  77. # 视频播放链接
  78. $videoInfo = $videoList->where('open_video_id', $info->open_video_id)->first();
  79. $info->video_url = $videoInfo->oss_url ?? '';
  80. # 广告标识
  81. $info->ad_status = 0;
  82. $info->ad_type = 2;
  83. if(!empty($albumInfo->charge_num) && $info->seq >= $albumInfo->charge_num){
  84. $info->ad_status = 1;
  85. }
  86. }
  87. return [['album_info' => $albumInfo, 'episode_list' => $list], $count];
  88. }
  89. }