VideoController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\VideoCollectService;
  5. use App\Services\Api\VideoService;
  6. use App\Services\RedisService;
  7. use Illuminate\Http\Request;
  8. /**
  9. * 短视频服务管理
  10. * @package App\Http\Controllers\Api
  11. */
  12. class VideoController extends webApp
  13. {
  14. /**
  15. * 列表
  16. * @return array
  17. */
  18. public function index()
  19. {
  20. try {
  21. $params = request()->post();
  22. $pageSize = request()->post('pageSize', 0);
  23. $params['is_recommend'] = 1;
  24. $datas = VideoService::make()->getIndexList($params, $pageSize,'', $this->userId);
  25. return showJson(1010, true, $datas);
  26. } catch (\Exception $exception){
  27. RedisService::set("caches:request:error_video_index", ['error'=>$exception->getshowJson(),'trace'=>$exception->getTrace()], 7200);
  28. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getshowJson() : '']);
  29. }
  30. }
  31. /**
  32. * 列表
  33. * @return array
  34. */
  35. public function list()
  36. {
  37. try {
  38. $params = request()->post();
  39. $pageSize = request()->post('pageSize', 0);
  40. $type = request()->post('type', 1);
  41. // 我的视频
  42. $datas = [];
  43. if($type == 1){
  44. $datas = VideoService::make()->getDataList($params, $pageSize,'', $this->userId);
  45. }
  46. // 喜欢的视频
  47. else if ($type == 2){
  48. }
  49. // 收藏的视频
  50. else if ($type == 3){
  51. }
  52. // 观看历史
  53. else if ($type == 4){
  54. }
  55. return showJson(1010, true, $datas);
  56. } catch (\Exception $exception){
  57. RedisService::set("caches:request:error_video_list", ['error'=>$exception->getshowJson(),'trace'=>$exception->getTrace()], 7200);
  58. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getTrace() : '']);
  59. }
  60. }
  61. /**
  62. * 详情
  63. * @return array
  64. */
  65. public function info()
  66. {
  67. $id = request()->post('id', 0);
  68. $info = VideoService::make()->getInfo($id, $this->userId);
  69. return showJson(1010, true, $info);
  70. }
  71. /**
  72. * 发布
  73. * @return array
  74. */
  75. public function publish(Request $request)
  76. {
  77. $params = request()->all();
  78. if(!$result = VideoService::make()->publish($this->userId, $params, $request)){
  79. return showJson(VideoService::make()->getError(), false);
  80. }else{
  81. return showJson(VideoService::make()->getError(), true, $result);
  82. }
  83. }
  84. /**
  85. * 播放与浏览
  86. * @return array
  87. */
  88. public function updatePlay()
  89. {
  90. $id = request()->post('id',0);
  91. if(!$result = VideoService::make()->updatePlay($this->userId, $id)){
  92. return showJson(VideoService::make()->getError(), false);
  93. }else{
  94. return showJson(VideoService::make()->getError(), true, $result);
  95. }
  96. }
  97. /**
  98. * 点赞
  99. * @return array|mixed
  100. */
  101. public function like()
  102. {
  103. $params = request()->post();
  104. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  105. return showJson(VideoCollectService::make()->getError(), false);
  106. }else{
  107. return showJson(VideoCollectService::make()->getError(), true, $result);
  108. }
  109. }
  110. /**
  111. * 收藏
  112. * @return array|mixed
  113. */
  114. public function collect()
  115. {
  116. $params = request()->post();
  117. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  118. return showJson(VideoCollectService::make()->getError(), false);
  119. }else{
  120. return showJson(VideoCollectService::make()->getError(), true, $result);
  121. }
  122. }
  123. /**
  124. * 状态
  125. * @return array|mixed
  126. */
  127. public function status()
  128. {
  129. if(!$result = VideoService::make()->status()){
  130. return showJson(VideoService::make()->getError(), false);
  131. }else{
  132. return showJson(VideoService::make()->getError(), true, $result);
  133. }
  134. }
  135. /**
  136. * 删除
  137. * @return array|mixed
  138. */
  139. public function delete()
  140. {
  141. if(!$result = VideoService::make()->delete()){
  142. return showJson(VideoService::make()->getError(), false);
  143. }else{
  144. return showJson(VideoService::make()->getError(), true);
  145. }
  146. }
  147. }