LiveController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\LiveValidator;
  5. use App\Services\LiveService;
  6. use App\Services\RedisService;
  7. /**
  8. * 在线直播
  9. * @package App\Http\Controllers\Api\v1
  10. */
  11. class LiveController extends webApp
  12. {
  13. /**
  14. * 列表
  15. * @return array
  16. */
  17. public function index()
  18. {
  19. try {
  20. $params = request()->post();
  21. $pageSize = request()->post('pageSize', 0);
  22. $params['is_recommend'] = 1;
  23. $datas = LiveService::make()->getDataList($params, $pageSize,'', $this->userId);
  24. return message(1010, true, $datas);
  25. } catch (\Exception $exception){
  26. RedisService::set("caches:request:error_live_index", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  27. return message(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  28. }
  29. }
  30. /**
  31. * 播放与浏览
  32. * @return array
  33. */
  34. public function updatePlay()
  35. {
  36. $id = request()->post('id',0);
  37. if(!$result = LiveService::make()->updatePlay($this->userId, $id)){
  38. return message(LiveService::make()->getError(), false);
  39. }else{
  40. return message(LiveService::make()->getError(), true, $result);
  41. }
  42. }
  43. /**
  44. * 获取流地址
  45. * @return array
  46. */
  47. public function getUrl()
  48. {
  49. $urls = LiveService::make()->getLiveUrl($this->userId);
  50. return message(1010, true, $urls);
  51. }
  52. /**
  53. * 直播详情
  54. * @param LiveValidator $validator
  55. * @return array
  56. */
  57. public function getInfo(LiveValidator $validator)
  58. {
  59. $params = request()->all();
  60. $params = $validator->check($params, 'info');
  61. if (!is_array($params)) {
  62. return message($params, false);
  63. }
  64. if(!$info = LiveService::make()->getInfo($params['id'], $this->userId)){
  65. return message(LiveService::make()->getError(),false);
  66. }else{
  67. return message(1010,true, $info);
  68. }
  69. }
  70. /**
  71. * 状态
  72. * @return array|mixed
  73. */
  74. public function status()
  75. {
  76. if(!$result = LiveService::make()->status()){
  77. return message(LiveService::make()->getError(), false);
  78. }else{
  79. return message(LiveService::make()->getError(), true, $result);
  80. }
  81. }
  82. /**
  83. * 创建直播间(开启直播)
  84. * @return array
  85. */
  86. public function create(LiveValidator $validator)
  87. {
  88. $params = request()->all();
  89. $params = $validator->check($params, 'create');
  90. if (!is_array($params)) {
  91. return message($params, false);
  92. }
  93. if(!$result = LiveService::make()->create($this->userId, $params)){
  94. return message(LiveService::make()->getError(),false);
  95. }else{
  96. return message(LiveService::make()->getError(),true, $result);
  97. }
  98. }
  99. }