VideoService.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Modules\Video\Services;
  3. use Illuminate\Support\Facades\DB;
  4. use Modules\Common\Errors\Errors;
  5. use Modules\Common\Exceptions\CommonBusinessException;
  6. class VideoService
  7. {
  8. public static function updateVideoChargeInfo($video, $userContext)
  9. {
  10. if ($userContext['loginUserRoles']->contains('administrator')) {
  11. $video->charge_sequence = $video->d_charge_sequence;
  12. $video->charge_coin = $video->d_charge_coin;
  13. return;
  14. }
  15. if ($userContext['loginUserRoles']->contains('company')) {
  16. if ($userContext['loginUser']->id == $userContext['operateUser']->id) {
  17. $video->charge_sequence = $video->d_charge_sequence;
  18. $video->charge_coin = $video->d_charge_coin;
  19. return;
  20. } else {
  21. $videoUserConfig = self::getVideoUserConfig($userContext['operateUser']->id, $video->id);
  22. $video->charge_sequence = $videoUserConfig->charge_sequence ?? $video->d_charge_sequence;
  23. $video->charge_coin = $videoUserConfig->charge_coin ?? $video->d_charge_coin;
  24. return;
  25. }
  26. }
  27. if ($userContext['loginUserRoles']->contains('optimizer')) {
  28. $videoUserConfig = self::getVideoUserConfig($userContext['loginUser']->id, $video->id);
  29. $video->charge_sequence = $videoUserConfig->charge_sequence ?? $video->d_charge_sequence;
  30. $video->charge_coin = $videoUserConfig->charge_coin ?? $video->d_charge_coin;
  31. return;
  32. }
  33. }
  34. private static function getVideoUserConfig($uid, $videoId)
  35. {
  36. return DB::table('video_user_config')
  37. ->where(['is_enabled' => 1, 'uid' => $uid, 'video_id' => $videoId])->first();
  38. }
  39. /**
  40. * 通过主键查询短剧信息,没有找到抛出异常
  41. * @param $videoId
  42. * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|object|null
  43. */
  44. public static function getVideoByIdOrException($videoId)
  45. {
  46. $video = DB::table('videos')
  47. ->where(['id' => $videoId])
  48. ->first();
  49. if (!$video) {
  50. CommonBusinessException::throwError(Errors::VIDEO_NOT_EXISTS);
  51. }
  52. return $video;
  53. }
  54. }