LiveController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 showJson(1010, true, $datas);
  25. } catch (\Exception $exception){
  26. RedisService::set("caches:request:error_live_index", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  27. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  28. }
  29. }
  30. /**
  31. * 在线用户数据
  32. * @return array
  33. */
  34. public function users()
  35. {
  36. $params =request()->post();
  37. $pageSize = request()->post('pageSize', 15);
  38. $datas = LiveService::make()->getUserList($params, $pageSize, $this->userId);
  39. return showJson(1010, true, $datas);
  40. }
  41. /**
  42. * 礼物列表
  43. * @return array
  44. */
  45. public function giftList()
  46. {
  47. $params =request()->post();
  48. $pageSize = request()->post('pageSize', 15);
  49. $datas = LiveService::make()->getGiftList($params, $pageSize, $this->userId);
  50. return showJson(1010, true, $datas);
  51. }
  52. /**
  53. * 播放与浏览
  54. * @return array
  55. */
  56. public function updatePlay()
  57. {
  58. $id = request()->post('id',0);
  59. if(!$result = LiveService::make()->updatePlay($this->userId, $id)){
  60. return showJson(LiveService::make()->getError(), false);
  61. }else{
  62. return showJson(LiveService::make()->getError(), true, $result);
  63. }
  64. }
  65. /**
  66. * 获取流地址
  67. * @return array
  68. */
  69. public function getUrl()
  70. {
  71. $urls = LiveService::make()->getLiveUrl($this->userId);
  72. return showJson(1010, true, $urls);
  73. }
  74. /**
  75. * 直播详情
  76. * @param LiveValidator $validator
  77. * @return array
  78. */
  79. public function getInfo(LiveValidator $validator)
  80. {
  81. $params = request()->all();
  82. $params = $validator->check($params, 'info');
  83. if (!is_array($params)) {
  84. return showJson($params, false);
  85. }
  86. if(!$info = LiveService::make()->getInfo($params['id'], $this->userId)){
  87. return showJson(LiveService::make()->getError(),false);
  88. }else{
  89. return showJson(1010,true, $info);
  90. }
  91. }
  92. /**
  93. * 状态
  94. * @return array|mixed
  95. */
  96. public function status()
  97. {
  98. if(!$result = LiveService::make()->status()){
  99. return showJson(LiveService::make()->getError(), false);
  100. }else{
  101. return showJson(LiveService::make()->getError(), true, $result);
  102. }
  103. }
  104. /**
  105. * 点赞
  106. * @return array|mixed
  107. */
  108. public function like()
  109. {
  110. $params = request()->post();
  111. if(!$result = LiveService::make()->like($this->userId, $params)){
  112. return showJson(LiveService::make()->getError(), false);
  113. }else{
  114. return showJson(LiveService::make()->getError(), true, $result);
  115. }
  116. }
  117. /**
  118. * 创建直播间(开启直播)
  119. * @return array
  120. */
  121. public function create(LiveValidator $validator)
  122. {
  123. $params = request()->all();
  124. $params = $validator->check($params, 'create');
  125. if (!is_array($params)) {
  126. return showJson($params, false);
  127. }
  128. if(!$result = LiveService::make()->create($this->userId, $params)){
  129. return showJson(LiveService::make()->getError(),false);
  130. }else{
  131. return showJson(LiveService::make()->getError(),true, $result);
  132. }
  133. }
  134. /**
  135. * 礼物打赏
  136. * @return array
  137. */
  138. public function reward()
  139. {
  140. $params = request()->all();
  141. if(!$result = LiveService::make()->reward($this->userId, $params)){
  142. return showJson(LiveService::make()->getError(),false);
  143. }else{
  144. return showJson(LiveService::make()->getError(),true, $result);
  145. }
  146. }
  147. }