LiveController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. public function users()
  31. {
  32. $params =request()->post();
  33. $pageSize = request()->post('pageSize', 15);
  34. $datas = LiveService::make()->getUserList($params, $pageSize, $this->userId);
  35. return message(1010, true, $datas);
  36. }
  37. /**
  38. * 播放与浏览
  39. * @return array
  40. */
  41. public function updatePlay()
  42. {
  43. $id = request()->post('id',0);
  44. if(!$result = LiveService::make()->updatePlay($this->userId, $id)){
  45. return message(LiveService::make()->getError(), false);
  46. }else{
  47. return message(LiveService::make()->getError(), true, $result);
  48. }
  49. }
  50. /**
  51. * 获取流地址
  52. * @return array
  53. */
  54. public function getUrl()
  55. {
  56. $urls = LiveService::make()->getLiveUrl($this->userId);
  57. return message(1010, true, $urls);
  58. }
  59. /**
  60. * 直播详情
  61. * @param LiveValidator $validator
  62. * @return array
  63. */
  64. public function getInfo(LiveValidator $validator)
  65. {
  66. $params = request()->all();
  67. $params = $validator->check($params, 'info');
  68. if (!is_array($params)) {
  69. return message($params, false);
  70. }
  71. if(!$info = LiveService::make()->getInfo($params['id'], $this->userId)){
  72. return message(LiveService::make()->getError(),false);
  73. }else{
  74. return message(1010,true, $info);
  75. }
  76. }
  77. /**
  78. * 状态
  79. * @return array|mixed
  80. */
  81. public function status()
  82. {
  83. if(!$result = LiveService::make()->status()){
  84. return message(LiveService::make()->getError(), false);
  85. }else{
  86. return message(LiveService::make()->getError(), true, $result);
  87. }
  88. }
  89. /**
  90. * 创建直播间(开启直播)
  91. * @return array
  92. */
  93. public function create(LiveValidator $validator)
  94. {
  95. $params = request()->all();
  96. $params = $validator->check($params, 'create');
  97. if (!is_array($params)) {
  98. return message($params, false);
  99. }
  100. if(!$result = LiveService::make()->create($this->userId, $params)){
  101. return message(LiveService::make()->getError(),false);
  102. }else{
  103. return message(LiveService::make()->getError(),true, $result);
  104. }
  105. }
  106. }